Closed ZacSweers closed 2 years ago
The way we handle this with google-java-format is to add it to the exec prefix like so
private val EXEC_PREFIX =
"""#!/bin/sh
exec java \
-Xmx512m \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
-jar "${'$'}0" "${'$'}@"
""".trimIndent()
You could update this line to do the same with the requisite args https://github.com/pinterest/ktlint/blob/94f42e0514d7b919986c1293372943bcc1adf2ac/ktlint/build.gradle#L57
One down side is it makes the CLI jar unusable on JDK versions <9. Another solution would be to publish two CLI jars - one with the exec prefix and one without (where folks that need to add extra commands can use the latter and repackage it themselves, like we do with GJF)
Thx for sharing the solution above. I would not be surprised if this relates to #1271 in which it is reported that ktlint no longer works on jdk8.
You don't need to add all those opens. You just need to add one. I altered the build.gradle like so :
it.write "#!/bin/sh\n\nexec java --add-opens java.base/java.lang=ALL-UNNAMED -Xmx512m -jar \"\$0\" \"\$@\"\n\n".bytes
And it works fine on Java 17.
I'd put in a PR, but I see in this thread that this would break Java 8? The --add-opens
is required for JDK 16+, and that cmd is unknown to JDK 8. You could either remove the reflection (seems unlikely), or have the shell detect the JDK version and use the appropriate cmd-line, or create / release two bins.
@paul-dingemans I do not think it is related to #1271
For maven I've added <jvmarg line="--add-opens java.base/java.lang=ALL-UNNAMED"/>
to my maven-antrun-plugin configuration to get it working with Java 17.
Let's track this in #1195
@nahguam
For maven I've added
<jvmarg line="--add-opens java.base/java.lang=ALL-UNNAMED"/>
to my maven-antrun-plugin configuration to get it working with Java 17. Can you please help with the complete excerpt of the antrun plugin?
See ktlint documentation.
Expected Behavior
I expect KtLint's fat jar on CLI to add requisite opens to run
Observed Behavior
It crashes when using JDK 16 or later
You can see this warning on older JDKs as well
Steps to Reproduce
Run the KtLint CLI binary with JDK 16
Your Environment