gpt4 book ai didi

maven - 在 Jenkins 的多模块项目中从 Sonar Qube 扫描中排除目录,无需修改项目

转载 作者:行者123 更新时间:2023-12-02 04:03:40 28 4
gpt4 key购买 nike

我创建了一个执行 SONAR QUBE 分析的 Jenkins 作业。我已将 SONAR 扫描添加为通用构建步骤。我没有对项目进行任何修改来启用 SONAR 集成,因为该项目不必关心 SONAR。 (即没有更改 POM.xml,也没有添加属性文件)

我的 SONAR 集成正在运行,无需对该项目进行任何修改,这非常棒。

但是,这是一个多模块项目,现在我想从扫描中排除其中一个模块,因为该模块包含自动生成的代码。以下是我用来在 Jenkins 中触发 SONAR 扫描的 Maven 命令:

sonar:sonar
-Dsonar:host.url=http://url.com:9000/sonar
-Dsonar.login=myusername
-Dsonar.password=mypassword

这是我的项目结构:

    root
Project A
Project B
Project C

我想从扫描中排除 ProjectB。

我尝试过-Dsonar.exclusions=/ProjectB,但没有成功。

以下是日志的摘录:

[INFO] ------------- Scan Project B
[INFO] Base dir: /workspace/jenkins/…/workspace/CI-JOB-NAME/projectB
[INFO] Working dir: /workspace/jenkins/…/workspace/CI-JOB-NAME/projectB/target/sonar
[INFO] Source paths: pom.xml, src/main/java
[INFO] Binary dirs: target/classes
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Index files
[INFO] Excluded sources:
[INFO] /projectB
[INFO] 44 files indexed
[INFO] 0 files ignored because of inclusion/exclusion patterns

如日志所示,排除的源属性已设置但不起作用,因为它显示忽略了 0 个文件...

问题:如何从扫描中排除项目 B 目录内的所有内容?(最好在 Jenkins 作业中使用命令,而不是向项目本身添加任何属性文件或其他修改)

“排除源路径”是相对于“基本目录”路径还是根路径?我应该将排除路径定义为绝对路径吗?

最佳答案

documentation为此有专门的部分。适合您情况的选项:

  • 使用构建配置文件排除某些模块(例如集成测试)
  • 使用Advanced Reactor Options (例如-pl)。例如mvn sonar:sonar -pl !module2

例如,使用最后一个,您可以这样做:

sonar:sonar -pl "!projectB"
-Dsonar:host.url=http://url.com:9000/sonar
-Dsonar.login=myusername
-Dsonar.password=mypassword
<小时/>

Is the “Excluded sources path” relative to the “Base dir” path or the Root?? Should I define the exclusion path as an absolute path?

根据documentation on exclusions ,模式是相对于基目录的,因此不是绝对路径。无论如何,我认为这个选项对你的情况没有用,因为在多模块maven项目中,子模块的文件使用相对于模块基目录的路径进行索引。因此,像 projectB/** 这样的模式将不会匹配任何内容,因为 projectB 不是所使用路径的一部分。如果模块中有一些唯一的包名称,例如位于 src/main/java/someuniquepackagesomeuniquepackage,则模式 src/main/java/someuniquepackage/** 可以。

无论如何,我推荐上面的-pl选项,或者使用Maven的配置文件功能。

关于maven - 在 Jenkins 的多模块项目中从 Sonar Qube 扫描中排除目录,无需修改项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41721436/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com