2016-03-22 25 views
1

Ich habe ein Projekt, für das die Code Coverage-Nummern ziemlich niedrig sind. Nach einem Deep-Dive fand ich heraus, dass die jacoco-Code-Coverage-Statistiken von Target-Directoy anstatt von Source abhängen.Generierte Quellen von der Codeabdeckung ausschließen, ohne die gesamte Codeabdeckung zu beeinträchtigen

target/generated-sources/delombok/com/ 

Wenn ich das Zielverzeichnis ausschließe, sinkt die Abdeckung um 0%. Daher sollte die Codeabdeckung nicht gegen den Zielordner, sondern gegen den Code (src) gemessen werden. Unten ist der Screenshot von SonarQube.

enter image description here

So ist die Frage, wie kann ich sicherstellen, dass die Code-Coverage für src gemessen wird, statt Ziel?

Im Anschluss an die pom ohne Abhängigkeiten:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>removed</groupId> 
    <artifactId>xxxx</artifactId> 
    <version>0.0.11-SNAPSHOT</version> 
    <packaging>war</packaging> 



    <build> 

     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>cassandra-maven-plugin</artifactId> 
       <version>2.1.7-1</version> 
       <configuration> 
        <script>${basedir}/src/main/cassandra/local_run.cql</script> 
        <cqlVersion>3.2.0</cqlVersion> 
        <startNativeTransport>true</startNativeTransport> 
        <nativeTransportPort>9142</nativeTransportPort> 
        <jmxPort>17199</jmxPort> 
        <storagePort>17000</storagePort> 
        <loadFailureIgnore>false</loadFailureIgnore> 
        <cuLoadFailureIgnore>false</cuLoadFailureIgnore> 
       </configuration> 
       <executions> 
        <execution> 
         <id>start</id> 
         <goals> 
          <goal>start</goal> 
          <goal>load</goal> 
         </goals> 
         <phase>process-classes</phase> <!--Bind cassandra start and load to process-classes which is the phase that is called up before tomcat is run --> 
        </execution> 
        <execution> 
         <id>stop</id> 
         <goals> 
          <goal>stop</goal> 
         </goals> 
         <!--Bind cassandra stop to generate-test-sources which is the phase that is called up before 
         tests are run. This is because our tests start their own cassandra --> 
         <phase>integration-test</phase> 
        </execution> 
       </executions> 
       <dependencies> 
        <dependency> 
         <groupId>org.slf4j</groupId> 
         <artifactId>slf4j-log4j12</artifactId> 
         <version>1.7.7</version> 
        </dependency> 
       </dependencies> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-release-plugin</artifactId> 
      </plugin> 

      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
      </plugin> 

      <plugin> 
       <groupId>org.projectlombok</groupId> 
       <artifactId>lombok-maven-plugin</artifactId> 
      </plugin> 
      <!--Needed to add this so that src/main/java is recognized as a source folder --> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-source-plugin</artifactId> 
      </plugin> 

      <!-- Unit Test --> 


      <!-- Integration Test --> 


      <plugin> 
       <artifactId>maven-enforcer-plugin</artifactId> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <warName>activationloginedge</warName> 
       </configuration> 
      </plugin> 

      <!-- Tomcat Integration Test --> 
      <plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat7-maven-plugin</artifactId> 
       <configuration> 
        <path>/activationloginedge</path> 
       </configuration> 
       <executions> 
        <execution> 
         <id>tomcat-run</id> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <phase>pre-integration-test</phase> 
         <configuration> 
          <systemProperties> 
           <!-- We want test configuration for running integration tests. --> 
           <archaius.deployment.environment>test</archaius.deployment.environment> 
           <logback-lib.env>filesystem</logback-lib.env> 
          </systemProperties> 
          <fork>true</fork> 
         </configuration> 
        </execution> 
        <execution> 
         <id>tomcat-shutdown</id> 
         <goals> 
          <goal>shutdown</goal> 
         </goals> 
         <phase>post-integration-test</phase> 
        </execution> 
       </executions> 
      </plugin> 
     <plugin> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>0.7.4.201502262128</version> 
     <executions> 
     <execution> 
      <id>pre-unit-test</id> 
      <goals> 
      <goal>prepare-agent</goal> 
      </goals> 
      <configuration> 
      <!-- Sets the path to the file which contains the execution data. --> 
      <destFile>${project.build.directory}/jacoco-ut.exec</destFile> 
      <!-- Sets the name of the property containing the settings for JaCoCo runtime agent.--> 
      <propertyName>surefireArgLine</propertyName> 
      </configuration> 
     </execution> 
     <!--Ensures that the code coverage report for unit tests is created after unit tests have been run.--> 
     <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}/jacoco-ut.exec</dataFile> 
      <!-- Sets the output directory for the code coverage report. --> 
      <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
      </configuration> 
