sonar-maven-plugin:无法设置sonar.sources src / main / resources

时间:2016-11-28 08:02:36

标签: java maven sonarqube pom.xml sonar-maven-plugin

我的maven-sonar设置有问题。我需要将所有项目文件包含在 src / main / java src / main / resources 中,以便SonarQube显示我所有文件的结果,但不包括< EM>的src /主/资源/静态/文件的。对于测试路径,默认情况下已在 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

如何设置声纳以便它可以扫描我的所有文件?我已经查看了documentationStackoverflow

2 个答案:

答案 0 :(得分:3)

你应该删除额外的空间。变化

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

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

答案 1 :(得分:1)

sonarQube只需要在声纳相关的指定条目下进行静态代码分析。

在pom.xml中的属性标记下,仅添加以下与声纳相关的条目:您可以使用属性。默认情况下,声纳会缩放放在src文件夹下的所有文件。

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

在pom.xml中的plugins标签下,将以下条目替换为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,则声纳不会从静态代码分析中排除文件。             我在项目中遇到了这个问题。

如果您仍然遇到一些问题,请告诉我。

相关问题