2016-05-30 51 views
0

测试范围[1] [我在这里输入图像] [2]我知道很多人都有类似的问题。我展示了很多answars,尝试了声纳网站上给出的示例代码。该示例工作正常。另外我给下面的链接不能得到它sonarqube

How to configure multi-module Maven + Sonar + JaCoCo to give merged coverage report?

,但似乎没有我的情况下工作。它没有在sonarqube中显示IT测试覆盖率,尽管mvn clean intsall在index.html正在进行覆盖报告的站点上制作jacoco文件夹。 我几乎在网上尝试了所有东西,但无法解决问题。 其多模块项目 我正在使用

java8。

sonarqube 4.5.6带有java插件2.5.1。

maven 3.0.5

请帮我解决这个问题。

下面是父模块POM文件

<build> 
<pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.jacoco</groupId> 
       <artifactId>jacoco-maven-plugin</artifactId> 
       <version>${jacoco-maven-plugin.version}</version> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>${maven-compiler-plugin.version}</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </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> 
         <destFile>${project.basedir}/target/jacoco.exec</destFile> 
         <propertyName>surefireArgLine</propertyName> 
        </configuration> 
       </execution> 
       <execution> 
        <id>post-unit-test</id> 
        <phase>test</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
        <configuration> 
         <!-- Sets the path to the file which contains the execution data. --> 
         <dataFile>${project.build.directory}/../target/jacoco.exec</dataFile> 
        </configuration> 
       </execution> 
       <execution> 
        <id>pre-integration-test</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
        <configuration> 
         <destFile>${project.basedir}/../target/jacoco-it.exec</destFile> 
         <propertyName>failsafe.argLine</propertyName> 
        </configuration> 
       </execution> 
       <execution> 
        <id>post-integration-test</id> 
        <phase>post-integration-test</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
        <configuration> 
         <dataFile>${project.basedir}/../target/jacoco-it.exec</dataFile> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>${maven-surefire-plugin.version}</version> 
      <configuration> 
       <!-- Sets the VM argument line used when unit tests are run. --> 
       <argLine>${surefireArgLine}</argLine> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <version>${maven-failsafe-plugin.version}</version> 
      <configuration> 
       <argLine>${failsafe.argLine}</argLine> 
       <includes> 
        <include>**/*Test.java</include> 
       </includes> 
      </configuration> 
      <executions> 
       <execution> 
        <id>integration-test</id> 
        <goals> 
         <goal>integration-test</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>verify</id> 
        <goals> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- automatic label creation --> 

    </plugins> 
    </build> 
    <!-- Plugin to generate unit test coverage in SonarQube 4.5.x report. --> 

<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <configuration> 
      <use>false</use> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-report-plugin</artifactId> 
      <version>${maven-surefire-report-plugin.version}</version> 
      <configuration> 
       <alwaysGenerateFailsafeReport>true</alwaysGenerateFailsafeReport> 
       <alwaysGenerateSurefireReport>true</alwaysGenerateSurefireReport> 
       <aggregate>true</aggregate> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>${jacoco-maven-plugin.version}</version> 
      <configuration> 
       <excludes> 
        <exclude>**/*.mar</exclude> 
        <exclude>${jacoco.excludePattern}</exclude> 
       </excludes> 
      </configuration> 
     </plugin> 
    </plugins> 
</reporting> 

在同一POM文件属性

<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath> <!-- This is the default, put here to be explicit --> 
    <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath> 
    <sonar.language>java</sonar.language> 
    <sonar.java.binaries>${project.basedir}/../target/classes</sonar.java.binaries> 
    <jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version> 
    <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> 
    <maven-surefire-report-plugin.version>2.19.1</maven-surefire-report-plugin.version> 
    <maven-surefire-plugin.version>2.16</maven-surefire-plugin.version> 
    <maven-failsafe-plugin.version>2.16</maven-failsafe-plugin.version> 

MVN干净的安装创造将以index.html jacoco文件夹中的测试覆盖率,但MVN声纳:sonarqube声纳不显示它

我是什么错误 制造。声纳:它建立成功,其中一条线是JaCoCoSensor:JaCoCo报告未找到。

可能是什么原因

我认真地觉得这与jacoco或sonarqube的错误。可能它不会与java 8兼容。我尝试了几乎所有的东西。声纳java插件2.5.1弃用了很多东西。请帮助我,我需要解决方案拼命

+0

** ** sonar.dynamicAnalysis用声纳Java插件2.5.1 –

+0

可能是插件将上线问题 –

+0

示例代码的组合弃用工作好,因为没有集成测试用例....请帮我 –

回答

0

刚刚尝试过,sample project完美。请确保你做到以下几点:

git clone https://github.com/SonarSource/sonar-examples.git 
cd projects/languages/java/code-coverage/combined ut-it/combined-ut-it-multimodule-maven-jacoco 
mvn clean package 
mvn sonar:sonar 

也 - 不知道这是相关的,但您使用的是很旧版本的SQ Java插件(2.5.1)的。我只能建议你将它更新到最新版本。

+0

谢谢Fabrice。我曾经尝试过示例项目。无论如何,我现在能够解决它。通过将Jacoco插件的步骤放在子文件夹中,我得到了解决方案。还有一件事,我的模块是一个大模块,所以,构建它是给出了问题,所以我使用argLine作为属性,而不是在surefire插件中 –

0

嗯,我不知道为什么上面的代码不工作,但我尝试相同的事情有点不同,奇迹发生。让我解决它对我的工作。

我从父pom中删除了下面的代码,并把它放在所有的孩子pom中。另外,因为我在子模块中使用它,我使用target/jacoco.exec而不是$ {project.basedir} /../target/jacoco.exec,对于jacoco-it.exec也是如此。

<plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <executions> 
      <execution> 
       <id>pre-unit-test</id> 
       <goals> 
        <goal>prepare-agent</goal> 
       </goals>  
       <configuration> 
        <destFile>target/jacoco.exec</destFile> 
        <propertyName>surefireArgLine</propertyName> 
        <append>true</append> 
       </configuration> 
      </execution> 
      <execution> 
       <id>post-unit-test</id> 
       <phase>test</phase> 
       <goals> 
        <goal>report</goal> 
       </goals> 
       <configuration> 
        <!-- Sets the path to the file which contains the execution data. --> 
        <dataFile>target/jacoco.exec</dataFile> 
       </configuration> 
      </execution> 
      <execution> 
       <id>pre-integration-test</id> 
       <phase>pre-integration-test</phase> 
       <goals> 
        <goal>prepare-agent</goal> 
       </goals> 
       <configuration> 
        <destFile>target/jacoco-it.exec</destFile> 
        <propertyName>failsafe.argLine</propertyName> 
        <append>true</append> 
       </configuration> 
      </execution> 
      <execution> 
       <id>post-integration-test</id> 
       <phase>post-integration-test</phase> 
       <goals> 
        <goal>report</goal> 
       </goals> 
       <configuration> 
        <dataFile>target/jacoco-it.exec</dataFile> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 

其他信息。下面的插件,我提到我的问题是不需要如果测试覆盖率只需要声纳报告。如果没有为代码报告要求另行那么它需要

<plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>${jacoco-maven-plugin.version}</version> 
     <configuration> 
      <excludes> 
       <exclude>**/*.mar</exclude> 
       <exclude>${jacoco.excludePattern}</exclude> 
      </excludes> 
     </configuration> 
    </plugin>