</execution>  <execution> 
<id>pre-integration-test</id> 
<phase>pre-integration-test</phase> 
<goals> 
    <goal>prepare-agent</goal> 
</goals> 
<configuration> 
<!-- Sets the path to the file which contains the execution data. --> 
    <destFile>${project.build.directory}/jacoco-it.exec</destFile> 
    <!-- Sets the name of the property containing the settings for JaCoCo runtime agent.--> 
    <propertyName>failsafeArgLine</propertyName> 
< 

    /configuration> 
    </execution> 
    <!-- Ensures that the code coverage report for integration tests after integration tests have been run.--> 
    <execution> 
     <id>post-integration-test</id> 
     <phase>post-integration-test</phase> 
     <goals> 
       <goal>report</goal> 
     </goals> 
    <configuration> 
    <!-- Sets the path to the file which contains the execution data. --> 
    <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile> 
    <!-- Sets the output directory for the code coverage report. --> 
      <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> 
     </configuration> 
    </execution> 
    </executions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.12.4</version> 
     <configuration> 
     <!-- Sets the VM argument line used when unit tests are run. --> 
     <argLine>${surefireArgLine}</argLine> 
     <!-- Skips unit tests if the value of skip.unit.tests property is true --> 
     <skipTests>${skip.unit.tests}</skipTests> 
     <!-- Excludes integration tests when unit tests are run. --> 
     <excludes> 
      <exclude>**/IT*.java</exclude> 
     </excludes> 
     </configuration> 
     </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-failsafe-plugin</artifactId> 
      <version>2.15</version>  <executions> 
      <execution> 
       <goals> 
       <goal>integration-test</goal> 
       <goal>verify</goal> 
       </goals> 
      <configuration> 
     <!-- Sets the VM argument line used when integration tests are run--> 
      <argLine>${failsafeArgLine}</argLine> 
     <!-- Skips integration tests if the value of skip.integration.tests property is true--> 
      <skipTests>${skip.integration.tests}</skipTests>  </configuration> 
       </execution> 
       </executions> 
     </plugin> 
    </plugins> 
     </build> 
    </project> 
+1

Können Sie bitte weitere Details zu Ihrer Konfiguration angeben? Tatsächlich wird die Quelltextabdeckung gegen den Quellcode berechnet. Sie sehen also so aus, als hätten Sie "Ziel" als einen der Quellordner konfiguriert. –

+0

Angehängt die Pom durch Entfernen der Abhängigkeit Abschnitt – Jeel

+0

Uhhh, sieht aus wie Sie vergessen, die Datei anfügen (oder einen Link zu geben) @Jeel –

Antwort

1

OK, das Lombok Maven Plugin ändert die Liste der Quellordner während des Maven bauen, deshalb der target/generated-sources/delombok Ordner Sonarqube als Quellordner erkannt wird.

Um Sonarqube zu zwingen, nur Ihre eigenen Quelldateien zu betrachten, sollten Sie die folgende Eigenschaft zu Ihrem POM hinzufügen:

<properties> 
    <sonar.sources>src/main/java</sonar.sources> 
</properties> 

dies Ihr Problem lösen wird.