Changed compile options to config phase instead of after evaulate

This commit is contained in:
Robinson 2021-05-10 00:07:47 +02:00
parent e07628fb20
commit fcde09ef5f

View File

@ -490,12 +490,10 @@ open class StaticMethodsAndTools(private val project: Project) {
* Always compile java with UTF-8, make it incremental, and compile `package-info.java` classes * Always compile java with UTF-8, make it incremental, and compile `package-info.java` classes
*/ */
fun defaultCompileOptions() { fun defaultCompileOptions() {
project.afterEvaluate { prj -> project.tasks.withType(JavaCompile::class.java) {
prj.tasks.withType(JavaCompile::class.java) { it.options.encoding = "UTF-8"
it.options.encoding = "UTF-8" it.options.isIncremental = true
it.options.isIncremental = true it.options.compilerArgs.add("-Xpkginfo:always")
it.options.compilerArgs.add("-Xpkginfo:always")
}
} }
} }
@ -507,21 +505,22 @@ open class StaticMethodsAndTools(private val project: Project) {
kotlinActions: KotlinJvmOptions.() -> Unit = {}) { kotlinActions: KotlinJvmOptions.() -> Unit = {}) {
val javaVer = javaVersion.toString() val javaVer = javaVersion.toString()
val kotlinJavaVer = kotlinJavaVersion.toString() val kotlinJavaVer = kotlinJavaVersion.toString()
val defaultKotlinVersion = "1.5.0"
val kotlinVer: String = try { val kotlinVer: String = try {
if (hasKotlin) { if (hasKotlin) {
val kot = project.plugins.findPlugin("org.jetbrains.kotlin.jvm") as org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper? val kot = project.plugins.findPlugin("org.jetbrains.kotlin.jvm") as org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper?
val version = kot?.kotlinPluginVersion ?: "1.4.32" val version = kot?.kotlinPluginVersion ?: defaultKotlinVersion
// we ONLY care about the major.minor // we ONLY care about the major.minor
val secondDot = version.indexOf('.', version.indexOf('.')+1) val secondDot = version.indexOf('.', version.indexOf('.')+1)
version.substring(0, secondDot) version.substring(0, secondDot)
} else { } else {
"1.4.32" defaultKotlinVersion
} }
} catch (e: Exception) { } catch (e: Exception) {
// in case we cannot parse it from the plugin, provide a reasonable default (latest stable) // in case we cannot parse it from the plugin, provide a reasonable default (latest stable)
"1.4.32" defaultKotlinVersion
} }
project.tasks.withType(JavaCompile::class.java) { task -> project.tasks.withType(JavaCompile::class.java) { task ->