Skip to content

Commit

Permalink
Fix #228: reduce parallelism in task and increase parallelism between…
Browse files Browse the repository at this point in the history
… tasks (#246)

* Enable configuration cache
* Remove parallelism inside compatTest tasks.
* Remove kotlin-dsl and only use what is used in this project (kotlin-dsl dependency and sam with receiver). This prevents us from needing to fight with kotlin-dsl overriding language versions.
* Move to new KGP DSL for setting up versions. (kotlinOptions to compilerOptions)
* Make compatTest past without kotlin-dsl
* Revert to kotlin-dsl, it does too many things apart from the forceful version.
* Fix kotlin versioning
* Simplify
* Un-nest
* Make a change to trigger rerun of tests
  • Loading branch information
TWiStErRob authored Jul 14, 2023
1 parent 66f3284 commit 55f4a5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
59 changes: 38 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.gradle.initialization.IGradlePropertiesLoader.ENV_PROJECT_PROPERTIES_PREFIX
import org.gradle.initialization.IGradlePropertiesLoader.SYSTEM_PROJECT_PROPERTIES_PREFIX
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
`kotlin-dsl`
Expand Down Expand Up @@ -161,28 +162,44 @@ sourceSets {
}
}

tasks {
afterEvaluate {
// This needs to be in an afterEvaluate block,
// because otherwise KotlinDslCompilerPlugins would win, and override what we've set to Kotlin 1.8.
withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
// Supporting Gradle 6.0+ needs to use Kotlin 1.3.
// See https://docs.gradle.org/current/userguide/compatibility.html
kotlinOptions.apiVersion = "1.3"
// Theoretically we could use newer language version here,
// but sadly the @kotlin.Metadata created on the classes would be incompatible with Kotlin 1.3 consumers.
kotlinOptions.languageVersion = "1.3"
doFirst {
if (kotlinOptions.apiVersion == "1.3") {
// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
kotlinOptions.freeCompilerArgs += "-Xsuppress-version-warnings"
} else {
TODO("Remove -Xsuppress-version-warnings suppression, or change the condition to ${kotlinOptions.languageVersion}")
}
kotlin.target.compilations.configureEach {
// Supporting Gradle 6.0+ needs to use Kotlin 1.3.
// See https://docs.gradle.org/current/userguide/compatibility.html
// For future maintainer: Kotlin 1.9.0 dropped support for Kotlin 1.3, it'll only support 1.4+.
// This means Gradle 7.0 will be the lowest supportable version for plugins.
val usedKotlinVersion = @Suppress("DEPRECATION") KotlinVersion.KOTLIN_1_3

compilerOptions.configure {
// Gradle fully supports running on Java 8: https://docs.gradle.org/current/userguide/compatibility.html,
// so we should allow users to do that too.
jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_1_8.toString())

// Suppress "Language version 1.3 is deprecated and its support will be removed in a future version of Kotlin".
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
compileTaskProvider.configure {
// These two (api & lang) needs to be here instead of in compilations.compilerOptions.configure { },
// to prevent KotlinDslCompilerPlugins overriding to Kotlin 1.8.
compilerOptions.apiVersion = usedKotlinVersion
// Theoretically we could use newer language version here,
// but sadly the @kotlin.Metadata created on the classes would be incompatible with older consumers.
compilerOptions.languageVersion = usedKotlinVersion

// Validate that we're using the right version.
doFirst {
val api = compilerOptions.apiVersion.get()
val language = compilerOptions.languageVersion.get()
if (api != usedKotlinVersion || language != usedKotlinVersion) {
TODO(
"There's mismatch between configured and actual versions:\n" +
"apiVersion=${api}, languageVersion=${language}, configured=${usedKotlinVersion}."
)
}
}
}
}

tasks {
shadowJar {
exclude("META-INF/maven/**", "META-INF/proguard/**", "META-INF/*.kotlin_module")
manifest {
Expand Down Expand Up @@ -228,7 +245,7 @@ tasks {
withType<Test>().configureEach {
dependsOn(shadowJar)
useJUnitPlatform()
maxParallelForks = 8
maxParallelForks = if (name.startsWith("compatTest")) 1 else 8
}
withType<Test>().matching { it.name.startsWith("compatTest") }.configureEach {
systemProperty("plugin.version", project.version)
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.configuration-cache=true
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import java.nio.file.Files
import java.nio.file.Path

fun Path.write(text: String): Path {
Files.createDirectories(parent)
toFile().writeText(text)
Files.createDirectories(this.parent)
this.toFile().writeText(text)
return this
}

fun Path.append(text: String): Path {
Files.createDirectories(parent)
toFile().appendText(text)
Files.createDirectories(this.parent)
this.toFile().appendText(text)
return this
}

0 comments on commit 55f4a5b

Please sign in to comment.