Search code examples
javamavenversionpom.xmlmvn-repo

Maven Versions Plugin - Skip running maven versions plugin during mvn build install


Whenever I run mvn clean install I want mvn versions plugin to run, which is how my project currently operates. This is perfect, but sometimes I may want to NOT run maven versions plugin to speed up build time (this case is more the exception that the rule).

But I can't find anyway to skip it... (there's no -DskipVersions=true AFAIK).

Does anyone know how can I skip the execution of only this plugin?

maven-versions-plugin: https://www.mojohaus.org/versions-maven-plugin/


Solution

  • Use a maven profile for executing the version maven plugin. When activeByDefault you do not need to add the profile for maven build.

    <profiles>
      <profile>
        <id>useVersion</id>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <plugins>
             <plugin>
                 ...
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>versions-maven-plugin</artifactId>        
                  ...
              </plugin>
        </plugins>
      </profile>
    </profiles>
    

    You could disable the profile by using !

    mvn clean install -P !useVersion
    

    For further information Llook at https://maven.apache.org/guides/introduction/introduction-to-profiles.html