或者子项目是否会在子项目目录中查找rules.xml 文件?
是的,如果您定义rules.xml
文件通过${project.basedir}
它将解析为子项目的当前本地基目录。我已经通过简单的父子 pom 设置验证了这一点。因此,除非您在每个项目中复制规则文件,否则这是行不通的。
如果您想包含插件配置and如果您想在父 pom 中设置规则集而不复制规则文件,您有两种选择:
例如,如果您的规则集 xml 文件托管在:http://www.mycompany.com/maven-version-rules.xml http://www.mycompany.com/maven-version-rules.xml那么您公司 pom 中的以下配置将确保所有项目都使用此规则集。
<configuration>
<rulesUri>http://www.mycompany.com/maven-version-rules.xml</rulesUri>
</configuration>
or
如果您想将规则集 xml 作为 Maven 工件分发,您也可以在 jar 中提供规则集 xml 文件。因此,您必须将包含的 jar 声明为 versions-maven-plugin 的直接依赖项,并使用类路径作为协议。
<configuration>
<rulesUri>classpath:///package/foo/bar/rules.xml</rulesUri>
</configuration>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>version-rules</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Source:
- https://www.mojohaus.org/versions-maven-plugin/version-rules.html https://www.mojohaus.org/versions-maven-plugin/version-rules.html
pom中的配置只有简陋includes
and excludes
过滤器。这些将允许您从整体上排除任何依赖项,但不能排除特定的更新版本。据我从可用的文档中可以看出,没有办法以任何其他方式定义版本规则。
See
- https://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html https://www.mojohaus.org/versions-maven-plugin/examples/advancing-dependency-versions.html
更新 09-2022
In the github 票证 https://github.com/mojohaus/versions-maven-plugin/issues/258我们在评论中发现可以看到以下更新:
看起来像这样的功能最近已经实现了#369 https://github.com/mojohaus/versions-maven-plugin/pull/369。请参见#318 https://github.com/mojohaus/versions-maven-plugin/issues/318可以提供包含和排除过滤器来确定将考虑哪些依赖模式。因此,您可以排除诸如以下的模式:.*-beta.
or .*_ALPHA
,虽然不使用正则表达式,但使用简单的星号通配符。
这将在今天的版本 (2.12.0) 中发布。
这将添加以下功能:
2.12.0版本将引入新的参数:dependencyIncluded
, dependencyExcludes
, dependencyManagementIncludes
, dependencyManagementExcludes
.
使用以下示例配置pom.xml
given:
<profile>
<id>display-dependency-updates</id>
<build>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>display-dependency-updates</goal>
</goals>
<configuration>
<dependencyIncludes>org.apache.maven.*:doxia*</dependencyIncludes>
<dependencyManagementIncludes>com.puppy*:*</dependencyManagementIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
这也将用于过滤plugin
and pluginManagement
,但这可能会在以后的版本中添加:
因此,我刚刚添加了缺少的插件和插件管理过滤,其工作原理类似。不过,我真的怀疑它是否会出现在今天的版本中。