Find-maven-plugin
From Evgeny Goldin
Introduction
Most of the time POMs operate on files located somewhere relative to ${project.basedir}:
-
${project.basedir}/src/main/java -
${project.basedir}/src/main/scripts -
${project.basedir}/../otherModule
Sometimes, file or directory path can not be expressed as a function of ${project.basedir}. It happens if some plugin is configured in aggregator/parent POM and needs an access to a certain directory. This "special" directory may contain a script to run or a data file to use. Since ${project.basedir}-related expressions are evaluated in the context of currently executing POM we can't use them in aggregator/parent POM: something that is "${project.basedir}/../../specialDir" in one child module, can be "${project.basedir}/../specialDir" or "${project.basedir}/specialDir" in another.
We need a way to get an absolute, not relative path:
<plugin> <groupId>com.github.goldin</groupId> <artifactId>find-maven-plugin</artifactId> <version>0.2.5</version> <executions> <execution> <id>find-special-dir</id> <goals> <goal>find</goal> </goals> <phase>validate</phase> <configuration> <runIf>{{ .. }}</runIf> <propertyName>special.dir.path</propertyName> <sysPropertyName>special.dir.path</sysPropertyName> <file>SPECIAL_DIR</file> <!-- Default value --> <startDir>${project.basedir}</startDir> <!-- Default value --> <failIfNotFound>true</failIfNotFound> </configuration> </execution> </executions> </plugin>
-
<runIf>is optional. It specifies if plugin needs to be run, see"copy-maven-plugin"documentation for more details. -
"find-maven-plugin""climbs up" directories starting from the<startDir>and looking for"SPECIAL_DIR"directory. It goes up until it either finds the"SPECIAL_DIR"or gets to the top and fails, if<failIfNotFound>is"true". - When found, Maven property
${special.dir.path}is set to directory's canonical path. - If
<sysPropertyName>is specified, system property with name specified is set as well. - If executed again in the same build,
"find-maven-plugin"does nothing since all variables are already set, so the "climbing" process only happens once.
Files can be searched for as well:
<plugin> <groupId>com.github.goldin</groupId> <artifactId>find-maven-plugin</artifactId> <version>0.2.5</version> <executions> <execution> <id>find-about-file</id> <goals> <goal>find</goal> </goals> <phase>validate</phase> <configuration> <propertyName>about.file.path</propertyName> <file>src/main/scripts/about.xml</file> </configuration> </execution> </executions> </plugin>
Now, having ${special.dir.path} and ${about.file.path} properties set we can use them for any purpose, as a usual Maven property. This time it is not ${project.basedir}-related expression and always contains the same full path of directory or file found in any child POM, regardless of its depth.
Details
| Provided By | ||
|---|---|---|
| Mailing List | Nabble | |
| Source Code | GitHub | |
| Tests | GitHub | |
| GroovyDoc | <groovydoc>
| |
| Issue Tracker | YouTrack | |
| Build Server | Maven TeamCity | |
| Maven Coordinates |
| |
| Goal |
| |
| Default Phase |
| |
| Maven Repository | Artifactory |
