Java 如何从声纳分析中排除一些 Maven 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22981028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 19:45:01  来源:igfitidea点击:

How to exclude some maven project from sonar analysis

javaeclipsemaveneclipse-pluginsonarqube

提问by Sumit Singh

I have many(Let say 10 (A, B, C...)) eclipse plugin which is maven based.

我有很多(比如说 10 个(A、B、C...))基于 Maven 的 Eclipse 插件。

I have one master pom file which includes all other plugin projects. now by building master file with sonar:sonargoal it will build all the plugins.

我有一个包含所有其他插件项目的主 pom 文件。现在通过使用sonar:sonar目标构建主文件,它将构建所有插件。

So my question:Is there is any way so that I can exclude some plugin let say A and C.?

所以我的问题有什么办法可以排除一些插件,比如说 A 和 C。?

采纳答案by Raghuram

NOTE:This property is deprecated since version 4.3 and should not be used anymore.

注意:此属性自 4.3 版起已弃用,不应再使用。

From the documentation, there is an option to skip module using sonar.skippedModules

文档中,有一个选项可以使用跳过模块sonar.skippedModules

You could also do this from the sonar admin page as documented in the Skipping Modules section here.

您也可以从此处的跳过模块部分中记录的声纳管理页面执行此操作。

回答by Cryn

There are several ways, one of which is adding the sonar.skipproperty inside the pom.xmlof the project / module you want to skip.

有几种方法,其中一种方法是在要跳过的项目/模块的sonar.skip内部添加属性pom.xml

This excludes a project from SonarQube analysis:

这从 SonarQube 分析中排除了一个项目:

<properties>
    <sonar.skip>true</sonar.skip>
</properties>

This also works with Jenkins and running Sonar as a post build action.

这也适用于 Jenkins 并将声纳作为后期构建操作运行。

For more details see: Analyzing with SonarQube Scanner for Maven

有关更多详细信息,请参阅:使用 SonarQube Scanner for Maven 进行分析

回答by Jesse Glick

I had no luck with the officially documented sonar.skip: when I set it in a submodule POM, I saw

我对官方文档没有运气sonar.skip:当我在子模块 POM 中设置它时,我看到

[INFO] Delaying SonarQube Scanner to the end of multi-module project

after modules which should have been included and then

在应该包含的模块之后,然后

[INFO] sonar.skip = true: Skipping analysis

at the end of the reactor build, and there was no analysis/upload.

在反应堆构建结束时,没有分析/上传。

Instead I defined sonar.exclusionsin the root POM to a patternmatching the source files (by package path) which would be used in the submodule to be skipped. This seems to have worked.

相反,我sonar.exclusions在根 POM 中定义了与源文件(按包路径)匹配的模式,该模式将在要跳过的子模块中使用。这似乎奏效了。



As an aside, setting sonar.projectKeyin the root POM did not work; Sonar complained that

顺便说一句,sonar.projectKey在根 POM 中设置不起作用;声纳抱怨说

Project '…' can't have 2 modules with the following key: …

which I fixed by moving this to .mvn/maven.config:

我通过将其移动到.mvn/maven.config

-Dsonar.projectKey=…