2016-05-30 5 views
0

[Bildbeschreibung hier eingeben] [1] [Bildbeschreibung hier eingeben] [2] Ich weiß, dass viele Leute solch ähnliches Problem haben. Ich zeige viele Antworten, probierte den Beispielcode, der auf Sonarseite gegeben wurde. dieses Beispiel funktioniert gut. Ich zeige folgenden auch LinkNicht in der Lage, es Testabdeckung in Sonarqube zu bekommen

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

aber nichts scheint in meinem Fall arbeiten. Es zeigt keine IT-Testabdeckung in sonarqube, obwohl mvn clean intsall den jacoco-Ordner in der Site erstellt, in der index.html einen Abdeckungsbericht hat. Ich versuchte fast alles auf dem Netz, aber nicht in der Lage, Problem zu lösen. ist es ein Multi-Modul-Projekt Ich verwende

java8.

sonarqube 4.5.6 mit Java-Plugin 2.5.1.

Maven 3.0.5

mir bitte helfen, dieses Problem zu beheben.

Nachfolgend finden Eltern Modul pom Datei

<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> 

Eigenschaften in derselben pom Datei

<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 saubere Installation für Testabdeckung jacoco Ordner mit index.html schafft aber mvn Sonar : Sonar zeigt es nicht in Sonarqube

was für ein Fehler ich bin machen.

in mvn Sonar: Sonar, es baut erfolgreich und einer der Linie ist JaCoCoSensor: JaCoCo Bericht nicht gefunden.

, was der Grund sein könnte

ich dies ernsthaft das Gefühl einen Fehler mit jacoco oder Sonarqube. Vielleicht wäre es nicht kompatibel mit Java 8 oder etwas. Ich habe fast alles ausprobiert. Viele Dinge sind veraltet mit Sonar Java Plugin 2.5.1. Bitte helfen Sie mir, ich brauche die Lösung verzweifelt

+0

** sonar.dynamicAnalysis ** mit Sonar Java Plugin ist veraltet 2.5.1 –

+0

Kombination von Plugins werden kann, wären der Problem –

+0

Beispielcode auf der Leitung arbeiten gut, weil es keine Integrationstestfälle darin gibt .... Bitte helfen Sie mir bitte –

Antwort

0

Probieren Sie es einfach, und die sample project funktioniert perfekt. Bitte stellen Sie sicher, dass Sie wie folgt vor:

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 

auch - nicht sicher, ob dies ist verwandt, aber Sie verwenden eine sehr alte Version des SQ Java Plugin (2.5.1). Ich kann Ihnen nur raten, es auf die neueste Version zu aktualisieren.

+0

Danke Fabrice. Ich habe vorher ein Beispielprojekt versucht. Wie auch immer, ich kann es jetzt lösen. Ich habe eine Lösung, indem ich Jacoco Plugins mit seinen Schritten in Child Pom-Datei legte. Eine weitere Sache ist, dass mein Modul ein großes Modul ist, also baute ich das Problem so auf, dass ich argLine als Eigenschaft anstelle von todsicherem Plugin verwendete –

0

Nun, ich bin mir nicht sicher, warum der obige Code nicht funktioniert, aber ich habe das gleiche Ding Bit anders versucht und Wunder passiert ist. Lass mich die Lösung geben, was es für mich gearbeitet hat.

Ich entfernte den untenstehenden Code von Eltern Pom und legte es in alle Kinder Pom. Auch da ich es im Kind-Modul verwendet habe, habe ich target/jacoco.exec anstelle von $ {project.basedir} /../ target/jacoco.exec und dasselbe für jacoco-it.exec verwendet.

<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> 

Zusätzliche Informationen. Das folgende Plugin, das ich in meiner Frage erwähnt habe, ist nicht erforderlich, wenn die Testabdeckung nur im Sonar-Report benötigt wird.Wenn es separat für die Code-Bericht Anforderung dann seinem erforderlichen

<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>