我有一个multimodule maven项目,我喜欢在构建多模块的过程中执行java类。
Java类是子模块的一部分,所以我尝试添加exec-maven-plugin
,但它始终失败并带有ClassNotFoundException
该部分看起来像
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>build-dump</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.sonar.plugins.coffeelint2java.Coffeelint2Java</mainClass>
<arguments>
<argument>${rules.path}</argument>
</arguments>
</configuration>
</plugin>
这导致
Caused by: java.lang.NoClassDefFoundError: org/sonar/check/Priority
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.getPriority(CheckTemplateWriter.java:126)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.checkLevelLine(CheckTemplateWriter.java:107)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.lambda$generateReplacementMapping$3(CheckTemplateWriter.java:86)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter$$Lambda$5/161691919.accept(Unknown Source)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.generateReplacementMapping(CheckTemplateWriter.java:84)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.generate(CheckTemplateWriter.java:52)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.doGenerateChecks(Coffeelint2Java.java:72)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.generateChecks(Coffeelint2Java.java:59)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.lambda$generateChecks$1(Coffeelint2Java.java:51)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java$$Lambda$4/1333998550.accept(Unknown Source)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.generateChecks(Coffeelint2Java.java:51)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.main(Coffeelint2Java.java:41)
... 6 more
声纳依赖是在父pom中定义的,但是当我将它添加到子模块pom中的<dependency>
部分时,它会返回相同的结果。
如何正确定义pom,在执行主类时包含依赖项?
===更新=== 父pom中的依赖是
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
<artifactId>sslr-squid-bridge</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
子模块本身也添加了其他依赖项
<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
</dependencies>
答案 0 :(得分:1)
在更新我的问题并向其添加依赖关系信息之后,我自己就看到了。
提供的属性是问题所在。哎呀
删除它解决了问题