我有一个子项目Project C
,它依赖于Maven的物料清单(BOM)父项目Project P
。父项目Project P
包含一些需要应用于所有子项目的代码样式和格式。
我没有将这些代码样式应用于我的子项目Project C
,因为当我在子项目Project C
上运行mvn clean install
时,会得到以下错误:
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
引用的全部错误:
[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
我想关闭maven中的校验样式选项,并希望构建该项目。如何做到这一点?我尝试了这里提到的一些答案,比如:https://stackoverflow.com/a/70023748/7584240,但是它似乎对我没有用,并且得到了相同的错误。请就这个问题提出一些建议.
如果我删除插件:使用groupId、com.cosium.code
和工件ID:git-code-format-maven-plugin
,但是我不希望对父项目做任何更改,而是处理子项目中的所有内容。
**更新:**
在基于文档进行了一些更改之后,我只获得了一个特定文件的错误。我不知道为什么会出现这个错误,因为它应该跳过所有文件的格式检查。我试图按照intellij格式格式化该文件,但仍然无法构建。
我按照文档将以下内容添加到我的pom.xml中:
<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>
发布于 2022-08-04 12:20:23
您可以跳过在子项目中执行插件,通过绑定插件到阶段none
,例如:
<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>
您还可以通过不继承子模块的配置,在一个指定的模块中执行此操作:
<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>
https://stackoverflow.com/questions/73233068
复制相似问题