2016-11-28 2 views
1

Ich habe ein Problem mit Maven-Sonar-Einstellungen festgelegt. Ich brauche alle Dateien mein Projekt in src enthalten/main/java und src/main/resources so dass Sonarqube Ergebnisse aller meiner Dateien zeigen aber einige Dateien in src/main/resources/static/Datei ausschließen . Für Testpfad ist bereits standardmäßig bei src/test/javaSonar-Maven-Plugin: Kann nicht sonar.sources src/main/resources

gesetzt Dieses ist, wie ich meine pom.xml

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.1.RELEASE</version> 
    <relativePath /> <!-- lookup parent from repository --> 

    <!-- Sonar static analysis/Jacoco code coverage --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <start-class>com.Example.wp.WpCoreApplication</start-class> 
    <java.version>1.8</java.version> 
    <sonar.sources>src/main/java, src/main/resources</sonar.sources> 
    <sonar.exclusions>src/main/resources/static/file</sonar.exclusions> 
</properties> 

<dependencies> 
    <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId> 
     </dependency> --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-elasticsearch</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-neo4j</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>info.debatty</groupId> 
     <artifactId>java-string-similarity</artifactId> 
     <version>RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.poi</groupId> 
     <artifactId>poi-ooxml</artifactId> 
     <version>3.11</version> 
    </dependency> 
</dependencies> 
<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-report-plugin</artifactId> 
      <version>2.7.2</version> 
     </plugin> 
    </plugins> 
</reporting> 
<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19.1</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.maven.surefire</groupId> 
         <artifactId>surefire-junit47</artifactId> 
         <version>2.19.1</version> 
        </dependency> 
       </dependencies> 
       <configuration> 
        <argLine>${jacoco.agent.argLine}</argLine> 
        <skipTests>false</skipTests> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
      </plugin> 
      <plugin> 
       <groupId>org.sonarsource.scanner.maven</groupId> 
       <artifactId>sonar-maven-plugin</artifactId> 
       <version>3.1.1</version> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>0.7.7.201606060606</version> 
      <configuration> 
       <dataFile>target/jacoco.exec</dataFile> 
      </configuration> 
      <executions> 
       <execution> 
        <id>jacoco-initialize</id> 
        <phase>initialize</phase> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
        <configuration> 
         <propertyName>jacoco.agent.argLine</propertyName> 
         <destFile>target/jacoco.exec</destFile> 
        </configuration> 
       </execution> 
       <execution> 
        <id>jacoco-report</id> 
        <phase>verify</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-site-plugin</artifactId> 
     </plugin> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>rpm-maven-plugin</artifactId> 
      <version>2.1-alpha-3</version> 
      <executions> 
       <execution> 
        <id>attach-rpm</id> 
        <goals> 
         <goal>attached-rpm</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

Aber wenn ich betreibe meine Maven-Sonar mit Eingabeaufforderung: mvn Sonar: Sonar. Es gibt ein Fehlerprotokoll wie dieses

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.865 s 
[INFO] Finished at: 2016-11-28T14:46:40+07:00 
[INFO] Final Memory: 68M/449M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin: 
3.1.1:sonar (default-cli) on project wp: The directory 'D:\PROJECT\wp-core\ 
src\main\resources' does not exist for Maven module com.sample:wp:jar:0.1.26. Pleas 
e check the property sonar.sources -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit 
ch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please rea 
d the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE 
xception 

Wie kann ich Sonar so einrichten, dass es alle meine Dateien scannen kann? Ich sehe schon documentation und Stackoverflow

Antwort

3

sollten Sie wahrscheinlich den zusätzlichen Platz entfernen. Ändern

<sonar.sources>src/main/java, src/main/resources</sonar.sources> 

zu

<sonar.sources>src/main/java,src/main/resources</sonar.sources> 
+1

Wenn das die Lösung ist, solltest du wahrscheinlich das 'Sonar-Maven-Plugin' verbessern ;-) – FrVaBe

+0

Ahh .. das ist ziemlich schwierig, wenn ich es überprüfe, finde ich den Pfad" Space ".. Ich denke, dass sie Sonar-Maven-Plugin wie @FrVaBe verbessern müssen, sagte. –

+0

@David Vincent - Trotzdem, wenn das Entfernen des Platzes Ihr Problem löste, sollten Sie die Antwort akzeptieren (und wahrscheinlich upvote). – FrVaBe

1

Nur unten angegebene Einträge im Zusammenhang mit Sonar werden von SonarQube für statische Code-Analyse benötigt.

Unter der Eigenschaften Tag in Ihrem pom.xml, fügen Sie nur folgende Einträge Sonar bezogen werden: Sie können Eigenschaft. Standardmäßig scariert sonar alle Dateien, die sich im src-Ordner befinden.

<sonar.language>java</sonar.language> 
    <sonar.exclusions> 
     **/static/file/** 
    </sonar.exclusions> 

Unter dem Plugin-Tag in Ihrem pom.xml, ersetzen Sie die Maven-todsichere-Plugin und jacoco-Maven-Plugin Einträge mit folgenden Einträgen:

<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.13</version> 
     </plugin> 
     <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>0.7.2.201409121644</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>report</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

Lets all diese Parameter nicht hinzufügen, die sind wird von Sonar für statische Code-Analyse nicht benötigt. Sie werden sehen, dass ich nur hinzugefügt habe und Eigenschaft in Eigenschaften Tag. Die richtige zu verwendende Syntax ist nicht src/main/diese Art von Pfad zu verwenden. Wenn Sie src/main in sonar.exclusions angeben, schließt das Sonar keine Dateien von der statischen Codeanalyse aus. Ich habe dieses Problem in meinem Projekt konfrontiert.

Lassen Sie mich wissen, wenn es Sie noch einige Fragen stellen.

+0

Nach gelesen Ihren Beitrag, fand ich meinen Fehler. Ich muss nur src/main und seine Funktionen schreiben. Ich weiß nicht, warum ich nicht jeden Pfad wie meine Einstellungen angeben kann. –

+0

Btw, nicht mit Im Ihre Maven-todsichere-Plugin und jacoco-Maven-Plugin-Einstellungen, aber es funktioniert immer noch. Ich habe nur die Zusammenfassung gelesen, die du geschrieben hast, und ich verstehe plötzlich meinen Fehler. Danke @Reena –

+0

vielleicht können Sie Ihre Antwort bearbeiten, und fügen Sie src/main Da nach der Erklärung lesen, muss ich einfach so meine Einstellung ändern und es funktioniert wie Magie . Ahaha. Danke :) –