【问题标题】:Maven Looking for a config file in server address, but I need it to run offlineMaven 在服务器地址中寻找配置文件,但我需要它离线运行
【发布时间】:2022-01-03 21:51:20
【问题描述】:

我在从服务器下载的许多项目中使用了一些 checkstyle XML 配置。 但我需要它们位于存储库位置。

可以类比为本地仓库为第三方库提供本地缓存的场景。

【问题讨论】:

    标签: maven maven-3 maven-plugin


    【解决方案1】:

    来自Checkstyle-Mojo-Documentation#configLocation

    可能的值是文件系统路径、URL 或类路径资源。该参数期望location的内容符合规则集的xml格式(Checkstyle Checker模块)配置。

    此参数被解析为 (1.) 资源,(2.) URL,然后 (3.) 文件。

    sun_checks.xmlgoogle_checks.xmlpackaged 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

    这涉及:

    1. 创建一个新的(独立的)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/其他工具配置;)

    2. mvn install build-tools(在本地使用),在“公司存储库”中使用:mvn deploy it。

    3. 使用它(在 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)。

    【讨论】:

    • 感谢您的解决方案,但多模块配置将需要在整个项目中更改使用 checkstyle 项目的地方,我有一种方法可以在根级别完成。
    • 当您在“根 pom”中放置 pluginManagement 时,此(配置)将应用到所有子级,它可以/可能明智地覆盖项目(层次结构级别)..
    • 当您放入plugins(不是pluginManagement)时,它将应用于“作为执行”(不仅仅是“配置”)的所有子项
    猜你喜欢
    • 2021-06-02
    • 2020-10-14
    • 1970-01-01
    • 2018-11-13
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    相关资源
    最近更新 更多