【发布时间】:2022-01-03 21:51:20
【问题描述】:
我在从服务器下载的许多项目中使用了一些 checkstyle XML 配置。 但我需要它们位于存储库位置。
可以类比为本地仓库为第三方库提供本地缓存的场景。
【问题讨论】:
标签: maven maven-3 maven-plugin
我在从服务器下载的许多项目中使用了一些 checkstyle XML 配置。 但我需要它们位于存储库位置。
可以类比为本地仓库为第三方库提供本地缓存的场景。
【问题讨论】:
标签: maven maven-3 maven-plugin
来自Checkstyle-Mojo-Documentation#configLocation:
可能的值是文件系统路径、URL 或类路径资源。该参数期望location的内容符合规则集的xml格式(Checkstyle Checker模块)配置。
此参数被解析为 (1.) 资源,(2.) URL,然后 (3.) 文件。
sun_checks.xml 和 google_checks.xml 是 packaged with checkstyle(在类路径根目录下/在默认包中)。
所以听起来您的配置文件当前配置如下:
<configLocation>https://some.server.it/some-config.xml</configLocation>
<!-- e.g.: https://github.com/checkstyle/checkstyle/raw/master/src/main/resources/google_checks.xml ^^ -->
如果我们:
...需要它们位于存储库位置
,我们可以坚持How To:multi-module-confg。
这涉及:
创建一个新的(独立的)jar artifact/pom/project:
<groupId>com.foo.my</groupId>
<artifactId>build-tools</artifactId>
...
在src/main/resources/[com/foo/my/]my-checkstyle-config.xml 中拥有 checkstyle 配置(我们也可以在此处放置抑制、pmd/editor/其他工具配置;)
mvn install build-tools(在本地使用),在“公司存储库”中使用:mvn deploy it。
使用它(在 checkstyle-projects 中),例如:
...
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency> <!-- as plugin dependency! -->
<groupId>com.foo.my</groupId>
<artifactId>build-tools</artifactId>
<version>...</version>
</dependency>
</dependencies>
<configuration> <!-- pointing to the (classpath) resource (pulled by the above dependency): -->
<configLocation>[com/foo/my/]my-checkstyle-config.xml</configLocation>
...
这将分别从本地 maven 存储库的类路径中获取配置。
[com/foo/my] 是my-checkstyle-config.xml 的可选 包,所以当我们将它(在构建工具中)放在:src/main/resources/foo/bar/my-checkstyle-config.xml 下时,configLocation 应该是/foo/bar/my-checkstyle-config.xml。
如果它在顶级/默认包中,则只需 my-checkstyle-config.xml 或(等效)/my-checkstyle-config.xml(类似于操作指南中的 whizbang/checkstyle.xml)。
【讨论】:
pluginManagement 时,此(配置)将应用到所有子级,但它可以/可能明智地覆盖项目(层次结构级别)..
plugins(不是pluginManagement)时,它将应用于“作为执行”(不仅仅是“配置”)的所有子项