相关疑难解决方法(0)

不能在maven中使用jacoco JVM args和surefire JVM args

我正在使用带有jacoco插件的maven 来生成代码覆盖率指标.我有在配置一些困难神火由所需的Java插件的选项jacoco插件.我已经在Stack Overflow上看到了一些关于此问题的答案,但有些东西对我不起作用.

我有一个多模块项目,我的一个模块配置了surefire插件,如下所示:

foo/pom.xml:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <argLine>-XX:MaxPermSize=512m</argLine>
    </configuration>
  </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

这按预期工作.

现在我想结合jacoco获取代码覆盖率的指标,所以我加了一个代码覆盖率配置文件,处理所有jacoco配置:

parent/pom.xml:

<profile>
  <id>CodeCoverage</id>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <executions>
            <execution>
              <id>jacoco-initialize</id>
              <goals><goal>prepare-agent</goal></goals>
              <configuration>
                <propertyName>surefire.argLine</propertyName>
              </configuration>
              ...
            </execution>
          <executions> 
        </plugin>
      </plugins>
    </pluginManagement>
  </build>   
</profile>
Run Code Online (Sandbox Code Playgroud)

它是在这里看到的是,如果代码覆盖率指定配置文件,然后jacoco插件配置为使用surefire.argLine属性,该属性用于配置argLine万无一失插件.

然后我更新了foo模块的pom.xml文件,以使用jacoco插件生成的属性:surefire.argLine

foo/pom.xml:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <argLine>${surefire.argLine} -XX:MaxPermSize=512m</argLine> …
Run Code Online (Sandbox Code Playgroud)

maven maven-surefire-plugin jacoco

60
推荐指数
5
解决办法
4万
查看次数

标签 统计

jacoco ×1

maven ×1

maven-surefire-plugin ×1