acanda/code-analysis-maven-plugin
GitHub: acanda/code-analysis-maven-plugin
Coan 是一个 Maven 代码分析插件,集成 Checkstyle 和 PMD 并生成单页 HTML 报告,同时支持 GitHub、GitLab 和 Bitbucket 等 CI/CD 平台的原生报告集成。
Stars: 3 | Forks: 0
= Coan - Code Analysis Maven Plugin
:plugin-version: 1.30.0
:idprefix:
:idseparator: -
Coan 是一个代码分析 Maven plugin,它可以运行 Checkstyle 和 PMD,并生成单页的 HTML 报告。
你可以为 Maven 项目中的每个模块生成单独的报告,也可以为所有模块生成汇总报告。
它还会将发现的问题记录到控制台,并提供可点击的链接,这些链接会在 IntelliJ IDEA 中打开相应的文件。
Coan 会检测它是否作为 GitHub workflow 的一部分运行,并自动将报告附加到作业的摘要中。
它还支持 GitLab Code Quality 报告,你可以将其作为 artifact 附加到你的 GitLab CI/CD 作业中,以便在合并请求和 pipeline 视图中汇总插件发现的问题。
当作为 Bitbucket pipeline 的一部分运行时,插件会自动生成代码洞察报告(code insight report)并将其附加到构建中。
== 用法
=== 分析单个 Maven 项目或模块
你可以使用 `analyse` 目标为单个 Maven 项目或模块创建报告。
如果你将以下配置放入多模块项目的父 pom 中,那么插件将为每个模块生成单独的报告。
## [source,xml,subs="attributes+"]
ch.acanda.maven
code-analysis-maven-plugin
{plugin-version}
analyse-code
verify
analyse
false
true
config/pmd.xml
config/checkstyle.xml
${project.build.directory}/code-analysis
html
----
<1> 默认阶段是 `verify`。
除非你想在另一个阶段运行该插件,否则可以省略此项。
<2> 所有配置参数都是可选的。
此示例中的值为默认值。
=== 多模块项目的汇总报告
你可以使用 `aggregate` 目标为多模块 Maven 项目创建汇总报告。
`aggregate` 目标默认不绑定到任何阶段,因为此目标不打算作为构建的一部分调用,而是通过 `mvn ch.acanda.maven:code-analysis-maven-plugin:aggregate` 单独调用。
如果你需要更改配置,可以通过直接在 CLI 中设置属性来完成,例如:
## [source,bash]
## mvn ch.acanda.maven:code-analysis-maven-plugin:aggregate -Dcoan.failOnIssues=false
或者通过添加一个不带目标的构建插件配置,如下所示。
## [source,xml,subs="attributes+"]
ch.acanda.maven
code-analysis-maven-plugin
{plugin-version}
false
true
config/pmd.xml
config/checkstyle.xml
${project.build.directory}/code-analysis
html
----
<1> 所有配置参数都是可选的。
此示例中的值为默认值。
=== 配置参数
所有参数都是可选的。
skip::
当设置为 `true` 时跳过执行。 +
默认值:`false` +
属性:`coan.skip`
failOnIssues::
如果任何代码分析器发现任何问题,则导致构建失败。
如果你在运行 Maven 时加上了 `--fail-at-end`,那么构建不会立即失败,而只会在构建结束时失败。 +
默认值:`true` +
属性:`coan.failOnIssues`
pmdConfigPath::
PMD 配置文件的路径。
这可以是绝对路径或相对路径。
如果路径是相对的,则插件会尝试根据它正在分析的项目或模块的基础路径来解析它。
如果无法解析路径,它会递归地尝试根据父项目来解析它。
这允许你既在父项目中拥有全局配置,又为特定模块提供特殊配置。 +
默认值:`config/pmd.xml` +
属性:`coan.pmd.configPath`
checkstyleConfigPath::
Checkstyle 配置文件的路径。
这可以是绝对路径或相对路径。
如果路径是相对的,则插件会尝试根据它正在分析的项目或模块的基础路径来解析它。
如果无法解析路径,它会递归地尝试根据父项目来解析它。
这允许你既在父项目中拥有全局配置,又为特定模块提供特殊配置。 +
默认值:`config/checkstyle.xml` +
属性:`coan.checkstyle.configPath`
targetPath::
插件的工作目录。
最终报告(例如 `report.html`)以及其他一些临时文件将保存在此目录中。 +
默认值:`${project.build.directory}/code-analysis` +
属性:`coan.targetPath`
reportFormats::
插件可以创建不同格式的报告。
此参数包含一个以逗号分隔的格式列表。
插件会检测它是否作为 GitHub workflow 的一部分运行,并自动将报告附加到作业的摘要中。
+
默认值:`html` +
属性:`coan.report.formats` +
+
支持的格式有 `html`、`gitlab` 和 `github`:
html:::
创建一个 HTML 报告 `report.html`,列出插件发现的所有问题。
gitlab:::
创建一个 GitLab Code Quality 报告 `report.gitlab.json`,你可以将其作为 artifact 附加到你的 GitLab CI/CD 作业中,以便在合并请求和 pipeline 视图中汇总插件发现的问题,参见 https://docs.gitlab.com/ee/ci/yaml/index.html#artifactsreportscodequality[artifacts:reports:codequality]。
github:::
插件会检测它是否作为 GitHub workflow 的一部分运行,并在不添加此格式的情况下自动将报告附加到作业的摘要中。
只有当你想将报告存储在 `report.github.md` 中时,你才必须添加 `github`。
== 构建状态
image:https://github.com/acanda/code-analysis-maven-plugin/actions/workflows/build.yaml/badge.svg["GitHub Actions Build Status",link="https://github.com/acanda/code-analysis-maven-plugin/actions/workflows/build.yaml"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=alert_status["Sonar Quality Gate Status",link="https://sonarcloud.io/dashboard?id=acanda_code-analysis-maven-plugin"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=security_rating["Sonar Security Rating",link="https://sonarcloud.io/component_measures?id=acanda_code-analysis-maven-plugin&metric=Security&view=list"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=reliability_rating["Sonar Reliability Rating",link="https://sonarcloud.io/component_measures?id=acanda_code-analysis-maven-plugin&metric=Reliability&view=list"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=sqale_rating["Sonar Maintainability Rating",link="https://sonarcloud.io/component_measures?id=acanda_code-analysis-maven-plugin&metric=Maintainability&view=list"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=vulnerabilities["Sonar Vulnerabilites",link="https://sonarcloud.io/project/issues?id=acanda_code-analysis-maven-plugin&resolved=false&types=VULNERABILITY"]
image:https://sonarcloud.io/api/project_badges/measure?project=acanda_code-analysis-maven-plugin&metric=bugs["Sonar Bugs",link="https://sonarcloud.io/project/issues?id=acanda_code-analysis-maven-plugin&resolved=false&types=BUG"]
== 许可证
Code Analysis Maven Plugin 基于 http://www.apache.org/licenses/LICENSE-2.0[Apache License, Version 2.0] 授权。
标签:Checkstyle, JS文件枚举, Maven插件, PMD, 代码分析, 凭证管理, 域名枚举, 多模态安全, 实时流处理, 静态代码扫描