Skip to content

Commit 4c3bd6a

Browse files
committed
Multi-Release for Class-File API
1 parent 60d0f8b commit 4c3bd6a

File tree

5 files changed

+722
-540
lines changed

5 files changed

+722
-540
lines changed

build.gradle.kts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME
77
import org.gradle.plugin.compatibility.compatibility
88
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
99
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
10+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
1011
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
1112
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation
1213

@@ -30,7 +31,7 @@ dokka { dokkaPublications.html { outputDirectory = rootDir.resolve("docs/api") }
3031
kotlin {
3132
explicitApi()
3233
@OptIn(ExperimentalAbiValidation::class) abiValidation { enabled = true }
33-
val jdkRelease = "24"
34+
val jdkRelease = "17"
3435
compilerOptions {
3536
allWarningsAsErrors = true
3637
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
@@ -45,6 +46,8 @@ kotlin {
4546
}
4647
}
4748

49+
addMultiReleaseSourceSet(24)
50+
4851
lint {
4952
baseline = file("gradle/lint-baseline.xml")
5053
ignoreTestFixturesSources = true
@@ -222,6 +225,8 @@ kotlin.target.compilations {
222225
}
223226
}
224227

228+
tasks.jar { manifest.attributes("Multi-Release" to true) }
229+
225230
tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }
226231

227232
tasks.check { dependsOn(tasks.withType<Test>()) }
@@ -236,3 +241,21 @@ tasks.clean {
236241
rootDir.resolve("site"),
237242
)
238243
}
244+
245+
fun addMultiReleaseSourceSet(version: Int) {
246+
kotlin.target.compilations.create("java${version}") {
247+
associateWith(kotlin.target.compilations.getByName("main"))
248+
compileTaskProvider {
249+
compilerOptions {
250+
this@compilerOptions as KotlinJvmCompilerOptions
251+
jvmTarget = JvmTarget.fromTarget(version.toString())
252+
freeCompilerArgs.add("-Xjdk-release=$version")
253+
}
254+
}
255+
compileJavaTaskProvider { options.release = version }
256+
257+
tasks.jar { from(output.allOutputs) { into("META-INF/versions/$version") } }
258+
259+
tasks.withType<Test>().configureEach { inputs.files(output.allOutputs) }
260+
}
261+
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# https://kotlinlang.org/docs/gradle-configure-project.html#dependency-on-the-standard-library
33
kotlin.stdlib.default.dependency=false
44

5+
# Keep associated Kotlin compilations from depending on archive tasks (e.g., jar), which can create circular task graphs in multi-release setups.
6+
# https://kotlinlang.org/docs/gradle-configure-project.html//disable-use-of-artifact-in-compilation-task
7+
# https://kotlinlang.org/docs/whatsnew2020.html#added-task-dependency-for-rare-cases-when-the-compile-task-lacks-one-on-an-artifact
8+
kotlin.build.archivesTaskOutputAsFriendModule=false
9+
510
org.gradle.caching=true
611
org.gradle.configuration-cache=true
712
org.gradle.configuration-cache.parallel=true

0 commit comments

Comments
 (0)