0

I have a child project Project C which has a dependency on the Maven's Bill of Materials (BOM) parent project Project P. The parent project Project P contains some of the code styles and formatting which needs to be applied to all the child project.

I do not which to apply these code styles to my child project Project C due to which when I run the mvn clean install on the child project Project C, I get the error:

An API incompatibility was encountered while executing com.cosium.code:git-code-format-maven-plugin:3.4:validate-code-format: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x56da96b3) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind

Full error for the reference:

[ERROR] Failed to execute goal com.cosium.code:git-code-format-maven-plugin:3.4:validate-code-format (validate-code-format) on project project-c: Execution validate-code-format of goal com.cosium.code:git-code-format-maven-plugin:3.4:validate-code-format failed: 
An API incompatibility was encountered while executing com.cosium.code:git-code-format-maven-plugin:3.4:validate-code-format: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x4a320414) 
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 @0x4a320414

I would like to turn off the checkstyle option in maven and would like to build the project. How to achieve this? I tried some of the answers mentioned here such as: https://stackoverflow.com/a/70023748/7584240 but it does not seem to work for me at all and getting the same error. Please suggest some work-arounds to this issue.

If I remove the plugin: with groupId com.cosium.code and artifact ID: git-code-format-maven-plugin but I do not wish to make any change to parent project rather handle everything in child project.

**Updated: **

After making some changes based on the documentation, I am getting the error for only one particular file. I am not sure why am I getting that error because it should skip the checking of the formatting for all the file. I tried to format that file as per intellij formatting but still build is failing.

I have added following to my pom.xml as per documentation:

<plugin>
  <groupId>com.cosium.code</groupId>
  <artifactId>git-code-format-maven-plugin</artifactId>
  <version>${git-code-format-maven-plugin.version}</version>
  <configuration>
      <skip>true</skip>
      <googleJavaFormatOptions>
          <aosp>false</aosp>
      </googleJavaFormatOptions>
  </configuration>
</plugin> 
BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
  • have you read documentation? https://github.com/Cosium/git-code-format-maven-plugin clearly states that for `JDK 16+` you need to setup JVM arguments in `.mvn/jvm.config` – Andrey B. Panfilov Aug 04 '22 at 09:15
  • @AndreyB.Panfilov Thanks a lot for your response. I have done this and getting error for only one particular file now. I am not sure why am I getting the error for that file. I am trying to skip all formatting. I get the path to the file then followed by message `is not correctly formatted ! -> [Help 1]`. Can you please let me know how to fix this? – BATMAN_2008 Aug 04 '22 at 11:02

1 Answers1

0

You can skip executing plugin at all in child project, by bind plugin to phase none, eg:

<plugin>
  <groupId>com.cosium.code</groupId>
  <artifactId>git-code-format-maven-plugin</artifactId>
  <executions>
    <execution>
     <id>validate-code-format</id><!-- the same as in parent -->
     <phase>none</phase>
    </execution>
  </executions>
</plugin> 

You can also do it in one specified module by not inherited configuration to child module:

<plugin>
  <groupId>com.cosium.code</groupId>
  <artifactId>git-code-format-maven-plugin</artifactId>
  <executions>
    <execution>
     <inherited>false</inherited>
     <id>validate-code-format</id><!-- the same as in parent -->
     <phase>none</phase>
    </execution>
  </executions>
</plugin> 
Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
  • Thanks a lot for the response. I do not wish to disable it in all the child projects but only in this particular child project, I want to disable it. Suppose we are disabling in all child projects then what the point in adding this in the first place is? Please let me know if there is a way I can disable in particular child projects. – BATMAN_2008 Aug 04 '22 at 13:33
  • @BATMAN_2008 I added next example - maybe it will be what you are looking for. – Slawomir Jaranowski Aug 05 '22 at 17:18