From ff11f543310422c51d9e68c1011f57f01ff41f1c Mon Sep 17 00:00:00 2001 From: Stefan M Date: Wed, 28 Feb 2024 09:41:32 +0000 Subject: [PATCH 1/7] Add Gradle toolchain support --- buildSrc/build.gradle.kts | 15 +-------------- .../src/main/kotlin/pklAllProjects.gradle.kts | 7 ------- buildSrc/src/main/kotlin/pklFatJar.gradle.kts | 11 +++++++++-- .../src/main/kotlin/pklJavaLibrary.gradle.kts | 5 +++++ .../src/main/kotlin/pklKotlinLibrary.gradle.kts | 5 +++++ buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts | 5 +++++ settings.gradle.kts | 9 ++++----- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index e8bf11759..adff1fc48 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.config.JvmTarget - plugins { `kotlin-dsl` } @@ -17,17 +15,6 @@ dependencies { implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) } -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} - kotlin { - target { - compilations.configureEach { - kotlinOptions { - jvmTarget = "11" - } - } - } + jvmToolchain(11) } diff --git a/buildSrc/src/main/kotlin/pklAllProjects.gradle.kts b/buildSrc/src/main/kotlin/pklAllProjects.gradle.kts index 4daf287a7..8c4768f89 100644 --- a/buildSrc/src/main/kotlin/pklAllProjects.gradle.kts +++ b/buildSrc/src/main/kotlin/pklAllProjects.gradle.kts @@ -22,15 +22,8 @@ configurations { } } -plugins.withType(JavaPlugin::class).configureEach { - val java = project.extensions.getByType() - java.sourceCompatibility = JavaVersion.VERSION_11 - java.targetCompatibility = JavaVersion.VERSION_11 -} - tasks.withType().configureEach { kotlinOptions { - jvmTarget = "11" freeCompilerArgs = freeCompilerArgs + listOf("-Xjsr305=strict", "-Xjvm-default=all") } } diff --git a/buildSrc/src/main/kotlin/pklFatJar.gradle.kts b/buildSrc/src/main/kotlin/pklFatJar.gradle.kts index 675e2dbf8..bc6203386 100644 --- a/buildSrc/src/main/kotlin/pklFatJar.gradle.kts +++ b/buildSrc/src/main/kotlin/pklFatJar.gradle.kts @@ -43,7 +43,7 @@ val relocations = mapOf( // pkl-doc dependencies "org.commonmark." to "org.pkl.thirdparty.commonmark.", "org.jetbrains." to "org.pkl.thirdparty.jetbrains.", - + // pkl-config-java dependencies "io.leangen.geantyref." to "org.pkl.thirdparty.geantyref.", @@ -54,6 +54,13 @@ val relocations = mapOf( "com.squareup.kotlinpoet." to "org.pkl.thirdparty.kotlinpoet.", ) +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + vendor.set(JvmVendorSpec.ADOPTIUM) + } +} + val nonRelocations = listOf("com/oracle/truffle/") tasks.shadowJar { @@ -117,7 +124,7 @@ val validateFatJar by tasks.registering { val path = fileDetails.relativePath.pathString if (!(fileDetails.isDirectory || path.startsWith("org/pkl/") || - path.startsWith("META-INF/") || + path.startsWith("META-INF/") || nonRelocations.any { path.startsWith(it) })) { // don't throw exception inside `visit` // as this gives a misleading "Could not expand ZIP" error message diff --git a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts index a79d78347..1aea93fd7 100644 --- a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts +++ b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts @@ -17,6 +17,11 @@ val libs = the() java { withSourcesJar() // creates `sourcesJar` task withJavadocJar() + + toolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + vendor.set(JvmVendorSpec.ADOPTIUM) + } } artifacts { diff --git a/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts b/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts index cbc728365..82083503b 100644 --- a/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts +++ b/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts @@ -24,6 +24,11 @@ tasks.compileKotlin { enabled = true // disabled by pklJavaLibrary } +kotlin.jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + vendor.set(JvmVendorSpec.ADOPTIUM) +} + spotless { kotlin { ktfmt(libs.versions.ktfmt.get()).googleStyle() diff --git a/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts b/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts index 0b40c9564..cb7c089ed 100644 --- a/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts +++ b/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts @@ -16,6 +16,11 @@ dependencies { testRuntimeOnly(buildInfo.libs.findLibrary("junitEngine").get()) } +kotlin.jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + vendor.set(JvmVendorSpec.ADOPTIUM) +} + tasks.withType().configureEach { val testTask = this diff --git a/settings.gradle.kts b/settings.gradle.kts index 1fc89a8d3..5a419f60f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,6 +27,10 @@ pluginManagement { } } +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + @Suppress("UnstableApiUsage") dependencyResolutionManagement { repositories { @@ -34,11 +38,6 @@ dependencyResolutionManagement { } } -val javaVersion = JavaVersion.current() -require(javaVersion.isJava11Compatible) { - "Project requires Java 11 or higher, but found ${javaVersion.majorVersion}." -} - if (gradle.startParameter.taskNames.contains("updateDependencyLocks") || gradle.startParameter.taskNames.contains("uDL") ) { From 0371c2ff0e991263f4c13fc9dca27310685f09a0 Mon Sep 17 00:00:00 2001 From: Stefan M Date: Wed, 28 Feb 2024 20:36:32 +0000 Subject: [PATCH 2/7] Move toolchain version and vendor to single place and make them configurable --- buildSrc/src/main/kotlin/JvmToolchain.kt | 14 ++++++++++++++ buildSrc/src/main/kotlin/pklFatJar.gradle.kts | 4 ++-- buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts | 4 ++-- .../src/main/kotlin/pklKotlinLibrary.gradle.kts | 4 ++-- buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts | 4 ++-- 5 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 buildSrc/src/main/kotlin/JvmToolchain.kt diff --git a/buildSrc/src/main/kotlin/JvmToolchain.kt b/buildSrc/src/main/kotlin/JvmToolchain.kt new file mode 100644 index 000000000..445bfc4c5 --- /dev/null +++ b/buildSrc/src/main/kotlin/JvmToolchain.kt @@ -0,0 +1,14 @@ +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.jvm.toolchain.JvmVendorSpec +import org.gradle.api.Project + +private const val JDK_VERSION = 11 + +val jvmToolchainVersion: JavaLanguageVersion + get() { + val jvmVersion = System.getProperty("PKL_JVM_VERSION", JDK_VERSION.toString()).toInt() + return JavaLanguageVersion.of(jvmVersion) + } + +val jvmToolchainVendor: JvmVendorSpec + get() = JvmVendorSpec.ADOPTIUM \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/pklFatJar.gradle.kts b/buildSrc/src/main/kotlin/pklFatJar.gradle.kts index bc6203386..9fa7e4286 100644 --- a/buildSrc/src/main/kotlin/pklFatJar.gradle.kts +++ b/buildSrc/src/main/kotlin/pklFatJar.gradle.kts @@ -56,8 +56,8 @@ val relocations = mapOf( java { toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - vendor.set(JvmVendorSpec.ADOPTIUM) + languageVersion.set(jvmToolchainVersion) + vendor.set(jvmToolchainVendor) } } diff --git a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts index 1aea93fd7..6ebfb1dc6 100644 --- a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts +++ b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts @@ -19,8 +19,8 @@ java { withJavadocJar() toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - vendor.set(JvmVendorSpec.ADOPTIUM) + languageVersion.set(jvmToolchainVersion) + vendor.set(jvmToolchainVendor) } } diff --git a/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts b/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts index 82083503b..69a927719 100644 --- a/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts +++ b/buildSrc/src/main/kotlin/pklKotlinLibrary.gradle.kts @@ -25,8 +25,8 @@ tasks.compileKotlin { } kotlin.jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - vendor.set(JvmVendorSpec.ADOPTIUM) + languageVersion.set(jvmToolchainVersion) + vendor.set(jvmToolchainVendor) } spotless { diff --git a/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts b/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts index cb7c089ed..b348835c5 100644 --- a/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts +++ b/buildSrc/src/main/kotlin/pklKotlinTest.gradle.kts @@ -17,8 +17,8 @@ dependencies { } kotlin.jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - vendor.set(JvmVendorSpec.ADOPTIUM) + languageVersion.set(jvmToolchainVersion) + vendor.set(jvmToolchainVendor) } tasks.withType().configureEach { From 2921b89e4d6785bada73e3fdb59369342153e6ff Mon Sep 17 00:00:00 2001 From: Stefan M Date: Thu, 29 Feb 2024 14:43:24 +0000 Subject: [PATCH 3/7] Update development.adoc --- DEVELOPMENT.adoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/DEVELOPMENT.adoc b/DEVELOPMENT.adoc index 0062a780c..3c258b152 100644 --- a/DEVELOPMENT.adoc +++ b/DEVELOPMENT.adoc @@ -2,11 +2,9 @@ :uri-gng: https://gng.dsun.org :uri-jenv: https://www.jenv.be :uri-intellij: https://www.jetbrains.com/idea/download/ -:uri-jdk: https://adoptopenjdk.net/releases.html == Setup -. (mandatory) Install {uri-jdk}[OpenJDK 11 HotSpot] (as long as we support JDK11) . (recommended) Install {uri-intellij}[IntelliJ IDEA 2023.x] + To import the project into IntelliJ, go to File->Open and select the project's root directory. If the project is opened but not imported, look for a popup in the lower right corner From cffa8e05a079209f7d83640dd30a5fe31ef4851e Mon Sep 17 00:00:00 2001 From: StefMa Date: Tue, 5 Mar 2024 09:26:24 +0100 Subject: [PATCH 4/7] Fix CI job --- .circleci/config.yml | 4 ++-- .circleci/jobs/GradleCheckJob.pkl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c21303fc2..4c8a6c4df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -583,7 +583,7 @@ jobs: steps: - checkout - run: - command: ./gradlew --info --stacktrace check + command: ./gradlew --info --stacktrace check -DPKL_JVM_VERSION=11 name: gradle check - run: command: |- @@ -601,7 +601,7 @@ jobs: steps: - checkout - run: - command: ./gradlew --info --stacktrace check + command: ./gradlew --info --stacktrace check -DPKL_JVM_VERSION=17 name: gradle check - run: command: |- diff --git a/.circleci/jobs/GradleCheckJob.pkl b/.circleci/jobs/GradleCheckJob.pkl index cf9b70b3f..fcbfb3a54 100644 --- a/.circleci/jobs/GradleCheckJob.pkl +++ b/.circleci/jobs/GradleCheckJob.pkl @@ -22,7 +22,7 @@ javaVersion: "11.0"|"17.0" steps { new Config.RunStep { name = "gradle check" - command = "./gradlew \(module.gradleArgs) check" + command = "./gradlew \(module.gradleArgs) check -DPKL_JVM_VERSION=\(javaVersion.dropLast(2))" } } From 5b2e95b4b3a01280f69930dc43d087242ffcbbc5 Mon Sep 17 00:00:00 2001 From: StefMa Date: Wed, 20 Mar 2024 19:42:36 +0100 Subject: [PATCH 5/7] Update CI config --- .circleci/config.pkl | 4 ++-- .circleci/config.yml | 2 +- .circleci/jobs/GradleCheckJob.pkl | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.pkl b/.circleci/config.pkl index f35042a5e..cb892d73b 100644 --- a/.circleci/config.pkl +++ b/.circleci/config.pkl @@ -141,11 +141,11 @@ local buildNativeJobs: Mapping = new { local gradleCheckJobs: Mapping = new { ["gradle-check-jdk11"] { - javaVersion = "11.0" + javaVersion = "11" isRelease = false } ["gradle-check-jdk17"] { - javaVersion = "17.0" + javaVersion = "17" isRelease = false } } diff --git a/.circleci/config.yml b/.circleci/config.yml index 4c8a6c4df..7ccbb9218 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -614,7 +614,7 @@ jobs: environment: LANG: en_US.UTF-8 docker: - - image: cimg/openjdk:17.0 + - image: cimg/openjdk:11.0 bench: steps: - checkout diff --git a/.circleci/jobs/GradleCheckJob.pkl b/.circleci/jobs/GradleCheckJob.pkl index fcbfb3a54..64a2b5880 100644 --- a/.circleci/jobs/GradleCheckJob.pkl +++ b/.circleci/jobs/GradleCheckJob.pkl @@ -17,19 +17,19 @@ extends "GradleJob.pkl" import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.0#/Config.pkl" -javaVersion: "11.0"|"17.0" +javaVersion: "11"|"17" steps { new Config.RunStep { name = "gradle check" - command = "./gradlew \(module.gradleArgs) check -DPKL_JVM_VERSION=\(javaVersion.dropLast(2))" + command = "./gradlew \(module.gradleArgs) check -DPKL_JVM_VERSION=\(javaVersion)" } } job { docker { new { - image = "cimg/openjdk:\(javaVersion)" + image = "cimg/openjdk:11.0" } } } From 8338c17e6eb496616d659f2be46d05fdd4d2050f Mon Sep 17 00:00:00 2001 From: StefMa Date: Wed, 3 Apr 2024 13:06:14 +0200 Subject: [PATCH 6/7] Remove unnecessary conversion --- buildSrc/src/main/kotlin/JvmToolchain.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/JvmToolchain.kt b/buildSrc/src/main/kotlin/JvmToolchain.kt index 445bfc4c5..bd41936d3 100644 --- a/buildSrc/src/main/kotlin/JvmToolchain.kt +++ b/buildSrc/src/main/kotlin/JvmToolchain.kt @@ -1,14 +1,13 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.jvm.toolchain.JvmVendorSpec -import org.gradle.api.Project private const val JDK_VERSION = 11 val jvmToolchainVersion: JavaLanguageVersion get() { - val jvmVersion = System.getProperty("PKL_JVM_VERSION", JDK_VERSION.toString()).toInt() + val jvmVersion = System.getProperty("PKL_JVM_VERSION")?.toInt() ?: JDK_VERSION return JavaLanguageVersion.of(jvmVersion) } val jvmToolchainVendor: JvmVendorSpec - get() = JvmVendorSpec.ADOPTIUM \ No newline at end of file + get() = JvmVendorSpec.ADOPTIUM From ad5df187ab28698ccb992a8724455e8fd3f5c3dc Mon Sep 17 00:00:00 2001 From: StefMa Date: Wed, 3 Apr 2024 13:56:05 +0200 Subject: [PATCH 7/7] Set javaLauncher for JavaExec tasks --- buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts index 6ebfb1dc6..4db4c2200 100644 --- a/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts +++ b/buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts @@ -24,6 +24,10 @@ java { } } +tasks.withType().configureEach { + javaLauncher.set(javaToolchains.launcherFor(java.toolchain)) +} + artifacts { // make sources Jar available to other subprojects add("sourcesJar", tasks["sourcesJar"])