Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import org.gradle.api.plugins.JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.JAVADOC_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME
import org.gradle.api.plugins.JavaPlugin.SOURCES_ELEMENTS_CONFIGURATION_NAME
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
import org.gradle.plugin.compatibility.compatibility
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation

Expand Down Expand Up @@ -45,6 +47,8 @@ kotlin {
}
}

addMultiReleaseSourceSet(24)

lint {
baseline = file("gradle/lint-baseline.xml")
ignoreTestFixturesSources = true
Expand Down Expand Up @@ -222,6 +226,8 @@ kotlin.target.compilations {
}
}

tasks.jar { manifest.attributes("Multi-Release" to true) }

tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }

tasks.check { dependsOn(tasks.withType<Test>()) }
Expand All @@ -236,3 +242,34 @@ tasks.clean {
rootDir.resolve("site"),
)
}

fun addMultiReleaseSourceSet(version: Int) {
kotlin.target.compilations.create("java${version}") {
associateWith(kotlin.target.compilations.getByName("main"))
compileTaskProvider {
compilerOptions {
this@compilerOptions as KotlinJvmCompilerOptions
jvmTarget = JvmTarget.fromTarget(version.toString())
freeCompilerArgs.add("-Xjdk-release=$version")
}
}
compileJavaTaskProvider { options.release = version }

tasks.jar { from(output.allOutputs) { into("META-INF/versions/$version") } }

val versionedTest =
tasks.register("testJava${version}", Test::class) {
useJUnitPlatform()
group = VERIFICATION_GROUP
description = "Runs test suite using Java $version toolchain."
val testSourceSet = sourceSets.test.get()
testClassesDirs = testSourceSet.output.classesDirs
val testCpWithoutMainOutput = testSourceSet.runtimeClasspath - sourceSets.main.get().output
// Prefer MR classes on the classpath, so remove main output.
classpath = files(tasks.jar.flatMap { it.archiveFile }) + testCpWithoutMainOutput
javaLauncher =
javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }
}
tasks.check { dependsOn(versionedTest) }
}
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# https://kotlinlang.org/docs/gradle-configure-project.html#dependency-on-the-standard-library
kotlin.stdlib.default.dependency=false

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

org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ pluginManagement {
}
}

plugins { id("com.gradle.develocity") version "4.3.2" }
plugins {
id("com.gradle.develocity") version "4.3.2"
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}

develocity {
buildScan {
Expand Down
Loading
Loading