9

我正在使用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

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

4

2 回答 2

11

This works for me:

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

For the meaning of the variable ${session.executionRootDirectory}, see Finding the root directory of a multi module maven reactor project.

于 2015-11-16T02:55:52.163 回答
3

根据插件的文档,这是可能的:

如果您想将您的规则集 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>
    ...

运行 amvn 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>
    ...
于 2019-05-06T10:31:13.883 回答