Skip to content

Commit 3963223

Browse files
committed
Setup JDK 8 provisioning with java toolchains
Remove commented out JVM 6 target.
1 parent 6c84554 commit 3963223

File tree

5 files changed

+17
-57
lines changed

5 files changed

+17
-57
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ git submodule init
362362
git submodule update
363363
```
364364

365-
The path to JDK 8 must be specified either with the environment variable `JDK_8` or
366-
with the gradle property `JDK_8`. For local builds, you can use a later version of JDK if you don't have that
367-
version installed.
365+
The project requires JDK 8 to build classes and to run tests.
366+
Gradle will try to find it among the installed JDKs or [provision](https://docs.gradle.org/current/userguide/toolchains.html#sec:provisioning) it automatically if it couldn't be found.
367+
The path to JDK 8 can be additionally specified with the environment variable `JDK_8`.
368+
<!-- For local builds, you can use a later version of JDK if you don't have that
369+
version installed. -->
368370

369371
After that, the project can be opened in IDEA and built with Gradle.

build.gradle.kts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ infra {
1414
}
1515
}
1616

17-
fun jdkPath(version: Int): String {
18-
fun envOrProperty(name: String): String? = System.getenv(name) ?: findProperty(name) as String?
19-
20-
return envOrProperty("JDK_$version") ?:
21-
version.takeIf { it < 9 }?.let { envOrProperty("JDK_1$version") } ?:
22-
error("Specify path to JDK $version in JDK_$version environment variable or Gradle property")
23-
}
24-
//val JDK_6 by ext(jdkPath(6))
25-
val JDK_8 by ext(jdkPath(8))
2617

2718
allprojects {
2819
repositories {

core/build.gradle.kts

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ base {
1717
archivesBaseName = "kotlinx-datetime" // doesn't work
1818
}
1919

20-
//val JDK_6: String by project
21-
val JDK_8: String by project
2220
val serializationVersion: String by project
2321

22+
java {
23+
toolchain { languageVersion.set(JavaLanguageVersion.of(8)) }
24+
}
25+
logger.info("Using JDK 8 toolchain installed in ${javaToolchains.launcherFor(java.toolchain).get().metadata.installationPath}")
26+
2427
kotlin {
2528
explicitApi()
2629

@@ -51,29 +54,11 @@ kotlin {
5154
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
5255
}
5356
compilations.all {
54-
kotlinOptions {
55-
jvmTarget = "1.8"
56-
jdkHome = JDK_8
57-
}
57+
// Set compilation options for JVM target here
5858
}
5959

6060
}
6161

62-
/*
63-
jvm("jvm6") {
64-
this.withJava()
65-
attributes {
66-
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 6)
67-
}
68-
compilations.all {
69-
kotlinOptions {
70-
jvmTarget = "1.6"
71-
jdkHome = JDK_6
72-
}
73-
}
74-
}
75-
*/
76-
7762
js {
7863
nodejs {
7964
// testTask { }
@@ -168,26 +153,12 @@ kotlin {
168153
}
169154
}
170155

171-
/*
172-
val jvm6Main by getting {
173-
dependencies {
174-
api("org.jetbrains.kotlin:kotlin-stdlib")
175-
api("org.threeten:threetenbp:1.4.0")
176-
177-
}
178-
}
179-
val jvm6Test by getting {
180-
dependencies {
181-
api("org.jetbrains.kotlin:kotlin-test-junit")
182-
}
183-
}
184-
*/
185-
186156
val jvmMain by getting {
187157
dependencies {
188158
api("org.jetbrains.kotlin:kotlin-stdlib")
189159
}
190160
}
161+
191162
val jvmTest by getting {
192163
dependencies {
193164
api("org.jetbrains.kotlin:kotlin-test-junit")
@@ -230,7 +201,6 @@ kotlin {
230201
tasks {
231202
named("jvmTest", Test::class) {
232203
// maxHeapSize = "1024m"
233-
// executable = "$JDK_6/bin/java"
234204
}
235205
}
236206

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
org.gradle.jvmargs=-Xmx1G -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2+
org.gradle.java.installations.fromEnv=JDK_8
23

34
group=org.jetbrains.kotlinx
45
version=0.3.1

serialization/build.gradle.kts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ plugins {
55
kotlin("plugin.serialization")
66
}
77

8-
val JDK_8: String by project
98
val serializationVersion: String by project
109

10+
java {
11+
toolchain { languageVersion.set(JavaLanguageVersion.of(8)) }
12+
}
13+
1114
kotlin {
1215
infra {
1316
target("linuxX64")
@@ -32,13 +35,6 @@ kotlin {
3235
attributes {
3336
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
3437
}
35-
compilations.all {
36-
kotlinOptions {
37-
jvmTarget = "1.8"
38-
jdkHome = JDK_8
39-
}
40-
}
41-
4238
}
4339

4440
js {

0 commit comments

Comments
 (0)