Skip to content

Commit

Permalink
KTLN-246 - Configure Kotlin's bytecode version with Gradle (Baeldung#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
hangga authored Sep 30, 2024
1 parent 9d4ccf8 commit e0dcb9f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
60 changes: 60 additions & 0 deletions gradle-kotlin-dsl/configure-bytecode/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "2.0.0"
}

group = "com.baeldung"
version = "1.0-SNAPSHOT"


repositories {
mavenCentral()
}

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
}

tasks.test {
useJUnitPlatform()
}

// compileKotlin, compileKotlinTest
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

tasks.compileJava {
options.release.set(11)
}

// Reaching Test Source Only
tasks.compileTestJava {
options.release.set(11)
}

tasks.compileTestKotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

// configureEach
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

tasks.withType(JavaCompile::class).configureEach {
options.release.set(11)
}

// toolChain
kotlin {
jvmToolchain(11)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.baeldung

class Main {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("Just for test bytecode version!")
}
}
}
5 changes: 4 additions & 1 deletion gradle-kotlin-dsl/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rootProject.name = "gradle-kotlin-dsl"

include("gradle-kotlin-dsl", "custom-source-set")
include(
"gradle-kotlin-dsl",
"custom-source-set",
"configure-bytecode")

0 comments on commit e0dcb9f

Please sign in to comment.