Maven 目标进行 Cobertura 分析和安装
Maven goals doing cobertura analysis and install
我正在使用 Jenkins
和 Maven
构建一些 Java 项目。此外,我正在使用 Cobertura
进行覆盖率分析。因此,我设置了 Jenkins Maven 构建作业并配置了以下目标:
clean cobertura:cobertura
这对于覆盖率分析工作正常,但不会生成任何在 POM 中配置的 jar 输出。我认为是这样,因为 Maven 目标 package
不在 Cobertura lifecycle.
中
为了获取 jar 文件,我尝试将其更改为
clean cobertura:cobertura install
完成工作但遇到另一个问题:从 resources
到 test
的每个目标都执行了两次 :( 控制台输出看起来像(删除了详细信息行)
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ HelloWorld >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ HelloWorld <<<
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ HelloWorld ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
有没有一种方法可以使用 install
从 cobertura
阶段 resources
到 test
的结果?
换句话说输出像
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ HelloWorld >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ HelloWorld <<<
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ HelloWorld ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ HelloWorld ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
其他信息:无法更改 POM,因为它们不是由我管理的。
简答:没有。通过反复试验,我终于找到了一个解决方案:
离开 Maven 目标如
clean cobertura:cobertura
并添加一个 post 构建步骤来执行 Maven 目标
install -Dmaven.test.skip=true
这样测试就不会执行两次。 compile
和类似的执行了两次,但这还不错,因为 Cobertura 已经编译了所有内容,迫使 Maven 跳过这一步。
注意:clean cobertura:cobertura install -Dmaven.test.skip=true
不可能,因为 test.skip
开关对两个目标都有影响。
我正在使用 Jenkins
和 Maven
构建一些 Java 项目。此外,我正在使用 Cobertura
进行覆盖率分析。因此,我设置了 Jenkins Maven 构建作业并配置了以下目标:
clean cobertura:cobertura
这对于覆盖率分析工作正常,但不会生成任何在 POM 中配置的 jar 输出。我认为是这样,因为 Maven 目标 package
不在 Cobertura lifecycle.
为了获取 jar 文件,我尝试将其更改为
clean cobertura:cobertura install
完成工作但遇到另一个问题:从 resources
到 test
的每个目标都执行了两次 :( 控制台输出看起来像(删除了详细信息行)
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ HelloWorld >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ HelloWorld <<<
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ HelloWorld ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
有没有一种方法可以使用 install
从 cobertura
阶段 resources
到 test
的结果?
换句话说输出像
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWorld ---
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ HelloWorld >>>
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ HelloWorld ---
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ HelloWorld ---
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ HelloWorld ---
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ HelloWorld ---
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ HelloWorld ---
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ HelloWorld <<<
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ HelloWorld ---
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ HelloWorld ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ HelloWorld ---
其他信息:无法更改 POM,因为它们不是由我管理的。
简答:没有。通过反复试验,我终于找到了一个解决方案:
离开 Maven 目标如
clean cobertura:cobertura
并添加一个 post 构建步骤来执行 Maven 目标
install -Dmaven.test.skip=true
这样测试就不会执行两次。 compile
和类似的执行了两次,但这还不错,因为 Cobertura 已经编译了所有内容,迫使 Maven 跳过这一步。
注意:clean cobertura:cobertura install -Dmaven.test.skip=true
不可能,因为 test.skip
开关对两个目标都有影响。