sonar-maven-plugin: 无法设置 sonar.sources src/main/resources
sonar-maven-plugin: Can not set sonar.sources src/main/resources
我对 maven-sonar 设置有疑问。我需要将所有项目文件包含在 src/main/java 和 src/main/resources 以便 SonarQube 显示我所有文件的结果但排除 src/main/resources/static/file 中的一些文件。对于测试路径,它已默认设置为 src/test/java
这就是我设置 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>
但是当我 运行 我的 maven-sonar 带有命令提示符时: mvn sonar:sonar 。有这样的错误日志
[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
我如何设置声纳以便它可以扫描我的所有文件?我已经看过 documentation and this Whosebug
sonarQube 只需要下面指定的与声纳相关的条目来进行静态代码分析。
在您 pom.xml 的属性标签下,仅添加以下与声纳相关的条目:您可以 属性。默认情况下,sonar 将缩放 src 文件夹下的所有文件。
<sonar.language>java</sonar.language>
<sonar.exclusions>
**/static/file/**
</sonar.exclusions>
在您的 pom.xml 的插件标签下,将您的 maven-surefire-plugin 和 jacoco-maven-plugin 条目替换为以下条目:
<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>
我们不要添加声纳静态代码分析实际上不需要的所有参数。
你会看到,我只在属性标签中添加了 属性 。
正确使用的语法是不要使用 src/main/ 这种类型的路径。如果您在 sonar.exclusions 中指定 src/main,则声纳将不会从静态代码分析中排除文件。
我在我的项目中遇到了这个问题。
如果您仍然遇到一些问题,请告诉我。
您或许应该删除多余的 space。变化
<sonar.sources>src/main/java, src/main/resources</sonar.sources>
至
<sonar.sources>src/main/java,src/main/resources</sonar.sources>
我对 maven-sonar 设置有疑问。我需要将所有项目文件包含在 src/main/java 和 src/main/resources 以便 SonarQube 显示我所有文件的结果但排除 src/main/resources/static/file 中的一些文件。对于测试路径,它已默认设置为 src/test/java
这就是我设置 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>
但是当我 运行 我的 maven-sonar 带有命令提示符时: mvn sonar:sonar 。有这样的错误日志
[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
我如何设置声纳以便它可以扫描我的所有文件?我已经看过 documentation and this Whosebug
sonarQube 只需要下面指定的与声纳相关的条目来进行静态代码分析。
在您 pom.xml 的属性标签下,仅添加以下与声纳相关的条目:您可以 属性。默认情况下,sonar 将缩放 src 文件夹下的所有文件。
<sonar.language>java</sonar.language>
<sonar.exclusions>
**/static/file/**
</sonar.exclusions>
在您的 pom.xml 的插件标签下,将您的 maven-surefire-plugin 和 jacoco-maven-plugin 条目替换为以下条目:
<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>
我们不要添加声纳静态代码分析实际上不需要的所有参数。 你会看到,我只在属性标签中添加了 属性 。 正确使用的语法是不要使用 src/main/ 这种类型的路径。如果您在 sonar.exclusions 中指定 src/main,则声纳将不会从静态代码分析中排除文件。 我在我的项目中遇到了这个问题。
如果您仍然遇到一些问题,请告诉我。
您或许应该删除多余的 space。变化
<sonar.sources>src/main/java, src/main/resources</sonar.sources>
至
<sonar.sources>src/main/java,src/main/resources</sonar.sources>