Selective Build Maven Plugin
Selective Build Maven Plugin allows you to build and process only modules with changes in it. It is dependent on git client installed on your system.
Goal changes
This goal is used for selective builds (build only modules with changes).
It is used in three steps:
- Configure the plugin in the root POM
- Run the plugin and put the result into a environment variable
- Run standard maven build with options from the variable
Root POM setup
To use this plugin first you should set it up in the root POM like this.
<project>
...
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>eu.lundegaard.maven</groupId>
<artifactId>selective-build-maven-plugin</artifactId>
<version>0.5.0</version>
</plugin>
</plugins>
</pluginManagement>
...
</build>
...
</project>
Get params for the build
The changes
plugin outputs on stdout parameters for the onward build. These parameters are based on current git status and can result into one of the following states:
- Non-recursive build (build only root project) -- This happens mainly when there are no changes detected
- Selective build (build only changed modules)
- Full rebuild -- this happens when there are too much commits or when special files are changed
To obtain params one usually runs something like this:
MVN_RUN_OPTS=$(mvn -q -N selective-build:changes -Dsource=1234567890ABCDEF -Dtarget=FEDCBA0987654321)
The source
and target
properties are either commits or branches between which the changes are detected.
Run selective Maven build
To run the selective build afterwards is simple. Just run something like this:
mvn $MVN_RUN_OPTS clean verify