user1393881
user1393881

Reputation:

Override Maven Plugin Version from Command Line?

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>

Upvotes: 5

Views: 3467

Answers (1)

Slawomir Jaranowski
Slawomir Jaranowski

Reputation: 8497

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

Upvotes: 5

Related Questions