简体   繁体   English

Maven Checkstyle 和有效的 POM

[英]Maven Checkstyle and Effective POM

I created a new maven project and wanted to run an initial checkstyle check against it using a custom checkstyle ruleset.我创建了一个新的 maven 项目,并希望使用自定义 checkstyle 规则集对其运行初始checkstyle检查。 I went ahead and ran mvn checkstyle:check , not expecting it to work without first adding checkstyle to my pom, but to my surprise it did.我继续运行mvn checkstyle:check ,没想到它会在没有首先向我的 pom 添加 checkstyle 的情况下工作,但令我惊讶的是它确实如此。 That is, maven downloaded the checkstyle jar to my local .m2 and ran checkstyle:check on my project.也就是说,maven 将 checkstyle jar 下载到我的本地 .m2 并在我的项目上运行checkstyle:check

I find this surprising is because I have not added checkstyle to my pom;我觉得这令人惊讶是因为我没有在我的 pom 中添加 checkstyle; nor do I see any reference to checkstyle in the effective pom ( mvn help:effective-pom );我也没有在有效 pom 中看到任何对 checkstyle 的引用( mvn help:effective-pom ); nor does does checkstyle show as a dependency ( mvn dependency:tree ). checkstyle 也不显示为依赖项( mvn dependency:tree )。

So how is maven aware of checkstyle at all?那么 maven 是如何知道 checkstyle 的呢? What is the elusive source within maven of the checkstyle tool and what additional features are available from that source? checkstyle 工具的 maven 中难以捉摸的来源是什么,以及该来源有哪些附加功能?

I'm hoping the answer will also provide insight into how to tell mvn checkstyle:check to use a custom ruleset, not just the predefined google_checks.xml or sun_checks.xml .我希望答案也能提供有关如何告诉mvn checkstyle:check使用自定义规则集的见解,而不仅仅是预定义的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我如何告诉 mvn checkstyle:check 使用不同的规则集,比如 google_checks.xml,而不是它似乎默认使用的 sun_checks.xml

Use the configLocation parameter, which specifies the location of the XML configuration to use: https://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html使用configLocation参数,它指定要使用的 XML 配置的位置: https : configLocation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM