配置Sonar以从Maven pom.xml中排除文件 [英] Configure Sonar to exclude files from Maven pom.xml

查看:4813
本文介绍了配置Sonar以从Maven pom.xml中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在maven中配置了一个项目,代码分析由SonarQube完成。

I have a project configured in maven and the code analysis is done by SonarQube.

我正在尝试在pom.xml文件中配置SonarQube以排除一些来自代码分析的文件。这些文件可以通过它们的类名来标识,它们在扩展名之前包含下划线字符(它们是元模型类)。下面我给出了我尝试排除它们的pom.xml文件的一部分:

I am trying to configure SonarQube in the pom.xml file to exclude a few files from the code analysis. Those files can be identified by their class names, they contain the underscore character before the extension (they are metamodel classes). Below I give the part of the pom.xml file where I try to exclude them:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <sonar.sources>src/main/java</sonar.sources>
        <sonar.exclusions>file:**/src/main/java/**/*_.*</sonar.exclusions>
    </configuration>
</plugin>

但是,上述代码不起作用。有没有办法从我的pom.xml文件配置SonarQube以在分析源代码时忽略这些文件?

However, the above code does not work. Is there a way to configure SonarQube from my pom.xml file to ignore those files when analysing the source code?

提前谢谢。

推荐答案

声纳排除(与其他声纳属性一样)添加到POM文件的< properties> 部分。像这样(例如从当前项目中排除jOOQ自动生成的代码):

Sonar exclusions (like other sonar properties) have to be added to the <properties> section of the POM file. Like so (example from excluding jOOQ autogenerated code from current project):

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <sonar.host.url>http://www.example.com/</sonar.host.url>
    <sonar.jdbc.url>jdbc:postgresql://www.example.com/sonar</sonar.jdbc.url>
    <sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver>
    <sonar.jdbc.username>sonar</sonar.jdbc.username>
    <sonar.jdbc.password>sonar</sonar.jdbc.password>
    <sonar.exclusions>org/binarytherapy/generated/**/*, **/GuiceBindComposer.java</sonar.exclusions>
    <sonar.dynamic>reuseReports</sonar.dynamic>
</properties>

这篇关于配置Sonar以从Maven pom.xml中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