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

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta-1
    • Fix Version/s: 1.0
    • Component/s: Standard Rules
    • Labels:
      None
    • Environment:
      Any
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      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

        Issue Links

          Activity

          Dennis Lundberg made changes -
          Field Original Value New Value
          Link This issue relates to MENFORCER-94 [ MENFORCER-94 ]
          brianfox brianfox made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Fix Version/s 1.0-beta-2 [ 15129 ]
          Resolution Fixed [ 1 ]
          brianfox brianfox made changes -
          Fix Version/s 1.0 [ 13616 ]
          Fix Version/s 1.0-beta-2 [ 15129 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Prashant Bhate
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: