Cosium / git-code-format-maven-plugin

A maven plugin that automatically deploys code formatters as pre-commit git hook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java 16+ support

hashworks opened this issue · comments

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

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

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

@hashworks does it work for you on 3.1?

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

1
2
3

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

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 :(

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"

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

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.