Maven Checkstyle 和 Effective POM

Maven Checkstyle and Effective POM

我创建了一个新的 Maven 项目,并想 运行 使用自定义 checkstyle 规则集对其进行初始 checkstyle 检查。我继续 运行 mvn checkstyle:check,不希望它在不首先向我的 pom 添加 checkstyle 的情况下工作,但令我惊讶的是它确实如此。也就是说,maven 将 checkstyle jar 下载到我的本地 .m2 和 运行 checkstyle:check 在我的项目中

我觉得这很奇怪,因为我没有在我的 pom 中添加 checkstyle;我也没有在有效的 pom (mvn help:effective-pom) 中看到任何对 checkstyle 的引用。 checkstyle 也不显示为依赖项 (mvn dependency:tree)。

那么 maven 是怎么知道 checkstyle 的呢? checkstyle 工具的 maven 中难以捉摸的来源是什么?该来源还有哪些附加功能可用?

我希望这个答案还能让您深入了解如何告诉 mvn checkstyle:check 使用自定义规则集,而不仅仅是 predefined google_checks.xmlsun_checks.xml.

How do I tell mvn checkstyle:check to use a different ruleset, say google_checks.xml, rather than sun_checks.xml, which it seems to use by default

使用configLocation参数,指定要使用的XML配置的位置:https://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html