We use the frontend-maven-plugin for using grunt and bower in our builds. With the Frontend Maven Plugin, I can install NPM locally, use Bower to download Java libraries, and run Grunt to optimize and obfuscate my code.
Like this with some simplification:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.24</version>
<executions>
<execution>
<id>install node and npm</id>
<goals> <goal>install-node-and-npm</goal> </goals>
...
</execution>
<execution>
<id>npm-install</id>
<goals> <goal>npm</goal> </goals>
...
</execution>
<execution>
<id>bower-install</id>
<goals> <goal>bower</goal> </goals>
...
</execution>
<execution>
<id>grunt-build</id>
<goals> <goal>grunt</goal> </goals>
...
</execution>
</executions>
</plugin>
Note that the last execution is grunt-build which is where the JavaScript files are concatenated together, optimized (returns, comments, and other things removed) and obfuscated.
This works well for releases. However, developers would like to deploy the war without the JavaScript files being concatenated, optimized, and obfuscated. This will help them with debugging. To do that, we merely have to remove the grunt-build
execution section from this plugin's configuration.
I'd like to use profiles to do this. I could have a profile called development
that allows developers to do a build without that last section. I could simply copy and paste this section of the pom.xml
file, remove that last execution, and put it into a separate profile. All done.
However, there's the old programming adage of don't repeat yourself. I'd be duplicating about 50 lines of code in my pom.xml
.
What I'd like to do is have a way to execute the first three executions, and do the fourth only if this isn't a development build. I would have a few other nips and tucks in this as well. For example, I would have to copy in the JavaScripts themselves rather than the grunted results. But, that's easy enough to do and doesn't duplicate code.
This would cause duplicate code because I'd have to define the frontend-maven-plugin
with two configurations. Once for the development
profile and once for the standard release build. As far as I know, I can't say, run this configuration of the frontend-maven-plugin
, and if this isn't a development build, run this instance of the frontend-maven-plugin
which will only do the grunt stuff.
Is there a way to define the same plugin twice in the pom.xm
, and have Maven run both instances in the right order?