Skip to content

Commit

Permalink
chore(build): Derive our java target from what the API declares
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Jan 24, 2024
1 parent 81426e2 commit 82a4e85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion SpongeAPI
12 changes: 7 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ plugins {

val commonProject = project
val apiVersion: String by project
val apiJavaTarget: String by project
val minecraftVersion: String by project
val recommendedVersion: String by project

Expand Down Expand Up @@ -307,11 +308,12 @@ allprojects {
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
if (JavaVersion.current() < JavaVersion.VERSION_17) {
val targetJavaVersion = JavaVersion.toVersion(apiJavaTarget.toInt())
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion
if (JavaVersion.current() < targetJavaVersion) {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(apiJavaTarget.toInt()))
}
}
}
Expand Down Expand Up @@ -345,7 +347,7 @@ allprojects {
withType(JavaCompile::class).configureEach {
options.compilerArgs.addAll(listOf("-Xmaxerrs", "1000"))
options.encoding = "UTF-8"
options.release.set(17)
options.release.set(apiJavaTarget.toInt())
if (project.name != "testplugins" && System.getProperty("idea.sync.active") != null) {
options.annotationProcessorPath = emptyAnnotationProcessors // hack so IntelliJ doesn't try to run Mixin AP
}
Expand Down
5 changes: 3 additions & 2 deletions vanilla/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {

val commonProject = parent!!
val apiVersion: String by project
val apiJavaTarget: String by project
val minecraftVersion: String by project
val recommendedVersion: String by project
val organization: String by project
Expand Down Expand Up @@ -66,7 +67,7 @@ val vanillaInstallerJava9 by sourceSets.register("installerJava9") {
sequenceOf(runtimeClasspathConfigurationName, compileClasspathConfigurationName).map(configurations::named).forEach {
it.configure {
attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, apiJavaTarget.toInt())
}
}
}
Expand Down Expand Up @@ -180,7 +181,7 @@ minecraft {
}

configureEach {
targetVersion(17)
targetVersion(apiJavaTarget.toInt())
workingDirectory(project.file("run/"))
if (org.spongepowered.gradle.vanilla.internal.util.IdeConfigurer.isIdeaImport()) { // todo(zml): promote to API... eventually
// IntelliJ does not properly report its compatibility
Expand Down

0 comments on commit 82a4e85

Please sign in to comment.