Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 16+ support #73

Closed
hashworks opened this issue Jul 2, 2021 · 10 comments · Fixed by #74
Closed

Java 16+ support #73

hashworks opened this issue Jul 2, 2021 · 10 comments · Fixed by #74

Comments

@hashworks
Copy link
Contributor

What steps will reproduce the problem?
Steps to reproduce the behavior:

  1. Use openjdk 16
  2. Run mvn git-code-format:format-code
  3. Watch it fail

What is the expected output?
Success

What happens instead?

[INFO] --- git-code-format-maven-plugin:3.0:format-code (default-cli) @ projectname ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.394 s
[INFO] Finished at: 2021-07-02T13:19:12+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.0:format-code (default-cli) on project projectname: Execution default-cli of goal com.cosium.code:git-code-format-maven-plugin:3.0:format-code failed: An API incompatibility was encountered while executing com.cosium.code:git-code-format-maven-plugin:3.0:format-code: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x73d3e555) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x73d3e555
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.cosium.code:git-code-format-maven-plugin:3.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

Environment:

  • OS: Arch Linux
  • Git version: 2.32.0
  • git-code-format-maven-plugin version: 3.0
  • Maven version: 3.8.1
  • Java version: 16.0.1

Additional context
google/google-java-format#538
google/google-java-format#612

@mudlee
Copy link

mudlee commented Jul 6, 2021

It still doesn't work if I use 3.1. Is that possible that it's not been released @reda-alaoui?

@reda-alaoui
Copy link
Member

@mudlee I can confirm that the fix is in 3.1.
You can see the tag at 62a8da7

@reda-alaoui
Copy link
Member

@hashworks does it work for you on 3.1?

@mudlee
Copy link

mudlee commented Jul 6, 2021

See the images below. I've already removed ~/.m2 and cleaned my env, no luck.

1
2
3

@reda-alaoui
Copy link
Member

According to https://github.com/google/google-java-format/releases/tag/v1.10.0, java flags must be passed in addition.

@mudlee
Copy link

mudlee commented Jul 6, 2021

According to https://github.com/google/google-java-format/releases/tag/v1.10.0, java flags must be passed in addition.

Thanks for the blazing fast help! May I ask how can I add these flags in a case of maven? I've tried everything I know, but I cannot pass java args to the plugin :(

@mudlee
Copy link

mudlee commented Jul 6, 2021

OK, prepending the mvnw cli with these below works!

MAVEN_OPTS="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"

@hashworks
Copy link
Contributor Author

Is there a way to add those to the pom.xml or integrate them into the plugin?

@reda-alaoui
Copy link
Member

reda-alaoui commented Jul 8, 2021

The plugin can format/verify code at 2 occasions:

  • after a manual trigger
  • after a commit

To my knowledge, the only way to pass java options for the first case would be to fork a new VM (the same way maven surefire plugin does when asked for). That seems a little overkill for our usecase.

Meanwhile, I think using https://maven.apache.org/configure.html#mvn-jvm-config-file should cleanly solve your issue.

@reda-alaoui
Copy link
Member

I added https://github.com/Cosium/git-code-format-maven-plugin/blob/master/README.md#jdk-16-peculiarities to the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants