Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
reda-alaoui committed May 20, 2022
1 parent 36bcac9 commit 85fca3e
Showing 1 changed file with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@ Documentation from the google-java-format CLI tool :
Do not remove unused imports. Imports will still be sorted.
```

### JDK 16+ peculiarities

Since google-java-format uses JDK internal apis, if you need to run the plugin with JDK 16+, you must pass some additional arguments to the JVM.
Those are described at https://github.com/google/google-java-format/releases/tag/v1.10.0.

Thanks to https://maven.apache.org/configure.html#mvn-jvm-config-file, you should be able to pass them to `.mvn/jvm.config` as follow:

```
--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
```

### Frequently asked questions

#### If I have a multi-module project, do I need to install anything in the sub-projects?
Expand Down

2 comments on commit 85fca3e

@duke1995
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reda-alaoui

According to this comment on the google-java-format GitHub site, the --add-exports flags are still needed when using google-java-format as a library.

See also this #86 (comment)

@duke1995
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reda-alaoui

To be sure, I installed JDK 17 and Maven 3.8.5 to do a test with the latest version of git-code-format-maven-plugin (version 3.4) which uses the latest version of google-java-format (version 1.15.0).

duke1995@laptop:~/dev/prj/demo$ java -version
openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
duke1995@laptop:~/dev/prj/demo$ mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /home/duke1995/PortableApps/apache-maven-3.8.5
Java version: 17.0.3, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-44-generic", arch: "amd64", family: "unix"

Without the .mvn/jvm.config file with the --add-exports flags the commit fails:

duke1995@laptop:~/dev/prj/demo$ git commit -m "This is a test"
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:demo >---------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- git-code-format-maven-plugin:3.4:on-pre-commit (default-cli) @ demo ---
[INFO] Executing pre-commit hooks
[INFO] Formatting 'src/main/java/com/example/App.java'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.223 s
[INFO] Finished at: 2022-05-26T22:21:41+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.4:on-pre-commit (default-cli) on project demo: Execution default-cli of goal com.cosium.code:git-code-format-maven-plugin:3.4:on-pre-commit failed: An API incompatibility was encountered while executing com.cosium.code:git-code-format-maven-plugin:3.4:on-pre-commit: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x46d63dbb) 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 @0x46d63dbb
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>com.cosium.code:git-code-format-maven-plugin:3.4
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/duke1995/.m2/repository/com/cosium/code/git-code-format-maven-plugin/3.4/git-code-format-maven-plugin-3.4.jar
[ERROR] urls[1] = file:/home/duke1995/.m2/repository/commons-io/commons-io/2.7/commons-io-2.7.jar
[ERROR] urls[2] = file:/home/duke1995/.m2/repository/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar
[ERROR] urls[3] = file:/home/duke1995/.m2/repository/org/apache/commons/commons-exec/1.3/commons-exec-1.3.jar
[ERROR] urls[4] = file:/home/duke1995/.m2/repository/com/google/googlejavaformat/google-java-format/1.15.0/google-java-format-1.15.0.jar
[ERROR] urls[5] = file:/home/duke1995/.m2/repository/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar
[ERROR] urls[6] = file:/home/duke1995/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar
[ERROR] urls[7] = file:/home/duke1995/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
[ERROR] urls[8] = file:/home/duke1995/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
[ERROR] urls[9] = file:/home/duke1995/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar
[ERROR] urls[10] = file:/home/duke1995/.m2/repository/com/google/errorprone/error_prone_annotations/2.7.1/error_prone_annotations-2.7.1.jar
[ERROR] urls[11] = file:/home/duke1995/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar
[ERROR] urls[12] = file:/home/duke1995/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/5.13.0.202109080827-r/org.eclipse.jgit-5.13.0.202109080827-r.jar
[ERROR] urls[13] = file:/home/duke1995/.m2/repository/com/googlecode/javaewah/JavaEWAH/1.1.12/JavaEWAH-1.1.12.jar
[ERROR] urls[14] = file:/home/duke1995/.m2/repository/org/apache/maven/maven-builder-support/3.3.9/maven-builder-support-3.3.9.jar
[ERROR] urls[15] = file:/home/duke1995/.m2/repository/org/eclipse/aether/aether-util/1.0.2.v20150114/aether-util-1.0.2.v20150114.jar
[ERROR] urls[16] = file:/home/duke1995/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar
[ERROR] urls[17] = file:/home/duke1995/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar
[ERROR] urls[18] = file:/home/duke1995/.m2/repository/org/eclipse/sisu/org.eclipse.sisu.inject/0.3.2/org.eclipse.sisu.inject-0.3.2.jar
[ERROR] urls[19] = file:/home/duke1995/.m2/repository/com/google/inject/guice/4.0/guice-4.0-no_aop.jar
[ERROR] urls[20] = file:/home/duke1995/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[ERROR] urls[21] = file:/home/duke1995/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.21/plexus-interpolation-1.21.jar
[ERROR] urls[22] = file:/home/duke1995/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.6/plexus-component-annotations-1.6.jar
[ERROR] urls[23] = file:/home/duke1995/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
[ERROR] urls[24] = file:/home/duke1995/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[25] = file:/home/duke1995/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

With the .mvn/jvm.config file with the --add-exports flags the commit succeeds:

duke1995@laptop:~/dev/prj/demo$ git commit -m "This is a test"
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:demo >---------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- git-code-format-maven-plugin:3.4:on-pre-commit (default-cli) @ demo ---
[INFO] Executing pre-commit hooks
[INFO] Formatting 'src/main/java/com/example/App.java'
[INFO] Formatted 'src/main/java/com/example/App.java'
[INFO] Executed pre-commit hooks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.739 s
[INFO] Finished at: 2022-05-26T22:23:59+02:00
[INFO] ------------------------------------------------------------------------
[main 50857a0] This is a test
 1 file changed, 5 insertions(+), 10 deletions(-)

So it would be best to revert the above documentation change for the time being, as you already suggested.

Please sign in to comment.