i具有以下pom config。我添加了Cobertura插件,现在PMD,CPD,Findbugs和Test正在运行两次。
我明白这是因为我的"阶段"配置,但我不明白如何实现以下操作:
我想要的是在提交回购之前,构建我的应用程序并检查PMD错误,查找bugs错误,检查我的测试并检查我的Cobertura。
我该如何实现?提交之前,我被用来运行" MVN Clean Package"。没关系吗?
这是我的配置:
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<linkXref>false</linkXref>
<rulesets>
<!-- Custom Ruleset -->
<ruleset>codequality/pmd.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>70</branchRate>
<lineRate>70</lineRate>
<totalBranchRate>70</totalBranchRate>
<totalLineRate>70</totalLineRate>
<packageLineRate>70</packageLineRate>
<packageBranchRate>70</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
任何maven插件都有一个默认的执行阶段。在这种情况下,您应用的插件将在验证阶段(PMD-Plugin(中执行。但是您将其定义为在编译阶段也运行。删除相位标签并让其在验证阶段运行。
<execution>
<!--<phase>compile</phase>-->
<goals>
<goal>...</goal>
...
</goals>
</execution>
最后,在提交运行之前验证您的项目的好习惯:
mvn Clean验证