You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过maven-version-rules.xml仅处理指定前缀的构件?

Targeting Only com.xxx.yyy Artifacts with Maven Versions Plugin

Absolutely you can! The Maven Versions plugin lets you focus solely on artifacts with a group ID starting with com.xxx.yyy—you just need to configure it properly, either directly in your pom.xml or via the maven-version-rules.xml file you referenced. The key is to define a rule that matches your target group prefix and set a default rule to ignore all other artifacts.

1. Direct Configuration in pom.xml

You can embed the rules directly into your project's pom.xml. Here's how:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>versions-maven-plugin</artifactId>
      <version>2.16.0</version> <!-- Use the latest stable version -->
      <configuration>
        <!-- Rule to process only artifacts with group ID starting with com.xxx.yyy -->
        <rules>
          <rule>
            <groupIdRegex>^com\.xxx\.yyy.*</groupIdRegex>
            <!-- Allow all versions (enables normal version check/update for these artifacts) -->
            <allowedVersions>.*</allowedVersions>
          </rule>
        </rules>
        <!-- Default rule: ignore version checks for all other artifacts -->
        <ruleSet>
          <rules>
            <rule>
              <groupIdRegex>.*</groupIdRegex>
              <ignoreVersions>.*</ignoreVersions>
            </rule>
          </rules>
        </ruleSet>
      </configuration>
    </plugin>
  </plugins>
</build>

Key Notes:

  • The ^com\.xxx\.yyy.* regex ensures we match group IDs that start exactly with com.xxx.yyy (the backslashes escape the dots, since regex uses . to match any character).
  • Order matters! The specific target rule comes first, so it takes precedence over the default "ignore all" rule.
  • The <allowedVersions>.*</allowedVersions> tells the plugin to check all valid versions for the targeted artifacts—you can narrow this down to a version range if needed (e.g., [1.0.0,2.0.0)).

2. Using maven-version-rules.xml

If you prefer to keep rules in a separate file (like you mentioned), create the maven-version-rules.xml in your project root with this content:

<ruleset xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
  
  <!-- Process only com.xxx.yyy prefixed artifacts -->
  <rule>
    <groupIdRegex>^com\.xxx\.yyy.*</groupIdRegex>
    <allowedVersions>.*</allowedVersions>
  </rule>

  <!-- Ignore all other artifacts -->
  <rule>
    <groupIdRegex>.*</groupIdRegex>
    <ignoreVersions>.*</ignoreVersions>
  </rule>
</ruleset>

Then reference this file in your pom.xml's plugin configuration:

<configuration>
  <rulesUri>file://${basedir}/maven-version-rules.xml</rulesUri>
</configuration>

Testing the Setup

Run any Versions plugin goal (like mvn versions:display-dependency-updates) and you’ll see only updates for com.xxx.yyy artifacts listed—all others will be skipped entirely.

内容的提问来源于stack exchange,提问作者Marx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:58:00