|
1 | 1 | import kotlinx.team.infra.mavenPublicationsPom
|
| 2 | +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
2 | 3 | import java.net.URL
|
3 | 4 | import java.util.Locale
|
4 | 5 | import javax.xml.parsers.DocumentBuilderFactory
|
|
18 | 19 | }
|
19 | 20 |
|
20 | 21 | //val JDK_6: String by project
|
21 |
| -//val JDK_8: String by project |
22 |
| -val JDK_11: String by project |
| 22 | +val JDK_8: String by project |
23 | 23 | val serializationVersion: String by project
|
24 | 24 |
|
25 | 25 | kotlin {
|
@@ -54,7 +54,7 @@ kotlin {
|
54 | 54 | compilations.all {
|
55 | 55 | kotlinOptions {
|
56 | 56 | jvmTarget = "1.8"
|
57 |
| - jdkHome = JDK_11 |
| 57 | + jdkHome = JDK_8 |
58 | 58 | }
|
59 | 59 | }
|
60 | 60 |
|
@@ -199,7 +199,7 @@ kotlin {
|
199 | 199 | dependencies {
|
200 | 200 | api("org.jetbrains.kotlin:kotlin-stdlib-js")
|
201 | 201 | api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
|
202 |
| - implementation(npm("@js-joda/core", "3.2.0")) |
| 202 | + implementation(npm("@js-joda/core", "3.2.0")) |
203 | 203 | }
|
204 | 204 | }
|
205 | 205 |
|
@@ -233,6 +233,81 @@ tasks {
|
233 | 233 | // maxHeapSize = "1024m"
|
234 | 234 | // executable = "$JDK_6/bin/java"
|
235 | 235 | }
|
| 236 | + |
| 237 | + create("compileJavaModuleInfo", JavaCompile::class) { |
| 238 | + val compileKotlinJvm = getByName<KotlinCompile>("compileKotlinJvm") |
| 239 | + val sourceDir = file("jvm/java9/") |
| 240 | + val targetFile = compileKotlinJvm.destinationDir.resolve("../module-info.class") |
| 241 | + |
| 242 | + // Use a Java 11 compiler for the module info. |
| 243 | + javaCompiler.set(project.javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(11)) }) |
| 244 | + |
| 245 | + // Always compile kotlin classes before the module descriptor. |
| 246 | + dependsOn(compileKotlinJvm) |
| 247 | + |
| 248 | + // Add the module-info source file. |
| 249 | + source(sourceDir) |
| 250 | + |
| 251 | + // Also add the module-info.java source file to the Kotlin compile task. |
| 252 | + // The Kotlin compiler will parse and check module dependencies, |
| 253 | + // but it currently won't compile to a module-info.class file. |
| 254 | + // Note that module checking only works on JDK 9+, |
| 255 | + // because the JDK built-in base modules are not available in earlier versions. |
| 256 | + val javaVersion = compileKotlinJvm.kotlinJavaToolchain.javaVersion.orNull |
| 257 | + // Note: extra sanity check, because `jdkHome` might be overridden, this can be |
| 258 | + // removed once https://github.com/Kotlin/kotlinx-datetime/pull/155/files is merged. |
| 259 | + val isJava8 = compileKotlinJvm.kotlinOptions.jdkHome?.contains("1.8") == true |
| 260 | + if (!isJava8 && javaVersion?.isJava9Compatible == true) { |
| 261 | + logger.info("Module-info checking is enabled; $compileKotlinJvm is compiled using Java $javaVersion") |
| 262 | + compileKotlinJvm.source(sourceDir) |
| 263 | + } else { |
| 264 | + logger.info("Module-info checking is disabled") |
| 265 | + } |
| 266 | + |
| 267 | + // This task outputs only the module-info class file. |
| 268 | + outputs.file(targetFile) |
| 269 | + |
| 270 | + // Use the same destination dir to see classes compiled by compileKotlinJvm. |
| 271 | + destinationDir = compileKotlinJvm.destinationDir |
| 272 | + |
| 273 | + // Configure JVM compatibility |
| 274 | + sourceCompatibility = JavaVersion.VERSION_1_9.toString() |
| 275 | + targetCompatibility = JavaVersion.VERSION_1_9.toString() |
| 276 | + |
| 277 | + // Use an empty classpath, since we are using a module path instead. |
| 278 | + classpath = files() |
| 279 | + |
| 280 | + doFirst { |
| 281 | + // Create the module path that will be passed to the compiler instead of a classpath. |
| 282 | + // The module path should be the same as the classpath of the compiler. |
| 283 | + val modulePath = compileKotlinJvm.classpath.asPath |
| 284 | + |
| 285 | + options.compilerArgs = listOf( |
| 286 | + "--release", "9", |
| 287 | + "--module-path", modulePath, |
| 288 | + "-Xlint:-requires-transitive-automatic" |
| 289 | + ) |
| 290 | + } |
| 291 | + |
| 292 | + doLast { |
| 293 | + // Move the compiled file out of the Kotlin compile task's destination dir, |
| 294 | + // so it won't disturb Gradle's caching mechanisms. |
| 295 | + val compiledFile = destinationDir.resolve(targetFile.name) |
| 296 | + targetFile.parentFile.mkdirs() |
| 297 | + compiledFile.renameTo(targetFile) |
| 298 | + } |
| 299 | + |
| 300 | + // Configure the JAR task so it will include the compile module-info class file. |
| 301 | + getByName<Jar>("jvmJar") { |
| 302 | + dependsOn(this@create) |
| 303 | + manifest { |
| 304 | + attributes("Multi-Release" to true) |
| 305 | + } |
| 306 | + from(targetFile) { |
| 307 | + into("META-INF/versions/9/") |
| 308 | + } |
| 309 | + } |
| 310 | + } |
236 | 311 | }
|
237 | 312 |
|
238 | 313 | task("downloadWindowsZonesMapping") {
|
|
0 commit comments