5

How can I override a plugin's version in command line without changing pom.xml?

More specifically:

I cannot compile apache shiro commit 8dd6a13. The reason is buildnumber-maven-plugin version 1.0-beta-4 is not available any more. When I modify pom.xml and change the plugin version to 1.0, I can compile the project. I would like keep the project untouched, and just set the version of the plugin when I run mvn from command line. I appreciate any insight and help.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.0-beta-4</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
            </configuration>
        </plugin>
oberlies
  • 11,503
  • 4
  • 63
  • 110
  • Probably you are looking for this. http://stackoverflow.com/questions/4660047/override-maven-plugin-configuration-defined-in-the-pom-pluginmanagement-from-the – Pratik Ambani Mar 07 '17 at 03:40
  • The version is available on [Maven Central](http://search.maven.org/#search|gav|1|g%3A%22org.codehaus.mojo%22%20AND%20a%3A%22buildnumber-maven-plugin%22), cause releases are immutable which means they will never be deleted. So there must be problem in your local setup. – khmarbaise Mar 07 '17 at 08:02

1 Answers1

5

You can use maven properties to set default version, when you run from command line you will have possibility to overwrite it.

<properties>
    <buildnumber.version>1.0-beta-4</buildnumber.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>${buildnumber.version}</version>

        ...

        <plugin>
    <plugins>
<build>

Now you can run, eg:

mvn clen install -Dbuildnumber.version=1.0

without settings property in command line maven will use default from pom.xml

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33