【问题标题】:Maven versions plugin: reference a rule.xml from a maven dependency?Maven 版本插件:从 Maven 依赖项中引用 rule.xml?
【发布时间】:2014-11-25 01:46:38
【问题描述】:

我正在使用mvn versions:display-dependency-updates versions:display-plugin-updates 目标来检查依赖项或插件更新。

我的 maven 项目是一个多模块项目,如下所示:

moduleA
 |- moduleB1
 |    |- moduleC  
 |- moduleB2
 |- build-config/rules.xml

由于有一些不需要的更新,比如我不想要的测试版,我制作了一个过滤器(有效)。我是这样用的:

<profile>
  <id>maven-version-plugin-1</id>
  <activation>
    <property>
      <name>version.rules.uri</name>
    </property>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <configuration>
          <rulesUri>${version.rules.uri}</rulesUri>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

我不得不使用配置文件和属性version.rules.uri,因为它必须引用现有文件(默认情况下它指向./build-config/rules.xml,但它也在我的settings.xml 中,带有绝对路径)。

我想通过以下方式避免这种情况:

  • 发布独立的build-config 项目
  • 使用一些 uri 引用这个项目:m2:myGroupId:myArtifactId:version:scope:jar/rules.xml

现在的问题是:是否有 Maven Wagon 插件(由 maven 版本插件使用)的实现,允许读取存储库条目,例如 jar ?

【问题讨论】:

    标签: java maven versions-maven-plugin maven-wagon-plugin


    【解决方案1】:

    这对我有用:

    <rulesUri>file:///${session.executionRootDirectory}/maven-version-rules.xml</rulesUri>
    

    变量${session.executionRootDirectory}的含义见 Finding the root directory of a multi module maven reactor project.

    【讨论】:

      【解决方案2】:

      基于the documentation for the plugin 这是可能的:

      如果您想将您的规则集 xml 作为 Maven 工件分发,您也可以在 jar 中提供您的规则集 xml 文件。因此,您必须将包含的 jar 声明为 versions-maven-plugin 的直接依赖项,并将类路径用作协议。

      我刚试了一下,就让它工作了。

      为新的版本规则工件创建一个新文件夹,如下所示:

      version-rules
        |- files
             \- version-rules.xml
        \- pom.xml
      

      pom.xml 非常基本:

          ...
          <artifactId>my-version-rules</artifactId>
          <packaging>jar</packaging>
      
          <build>
              <defaultGoal>package</defaultGoal>
              <resources>
                  <resource>
                      <directory>files</directory>
                      <filtering>false</filtering>
                      <includes>
                          <include>**/*</include>
                      </includes>
                  </resource>
              </resources>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-jar-plugin</artifactId>
                  </plugin>
              </plugins>
          </build>
          ...
      
      

      运行mvn install 以安装此工件。

      然后,在另一个 pom 中,您配置版本插件如下:

          ...
          <build>
              ...
              <pluginManagement>
                  ...
                  <plugins>
                      ...
                      <plugin>
                          <groupId>org.codehaus.mojo</groupId>
                          <artifactId>versions-maven-plugin</artifactId>
                          <version>2.7</version>
                          <configuration>
                              <rulesUri>classpath:///version-rules.xml</rulesUri>
                          </configuration>
                          <dependencies>
                              <dependency>
                                  <groupId>com.mycompany</groupId>
                                  <artifactId>my-version-rules</artifactId>
                                  <version>1.0-SNAPSHOT</version>
                              </dependency>
                          </dependencies>
                      </plugin>
                      ...
                  </plugins>
                  ...
              </pluginManagement>
              ...
          </build>
          ...
      

      【讨论】:

      • 我会重试,但在写我的问题时,我的问题是能够在同一个反应器中的依赖项中使用版本 XML 文件而不是使用的那个 - 事实上,它是更多使用父级所在的绝对路径中的version.xml(否则,您需要一个依赖项)。不过,以前的答案可能会更好。
      • 从(本地)maven 存储库读取 jar 文件的最简单方法,正如您似乎想要做的那样,只需将其声明为依赖项。这样,maven 将为您处理“这个罐子在哪里以及我如何获得它”。 ;-)
      • 这行得通,但反应堆有问题(在构建过程中你不能引用你自己的依赖,没有先编译)。
      • 我把这个例子的my-version-rules放到了我们的Nexus存储库中。带有versions-maven-plugin 的项目找不到它。为了解决这个问题,我不得不将~/.m2/settings.xml 中指定的repository 复制为pluginRepository
      猜你喜欢
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2020-07-26
      • 2019-01-24
      • 2016-09-18
      • 2015-10-13
      • 1970-01-01
      相关资源
      最近更新 更多