Skip to content

Commit e0dcb9f

Browse files
authored
KTLN-246 - Configure Kotlin's bytecode version with Gradle (#1107)
* add module * add class * build test * downgrade to java 11 * split project * split, to avoid redundance * groovy to kts * skip * update kts * remove unused plugin * try remove toolchain * remove unused test * merge module * clean * targetCompatibility to release
1 parent 9d4ccf8 commit e0dcb9f

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
4+
plugins {
5+
kotlin("jvm") version "2.0.0"
6+
}
7+
8+
group = "com.baeldung"
9+
version = "1.0-SNAPSHOT"
10+
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
testImplementation("org.jetbrains.kotlin:kotlin-test")
18+
}
19+
20+
tasks.test {
21+
useJUnitPlatform()
22+
}
23+
24+
// compileKotlin, compileKotlinTest
25+
kotlin {
26+
compilerOptions {
27+
jvmTarget.set(JvmTarget.JVM_11)
28+
}
29+
}
30+
31+
tasks.compileJava {
32+
options.release.set(11)
33+
}
34+
35+
// Reaching Test Source Only
36+
tasks.compileTestJava {
37+
options.release.set(11)
38+
}
39+
40+
tasks.compileTestKotlin {
41+
compilerOptions {
42+
jvmTarget.set(JvmTarget.JVM_11)
43+
}
44+
}
45+
46+
// configureEach
47+
tasks.withType<KotlinCompile>().configureEach {
48+
compilerOptions {
49+
jvmTarget.set(JvmTarget.JVM_11)
50+
}
51+
}
52+
53+
tasks.withType(JavaCompile::class).configureEach {
54+
options.release.set(11)
55+
}
56+
57+
// toolChain
58+
kotlin {
59+
jvmToolchain(11)
60+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung
2+
3+
class Main {
4+
companion object {
5+
@JvmStatic
6+
fun main(args: Array<String>) {
7+
println("Just for test bytecode version!")
8+
}
9+
}
10+
}

gradle-kotlin-dsl/settings.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
rootProject.name = "gradle-kotlin-dsl"
22

3-
include("gradle-kotlin-dsl", "custom-source-set")
3+
include(
4+
"gradle-kotlin-dsl",
5+
"custom-source-set",
6+
"configure-bytecode")

0 commit comments

Comments
 (0)