Skip to content

Commit

Permalink
Fix JVM targets (#28)
Browse files Browse the repository at this point in the history
- Build with JDK 20
- Target JVM 11 bytecode
  • Loading branch information
chrisbanes authored Nov 9, 2023
1 parent 86e0c54 commit fac1184
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
java-version: 20

- uses: gradle/gradle-build-action@v2

Expand All @@ -48,7 +48,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
java-version: 20

- uses: gradle/gradle-build-action@v2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package dev.chrisbanes.gradle

import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

Expand All @@ -15,6 +16,11 @@ fun Project.configureAndroid() {
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ package dev.chrisbanes.gradle

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType

fun Project.configureJava() {
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
// Build with JDK 20
languageVersion.set(JavaLanguageVersion.of(20))
}
}

// Set Java language version to 11
tasks.withType<JavaCompile>().configureEach { options.release.set(11) }
}

private fun Project.java(action: JavaPluginExtension.() -> Unit) = extensions.configure<JavaPluginExtension>(action)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
package dev.chrisbanes.gradle

import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

fun Project.configureKotlin() {
// Configure Java to use our chosen language level. Kotlin will automatically pick this up
configureJava()

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
allWarningsAsErrors.set(true)

if (this is KotlinJvmCompilerOptions) {
// Target JVM 11 bytecode
jvmTarget.set(JvmTarget.JVM_11)
}
}
}
}

0 comments on commit fac1184

Please sign in to comment.