Maven:组合两个配置文件时没有覆盖范围



我有一个maven构建,其中包含两个相关的概要文件,称为集成构建(用于运行集成测试(和声纳(用于覆盖(。

  • 没有覆盖的集成构建有效
  • 没有集成测试的正常构建+声纳工程中的覆盖范围(覆盖范围出现在sonarqube中(
  • 具有覆盖率的集成构建不起作用(覆盖率为0(

所以最后一种类型的构建失败。我的命令是:

mvn clean install -Pintegration-build,sonar

这似乎是我的集成构建专家简介中的相关部分:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>-Xms256m -Xmx2048m</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<argLine>-Xms256m -Xmx2048m</argLine>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

这是我的声纳档案:

<profile>
<id>sonar</id>
<properties>
<envTarget>tst</envTarget>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>@{surefire.argLine} -Xms256m -Xmx2048m</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<argLine>@{failsafe.argLine} -Xms256m -Xmx2048m</argLine>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>surefire.argLine</propertyName>
<destFile>${project.basedir}/target/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.basedir}/target/jacoco.exec</dataFile>
</configuration>
</execution>
<execution>
<id>pre-it-test</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>failsafe.argLine</propertyName>
<destFile>${project.basedir}/target/jacoco-it.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-it-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.basedir}/target/jacoco-it.exec</dataFile>
</configuration>
</execution>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<createChecksum>true</createChecksum>
</configuration>
</plugin>
</plugins>
</build>
</profile>

现在,我在集成构建概要文件中更新了以下几行:<argLine>-Xms256m -Xmx2048m</argLine><argLine>@{surefire.argLine} -Xms256m -Xmx2048m</argLine><argLine>-Xms256m -Xmx2048m</argLine><argLine>@{failsafe.argLine} -Xms256m -Xmx2048m</argLine>

然后它就起作用了。在他之后,我运行mvn声纳:声纳-Psonar和我进行了集成测试和覆盖。

但当我现在只使用集成构建配置文件(没有声纳(运行时,它就会失败!然后我会得到错误,比如:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test (default-test) on project app-models: There are test failures.
[ERROR] 
[ERROR] Please refer to /srv/path//build/build-IB/app-models/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd "/srv/autobuild/workspace/build/build-IB/app-models" && /srv/path/tools/hudson.model.JDK/IBM-JDK8-x86_64/jre/bin/java '@{surefire.argLine}' -Xms256m -Xmx2048m -jar '/srv/autobuild/workspace/build/build-IB/app-models/target/surefire/surefirebooter6984324204710827506.jar' '/srv/autobuild/workspace/build/build-IB/app-models/target/surefire' 2020-03-20T11-00-50_881-jvmRun1 surefire5755643707151660451tmp surefire_04579178873474557152tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd "/srv/path/workspace/build/build-IB/app-models" && /srv/path/tools/hudson.model.JDK/IBM-JDK8-x86_64/jre/bin/java '@{surefire.argLine}' -Xms256m -Xmx2048m -jar '/srv/path/workspace/build/build-IB/app-models/target/surefire/surefirebooter6984324204710827506.jar' '/srv/path/workspace/build/build-IB/app-models/target/surefire' 2020-03-20T11-00-50_881-jvmRun1 surefire5755643707151660451tmp surefire_04579178873474557152tmp

如何解决此问题,但保留我的保险范围?

我认为主要的问题是,当两个配置文件都激活时,您将<configuration>放在了故障保护和surefire插件中,这是不兼容的。

请记住,配置文件在激活时会被合并。所以你突然有了两个<argLine>定义等

我想你需要把尽可能多的<configuration>转移到需要它的<execution>

最新更新