Dynamically Setting the Name of the output of a Maven build

by 4/05/2010 04:32:00 PM 0 comments

Dynamically Setting the Name of the output of a Maven build

I came across this post at DZone where essential the author was complaining that he couldn't set the name of the build product in Maven without modifying the pom.xml file. In his case he wanted to pull the version number from Git. The solution was actually pretty straightforward with a little scripting help from GMaven. Here's an example

 <plugins>
   <plugin>
     <groupId>org.codehaus.groovy.maven</groupId>
     <artifactId>gmaven-plugin</artifactId>
     <executions>
       <execution>
         <id>groovy-magic</id>
         <phase>prepare-package</phase>
         <goals>
           <goal>execute</goal>
         </goals>
         <configuration>
           <source>
             def scmversion = 'git describe'.execute().text.trim()
             project.build.finalName = "${project.artifactId}-${scmversion}"
           </source>
         </configuration>
       </execution>
     </executions>
   </plugin>
 </plugins>
</build>

Brian Schlining

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments: