2016-05-30 30 views
0

[ここに画像の説明を入力してください] [1] [ここに画像の説明を入力してください] [2]私は多くの答えを示し、ソナーサイトで与えられたサンプルコードを試しました。そのサンプルは正常に動作しています。また、私は次のリンクsonarqubeでテストカバレッジを取得することができません

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

しかし、何を示して私の場合で働いているようです。 mvn clean intsallがindex.htmlにカバレッジレポートを持っているサイトにjacocoフォルダを作っていますが、sonarqubeにITテストカバレッジを表示していません。 ネット上のほとんどのものを試しましたが、問題を解決できませんでした。 マルチモジュールプロジェクト 私は

java8を使用しています。

sonarqube 4.5.6 with java plugin 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> 

プロパティです

<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テストカバレッジが、MVNソナーのためのindex.htmlとjacocoフォルダを作成してクリーンインストール:ソナーはソナークベでそれを見せていません

私は間違っています作る。

mvn sonar:sonarで、正常に構築され、行の1つがJaCoCoSensor:JaCoCoレポートが見つかりません。私は真剣にjacocoまたはsonarqubeでこのバグを感じる理由

何ができるか

。それはJava 8などと互換性がないかもしれません。私はほとんどすべてを試しました。ソナーjavaプラグイン2.5.1では、多くのものが推奨されていません。助けてください、私は必死に解決策が必要です

+0

** sonar.dynamicAnalysis ** 2.5.1 –

+0

がライン上の問題 –

+0

サンプルコードになりますプラグインの組み合わせであってもよいソナーJavaプラグインで廃止されて働いていますそれに統合テストケースがないのでいいです...助けてください。助けてください。 –

答えて

0

ちょうどそれを試して、sample projectが完全に動作します。わからないこれが関連している場合がありますが、SQ Javaプラグイン(2.5.1)の非常に古いバージョンを使っている -

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 

はまた:あなたは次の操作を行うことを確認してください。私はそれを最新のバージョンに更新するようアドバイスするだけです。

+0

Fabriceに感謝します。私は前にサンプルプロジェクトを試しました。とにかく私は今それを解決することができます。 Jacocoプラグインをそのステップを子pomファイルに入れて解決策を得ました。もう一つは、私のモジュールは一つの大きなモジュールなので、ビルドするのは問題だから、argLineをプロパティとして使うのではなく、確かにプラグインで使う –

0

なぜ、上記のコードが動作しないのか分かりませんが、同じことを別の方法で試してみると、奇跡が起こりました。私が解決したことを私に教えてください。

親のpomから以下のコードを削除し、すべての子pomに入れました。また、子モジュールで使用していたので、$ {project.basedir} /../ target/jacoco.execの代わりに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> 
関連する問題