如何阻止Nexus中的特定Maven工件

Mic*_*fel 3 nexus maven

我们通过本地Nexus存储库使用Maven。不幸的是,在查询新版本时,我们得到了一些误报:

commons-collections:commons-collections ............ 3.2.1 -> 20040616
org.hibernate:hibernate-entitymanager ..... 4.1.9.Final -> 4.3.0.Beta1
Run Code Online (Sandbox Code Playgroud)

第一个是古老的版本,但命名方案不正确。第二个实际上只是一个beta版本(我们通常不会得到这些版本,但是有些似乎会漏掉)。现在的问题是:如何排除这些不是我们存储库中真正存在的版本,而是来自Nexus所指的存储库之一的版本?

我尝试过路由,但是要么我弄错了它,要么它不能阻止特定版本,只能阻止所有版本的完整工件。我在文档中看到了采购,但是看起来很复杂,我也不敢尝试。

use*_*849 5

您可以versions-maven-plugin在项目的POM(或公司的母公司)中配置,以使用规则文件告诉插件要忽略哪些版本。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>versions-maven-plugin</artifactId>
  <version>2.1</version>
  <configuration>
    <!-- some location that makes sense for your company/project -->
    <rulesUri>http://host.company.com/maven-config/maven-version2-rules.xml</rulesUri>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

示例规则文件如下所示。我的忽略了commons-logging插件的“ 99.0-does-not-exist存在”版本。

<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">
  <rules>
    <rule groupId="commons-logging" artifactId="commons-logging">
      <ignoreVersions>
        <ignoreVersion>99.0-does-not-exist</ignoreVersion>
      </ignoreVersions>
    </rule>
  </rules>
</ruleset>
Run Code Online (Sandbox Code Playgroud)

您可以添加配置以全局地忽略其他版本,而不是像我在此处那样按每个工件进行配置,并且也可以使用正则表达式。插件文档中提供了更多信息。