ext.PROJECT_NAME = "Releases Hub Gradle Plugin"
description = "Gradle Plugin to automatically upgrade your java gradle project dependencies and send a GitHub pull request with the changes"
ext.ARTIFACT_ID = "releases-hub-gradle-plugin"
ext.GRADLE_PLUGIN_ID = "com.dipien.releaseshub.gradle.plugin"
ext.GRADLE_PLUGIN_IMPLEMENTATION_CLASS = "com.releaseshub.gradle.plugin.ReleasesHubGradlePlugin"
ext.GRADLE_PLUGIN_PORTAL_TAGS = ["gradle", "plugin", "dependencies", "github", "releases"]

apply plugin: "kotlin"
apply plugin: "com.jdroidtools.gradle.plugin"

buildscript {
	dependencies {
		classpath(BuildLibs.KOTLIN_GRADLE_PLUGIN)
		classpath(BuildLibs.JDROID_GRADLE_PROJECT_PLUGIN)
	}
}

dependencies {
	implementation(Libs.KOTLIN)
	implementation(Libs.JDROID_JAVA_CORE)
	implementation(Libs.JDROID_JAVA_HTTP_OKHTTP)
	implementation(Libs.OKHTTP)
	implementation(Libs.GITHUB_API)
	implementation(Libs.JDROID_JAVA_GOOGLE_DRIVE)

	testImplementation(Libs.JUNIT)
	testImplementation(Libs.TRUTH)
}

sourceSets {
	main.java.srcDirs += "build/generated"
}

compileKotlin.kotlinOptions {
	jvmTarget = JavaVersion.VERSION_1_8.toString()
}

compileTestKotlin.kotlinOptions {
	jvmTarget = JavaVersion.VERSION_1_8.toString()
}

project.afterEvaluate {

	project.task('generateBuildConfigClass') {
		doLast {
			File dir = new File("$projectDir/build/generated/com/releaseshub/gradle/plugin/context")
			dir.mkdirs()
			File file = new File(dir, "BuildConfig.kt")
			file.withWriter { out ->

				out.writeLine("package com.releaseshub.gradle.plugin.context")
				out.writeLine("")
				out.writeLine("object BuildConfig {")
				out.writeLine("		const val VERSION = \"${project.version.toString()}\"")
				out.writeLine("}")
			}
		}
	}

	project.tasks.'compileKotlin'.dependsOn 'generateBuildConfigClass'
}
