Uploaded image for project: 'Maven Enforcer Plugin'
  1. Maven Enforcer Plugin
  2. MENFORCER-101

Enforcer does not allow to restrict based on SNAPSHOT version as version comparison uses artifact.getVersion() instead of artifact.getBaseVersion()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-1
    • 1.0
    • Standard Rules
    • None
    • Any
    • Patch

    Description

      When following restriction is given to banned dependency rule, comparison fails as it compare with actual snapshot version in the repository (which includes timestamp 1.0-20100715.155142-18 ) instead of base version ( which has 1.0-SNAPSHOT )

      <build>
      <plugins>
      <plugin>
      <artifactId>maven-enforcer-plugin</artifactId>
      <executions> 
      <execution>
        <id>enforce-snapshot-ver</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <bannedDependencies>
              <searchTransitive>true</searchTransitive>
              <excludes>
                <exclude>org.apache.maven.enforcer:enforcer-rules</exclude>
              </excludes>
              <includes>
                <include>org.apache.maven.enforcer:enforcer-rules:[1.0-beta-2-SNAPSHOT]</include>
              </includes>
            </bannedDependencies>
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
      </executions>
      </plugin>
      </plugins>
      ..
      ..
      ..
      <dependencies>
      <dependency>
        <groupId>org.apache.maven.enforcer</groupId>
        <artifactId>enforcer-rules</artifactId>
        <version>1.0-beta-2-SNAPSHOT</version>
      </dependency>
      </dependencies>
      
      

      See code snippet below

      BannedDependencies.java
      try
      {
       result = AbstractVersionEnforcer.containsVersion( 
                  VersionRange.createFromVersionSpec( pattern[2] ),
                  new DefaultArtifactVersion(  artifact.getVersion() ) 
                );
      }
      catch ( InvalidVersionSpecificationException e )
      {
      throw new EnforcerRuleException( "Invalid Version Range: ", e );
      }
      

      replace

       new DefaultArtifactVersion(  artifact.getVersion() ) 
      

      with

       new DefaultArtifactVersion(  artifact.getBaseVersion() )
      

      will solve this issue

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              prashant.bhate Prashant Bhate
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: