Question

We use Maven through a local Nexus repository. Unfortunately, when querying for new versions, we get several false positives:

commons-collections:commons-collections ............ 3.2.1 -> 20040616
org.hibernate:hibernate-entitymanager ..... 4.1.9.Final -> 4.3.0.Beta1

The first is a version that is ancient but with an incorrect naming scheme. The second is actually only a beta version (we don’t usually get these, but some seem to slip through). Now the question is: How can these versions, which are not really on our repository but come from one of the repositories our Nexus refers to, be excluded?

I have tried routing, but either I got it wrong or it cannot block specific versions, only the complete artifacts with all its versions. I have seen procurement in the documentation, but it seems very complicated and I did not dare trying.

Was it helpful?

Solution

You may configure the versions-maven-plugin in your project's POM (or a corporate parent somewhere) to use a rules file telling the plugin which versions to ignore.

<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>

An example rules file looks like the below. Mine ignores the "99.0-does-not-exist" version of the commons-logging plugin.

<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>

You may add configuration to ignore other versions globally, not per-artifact as I did here, and regular expressions may be used as well. More information is available in the plugin documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top