Skip to content

Commit

Permalink
Remove toolchain code; use jvmTarget when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed Mar 29, 2024
1 parent 5077df7 commit 7cd914b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 46 deletions.
25 changes: 19 additions & 6 deletions Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ that works with the latest Android tools already.

This should be fixed in 1.12.0.1 by using toolchains; if that doesn't work for you, here are other options.

The simplest solution here is to set your JDK to a Java 17 one and to change `sourceCompatibility` and
`targetCompatibility` to 17 each. A better solution is to use toolchains. In your root build.gradle, you can try adding
The simplest solution here is to set your JDK to a Java 17 one and to change `java.sourceCompatibility` and
`java.targetCompatibility` to 11 each. You may need to set this for both Java and Kotlin, and they must use the same
versions across the board. You can also set the `release` option to the same version as `targetCompatibility` to help
with some incompatibilities between versions; this is only available if you are using Java 9 or later.

```gradle
java.sourceCompatibility = 11
java.targetCompatibility = 11
if (JavaVersion.current().isJava9Compatible()) {
compileJava.options.release.set(11)
}
kotlin.compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
```

Another solution is to use toolchains. In your root build.gradle, you can try adding

```gradle
kotlin {
Expand Down Expand Up @@ -98,10 +111,10 @@ problem on the very first run. They may be what fixes it for the second and late
### Toolchains aren't working or are slow.

This is to be expected in 1.12.1.4, because some configuration was missing for Kotlin projects. That absence has been
fixed in 1.12.1.5. In that version onward, Java also uses toolchains, the same way Kotlin does. This means there can
be a long download for the first time you launch a gdx-liftoff project, but the download will get a JDK and keep it
for any future projects to use (as long as they need the same version). This can be useful if someone wants to build
your project but doesn't necessarily start with the right JVM version -- toolchains ensure they get the right one.
fixed in 1.12.1.5. In that version and in 1.12.1.6, Java also uses toolchains, the same way Kotlin does. This means
there can be a long download for the first time you launch a gdx-liftoff project, but the download will get a JDK and
keep it for any future projects to use (as long as they need the same version). This can be useful if someone wants to
build your project but doesn't necessarily start with the right JVM version -- toolchains ensure they get the right one.

A good option for cross-platform building is to keep the language level on 11 (supported by everything except RoboVM).
This works even on Android; even with its requirements for Java 17 in other places, using a toolchain JDK 11 seems to
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

apply plugin: 'kotlin'
apply plugin: 'java-library'
apply plugin: 'application'
Expand All @@ -20,9 +22,7 @@ mainClassName = 'gdx.liftoff.MainKt'
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

kotlin {
jvmToolchain(8)
}
kotlin.compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)

jar {
manifest {
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/gdx/liftoff/data/files/ProjectFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ class SettingsFile(val platforms: Iterable<Platform>) : ProjectFile {
override fun save(destination: FileHandle) {
val content = platforms.joinToString(
prefix =
"""// Can be used to automatically download a JDK with the correct version.
plugins {
id('org.gradle.toolchains.foojay-resolver-convention') version '0.7.0'
}
// A list of which subprojects to load as part of the same larger project.
"""// A list of which subprojects to load as part of the same larger project.
// You can remove Strings from the list and reload the Gradle project
// if you want to temporarily disable a subproject.
include """,
Expand Down
27 changes: 8 additions & 19 deletions src/main/kotlin/gdx/liftoff/data/files/gradle/RootGradleFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,17 @@ ${plugins.joinToString(separator = "\n") { " apply plugin: '$it'" }}
fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.each {
assetsFile.append(it + "\n")
}
}${if (project.hasPlatform(TeaVM.ID) && plugins.contains("kotlin")) {
}${if (plugins.contains("kotlin")) {
"""
compileKotlin {
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}"""
compileKotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_${
if (project.advanced.javaVersion.removePrefix("1.") == "8") {
"1_8"
} else {
project.advanced.javaVersion.removePrefix("1.")
}})
"""
} else {
""
}}${
if (plugins.contains("kotlin")) {
"""
kotlin {
jvmToolchain(${project.advanced.javaVersion.removePrefix("1.")})
}"""
} else {
"""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(${project.advanced.javaVersion.removePrefix("1.")})
}
}"""
}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,6 @@ class TantrumLibgdx : ThirdPartyExtension() {
}
}


/**
* Tantrum support for RegExodus types.
* @author Tommy Ettinger
Expand Down
18 changes: 8 additions & 10 deletions src/main/kotlin/gdx/liftoff/data/platforms/Android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,15 @@ android {
if (latePlugin) {
"""
kotlin {
jvmToolchain(${project.advanced.javaVersion.removePrefix("1.")})
}"""
kotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_${
if (project.advanced.javaVersion.removePrefix("1.") == "8") {
"1_8"
} else {
project.advanced.javaVersion.removePrefix("1.")
}})
"""
} else {
"""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(${project.advanced.javaVersion.removePrefix("1.")})
}
}"""
""
}}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/gdx/liftoff/data/platforms/IOSMOE.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import gdx.liftoff.data.files.CopiedFile
import gdx.liftoff.data.files.gradle.GradleFile
import gdx.liftoff.data.files.path
import gdx.liftoff.data.project.Project
import gdx.liftoff.views.GdxPlatform

/**
* Represents iOS backend.
*/
//@GdxPlatform
// @GdxPlatform
class IOSMOE : Platform {
companion object {
const val ID = "ios-moe"
Expand Down

0 comments on commit 7cd914b

Please sign in to comment.