Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven properties at plugin execution time

Tags:

People also ask

What is properties Maven plugin?

The Properties Maven Plugin is here to make life a little easier when dealing with properties. It provides goals to read properties from files and URLs and write properties to files, and also to set system properties. It's main use-case is loading properties from files or URLs instead of declaring them in pom.

What is the difference between plugin and pluginManagement tags?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

What is execution in Maven plugin?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .


I am trying to figure out how to set a maven property to a different value at different points in the lifecycle. For example, if I set a property at the project level

<project>
    <properties>
        <some.property>Value</some.property>
    </properties>
</project>

During a third-party plugins execution I would like to be able to change it to something else.

<plugins>
    <plugin>
        <groupId>com.github.mcheely</groupId>
        <artifactId>requirejs-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
           <execution>
                <!-- change the value here -->
           </execution>
           <execution>
                <!-- change the value here again-->
           </execution>
        </executions>
    </plugin>
</plugins>

Or alternatively, rather than go the variable setting route, It would work just as well if I could access a unique ID or property set inside the particular execution. For example-

<plugins>
    <plugin>
        <groupId>com.github.mcheely</groupId>
        <artifactId>requirejs-maven-plugin</artifactId>
        <version>2.0.0</version>
        <executions>
           <execution>
               <id>SomeID</id>
               <!-- change the value here -->
           </execution>
           <execution>
               <id>SomeID</id>
               <!-- change the value here again-->
           </execution>
        </executions>
    </plugin>
</plugins>

and then access this variable like so

${execution.id}

Any ideas?