我有一个maven build,其中有2个相关的概要文件,称为Integration-build(运行集成测试)和声纳(用于覆盖)。
没有覆盖的集成构建有效
没有集成测试的正常构建+声纳工程的覆盖范围(声纳显示在声纳中)
具有覆盖率的集成构建不起作用(覆盖率为0)
因此最后一种构建失败。我的命令是:
mvn clean install -Pintegration-build,sonar
这似乎是我的集成构建Maven配置文件中的相关部分:
<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 sonar:sonar -Psonar之后,我进行了集成测试和覆盖。
但是,当我现在仅使用Integration-Build Profile(没有声纳)运行时,它将失败!
然后我得到如下错误:
[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>
中。