Anuken / Mindustry

The automation tower defense RTS
https://mindustrygame.github.io
GNU General Public License v3.0
22.69k stars 2.98k forks source link

Build fails with JDK16 #5114

Closed ghost closed 3 years ago

ghost commented 3 years ago

Platform

Linux, reproduced on NixOS unstable and Debian sid

Build

126.2

Issue

When trying to build Mindustry, this error occurs:

Welcome to Gradle 6.8.3!

Here are the highlights of this release:
 - Faster Kotlin DSL script compilation
 - Vendor selection for Java toolchains
 - Convenient execution of tasks in composite builds
 - Consistent dependency resolution

For more details see https://docs.gradle.org/6.8.3/release-notes.html

To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/6.8.3/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings generic class cache for settings file '/build/Mindustry/settings.gradle' (/build/tmp.gqDSs64dwz/caches/6.8.3/scripts/cjjnld3d55pgftpmv7wz6xg61).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

This means there is currently no supported version of Java that Mindustry can be built with. JDK15 support ended in March 2021.

Steps to reproduce:

Update Java to 16, try to build Mindustry.


Place an X (no spaces) between the brackets to confirm that you have read the line below.

ghost commented 3 years ago

I have confirmed this issue happens in a Debian sid container as well:


pbb@debian:~/Mindustry$ java -version
openjdk version "16" 2021-03-16
OpenJDK Runtime Environment (build 16+36-Debian-4)
OpenJDK 64-Bit Server VM (build 16+36-Debian-4, mixed mode, sharing)

pbb@debian:~/Mindustry$ ./gradlew build
Downloading https://services.gradle.org/distributions/gradle-6.8.3-bin.zip
......................................................................................................

Welcome to Gradle 6.8.3!

Here are the highlights of this release:
 - Faster Kotlin DSL script compilation
 - Vendor selection for Java toolchains
 - Convenient execution of tasks in composite builds
 - Consistent dependency resolution

For more details see https://docs.gradle.org/6.8.3/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings generic class cache for settings file '/home/pbb/Mindustry/settings.gradle' (/home/pbb/.gradle/caches/6.8.3/scripts/cjjnld3d55pgftpmv7wz6xg61).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 7s
pbb@debian:~/Mindustry$
Anuken commented 3 years ago

Gradle 6.8.3 doesn't support JDK 16. Gradle 7.0 does, but Mindustry doesn't support it, as it breaks the Android module with a cryptic error, possibly due to the fact that the Android plugin hasn't been updated to support it. However, I can't update the Android plugin, because any version past the one I'm using breaks default interface method desugaring.

Current solution: Don't use JDK 16; I don't use any features from it anyway.

ghost commented 3 years ago

Thanks for the hint on gradle 7! Not using JDK 16 is not an option, since we will no longer ship the now-unmaintained JDK 15. We have either 8, 11 or 16; all currently supported versions of Java. Since we don't build for Android it might be possible to use gradle 7.

ghost commented 3 years ago

Yeah no, the Android error will be the smallest problem when updating to >=16, many of the com.sun.tools.javac APIs (for which stable replacement APIs exist since 15 years) have been removed or made private.

Anuken commented 3 years ago

for which stable replacement APIs exist since 15 years

What would the replacement APIs be? I wasn't aware of any.

ghost commented 3 years ago

https://openjdk.java.net/jeps/396

Tools that use the com.sun.tools.javac. packages to process source code. Such tools should instead use the javax.tools, javax.lang.model, and com.sun.source. APIs, available since JDK 6.

Anuken commented 3 years ago

Java's internal AnnotationProxyMaker in com.sun.tools.javac has a 7-year-old bug that causes an internal exception when trying to get annotations from certain classes. My only relevant usage of that package comes from a replacement AnnotationProxyMaker class that fixes the bug - everything else can be removed (and will be soon).

Anuken commented 3 years ago

I tried compiling with JDK 16 in my local gradle-7 branch to see what the errors would be, and it seems to work fine..? With all the other unnecessary stuff removed, it doesn't look like my usage of internal API in AnnotationProxyMaker is affecting the build.

EDIT: Nevermind, it looks like my JAVA_HOME was misconfigured. Apparently, even the kapt annotation processing system uses internal javac API, so fixing it my end wouldn't be enough.

EDIT 2: I managed to get it working anyway with some extra compiler arguments, but considering how unstable this branch is, master will continue to be broken on Java 16 for some time.

Anuken commented 3 years ago

As of the build 127 release, Mindustry now supports (and requires) Java 16 for compilation.