From 6e85bc13dab8e1fec27dc5ba525ee7233a7f7539 Mon Sep 17 00:00:00 2001
From: Tim Yates <tim.yates@gmail.com>
Date: Fri, 20 Oct 2023 10:33:51 +0100
Subject: [PATCH] Up to 6.6.0 shared plugin to run tests on 21 (#217)

* Up to 6.6.0 shared plugin to run tests on 21

* Use a toolchain for Kotlin and drop the magic add-opens

* Add magic properties back

* Run Ksp tests on 21?

* Unused import

* Next minor
---
 gradle.properties                  | 16 ++++++++++++++--
 gradle/libs.versions.toml          |  2 +-
 settings.gradle                    |  6 ++----
 test-suite-kotlin/build.gradle.kts |  6 ++++++
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/gradle.properties b/gradle.properties
index cba471a1..1c379ffa 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-projectVersion=2.1.1-SNAPSHOT
+projectVersion=2.2.0-SNAPSHOT
 projectGroup=io.micronaut.crac
 
 title=Micronaut CRaC
@@ -7,8 +7,20 @@ projectUrl=https://micronaut.io
 githubSlug=micronaut-projects/micronaut-crac
 developers=Tim Yates,Sergio del Amo
 
-
 # If needed, set additional properties
 
 org.gradle.caching=true
 org.gradle.jvmargs=-Xmx1g
+
+# No matter which Java toolchain we use, the Kotlin Daemon is always invoked by the current JDK.
+# Therefor to fix Kapt errors when running tests under Java 21, we need to open up some modules for the Kotlin Daemon.
+kotlin.daemon.jvmargs=--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\
+ --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
+ --add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index a9414c56..85cce2a4 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -20,7 +20,7 @@ managed-crac = "1.4.0"
 
 micronaut-logging = "1.0.0"
 
-testcontainers = "1.19.0"
+testcontainers = "1.19.1"
 
 [libraries]
 # Core
diff --git a/settings.gradle b/settings.gradle
index 84927813..2b1b43d0 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -6,7 +6,7 @@ pluginManagement {
 }
 
 plugins {
-    id 'io.micronaut.build.shared.settings' version '6.5.7'
+    id 'io.micronaut.build.shared.settings' version '6.6.0'
 }
 
 enableFeaturePreview('TYPESAFE_PROJECT_ACCESSORS')
@@ -21,9 +21,7 @@ include 'test-suite-dbcp-jooq'
 include 'test-suite-docker'
 include 'test-suite-groovy'
 include 'test-suite-hikari-jooq'
-if (JavaVersion.current() < JavaVersion.VERSION_21) {
-    include 'test-suite-kotlin'
-}
+include 'test-suite-kotlin'
 include 'test-suite-kotlin-ksp'
 include 'test-suite-redis'
 
diff --git a/test-suite-kotlin/build.gradle.kts b/test-suite-kotlin/build.gradle.kts
index 5d4a1aff..2160fe74 100644
--- a/test-suite-kotlin/build.gradle.kts
+++ b/test-suite-kotlin/build.gradle.kts
@@ -10,3 +10,9 @@ dependencies {
     testImplementation(mnTest.micronaut.test.junit5)
     testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
 }
+
+kotlin {
+    jvmToolchain {
+        languageVersion.set(JavaLanguageVersion.of(17))
+    }
+}