From acb45a1dea61dd844fba839cc31c79a7aca4bbe4 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 4 Nov 2022 16:53:22 +0100 Subject: build: Increase minimum Java version to Java 17 This change updates the Gradle configuration to target Java 17 (instead of Java 11) as the lowest denominator when running/building OpenDC. This version of Java has been available for more than a year and is the latest LTS release. --- buildSrc/src/main/kotlin/Libs.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'buildSrc/src') diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 6a73e1b9..97dc36ca 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -50,6 +50,6 @@ public class Libs(project: Project) { /** * The JVM version to target. */ - val jvmTarget = JavaVersion.VERSION_11 + val jvmTarget = JavaVersion.VERSION_17 } } -- cgit v1.2.3 From 83ad9c927952474f1adeb03bd67331288ed6d6d9 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 13 Nov 2022 12:28:04 +0000 Subject: build: Make use of Gradle's Java Toolchains feature This change updates the build configuration for Gradle to make use of its Java Toolchains feature which enables running/testing multiple Java versions at the same time. This feature can also provision a Java installation if it is not available on the user's system. --- buildSrc/src/main/kotlin/Libs.kt | 37 ++++++++++------------ .../main/kotlin/benchmark-conventions.gradle.kts | 4 +-- .../src/main/kotlin/java-conventions.gradle.kts | 6 ++-- .../src/main/kotlin/kotlin-conventions.gradle.kts | 9 +++++- .../src/main/kotlin/testing-conventions.gradle.kts | 26 ++++++++++++--- 5 files changed, 51 insertions(+), 31 deletions(-) (limited to 'buildSrc/src') diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 97dc36ca..09432b06 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -24,32 +24,27 @@ import org.gradle.api.JavaVersion import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.kotlin.dsl.getByType /** - * This class makes the version catalog accessible for the build scripts until Gradle adds support for it. - * - * See https://github.com/gradle/gradle/issues/15383 + * Obtain the default [VersionCatalog] of the project. */ -public class Libs(project: Project) { - /** - * The version catalog of the project. - */ - private val versionCatalog = project.extensions.getByType(VersionCatalogsExtension::class).named("libs") +public val Project.defaultVersionCatalog: VersionCatalog + get() = project.extensions.getByType(VersionCatalogsExtension::class).named("libs") - /** - * Obtain the version for the specified [dependency][name]. - */ - operator fun get(name: String): String { - val dep = versionCatalog.findLibrary(name).get().get() - return "${dep.module.group}:${dep.module.name}:${dep.versionConstraint.displayName}" - } +/** + * Obtain the dependency string for the specified [name]. + */ +public operator fun VersionCatalog.get(name: String): String { + val dep = findLibrary(name).get().get() + return "${dep.module.group}:${dep.module.name}:${dep.versionConstraint.displayName}" +} - companion object { - /** - * The JVM version to target. - */ - val jvmTarget = JavaVersion.VERSION_17 - } +/** + * Obtain the string representation of the version with the given [name]. + */ +public fun VersionCatalog.getVersion(name: String): String { + return findVersion(name).get().displayName } diff --git a/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts b/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts index 554d2279..e16733a4 100644 --- a/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/benchmark-conventions.gradle.kts @@ -50,7 +50,7 @@ tasks.named("jmh", JMHTask::class) { dependencies { constraints { - val libs = Libs(project) - jmh(libs["commons.math3"]) // XXX Force JMH to use the same commons-math3 version as OpenDC + val versionCatalog = project.defaultVersionCatalog + jmh(versionCatalog["commons.math3"]) // XXX Force JMH to use the same commons-math3 version as OpenDC } } diff --git a/buildSrc/src/main/kotlin/java-conventions.gradle.kts b/buildSrc/src/main/kotlin/java-conventions.gradle.kts index 8857d4ab..875ae2a7 100644 --- a/buildSrc/src/main/kotlin/java-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/java-conventions.gradle.kts @@ -31,8 +31,10 @@ repositories { } java { - sourceCompatibility = Libs.jvmTarget - targetCompatibility = Libs.jvmTarget + toolchain { + val javaVersion = project.defaultVersionCatalog.getVersion("java") + languageVersion.set(JavaLanguageVersion.of(javaVersion)) + } } tasks.withType { diff --git a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts index 5ccc06a4..79afdf7c 100644 --- a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts @@ -29,8 +29,15 @@ plugins { } /* Project configuration */ + +kotlin { + jvmToolchain { + val javaVersion = project.defaultVersionCatalog.getVersion("java") + languageVersion.set(JavaLanguageVersion.of(javaVersion)) + } +} + tasks.withType().configureEach { - kotlinOptions.jvmTarget = Libs.jvmTarget.toString() kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" kotlinOptions.freeCompilerArgs += "-Xjvm-default=all" } diff --git a/buildSrc/src/main/kotlin/testing-conventions.gradle.kts b/buildSrc/src/main/kotlin/testing-conventions.gradle.kts index ebeb58a4..a7fa9da9 100644 --- a/buildSrc/src/main/kotlin/testing-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/testing-conventions.gradle.kts @@ -34,10 +34,26 @@ tasks.test { } dependencies { - val libs = Libs(project) + val versionCatalog = project.defaultVersionCatalog - testImplementation(libs["junit.jupiter.api"]) - testImplementation(libs["junit.jupiter.params"]) - testImplementation(libs["mockk"]) - testRuntimeOnly(libs["junit.jupiter.engine"]) + testImplementation(versionCatalog["junit.jupiter.api"]) + testImplementation(versionCatalog["junit.jupiter.params"]) + testImplementation(versionCatalog["mockk"]) + testRuntimeOnly(versionCatalog["junit.jupiter.engine"]) +} + +tasks.register("testsOn18") { + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(18)) + }) + + useJUnitPlatform() +} + +tasks.register("testsOn19") { + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(19)) + }) + + useJUnitPlatform() } -- cgit v1.2.3