Grunt Maven Integration

You may want to integrate Grunt and Maven to be able to build frontend every time just before a Maven build.

For this purpose, I prefer to use exec plugin to invoke “grunt build” in the beginning of each Maven build.

My “Gruntfile.js” is under /WebContent directory so

<workingDirectory>WebContent</workingDirectory>

line is important.

<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>grunt-default</id>
<phase>generate-resources</phase>
<configuration>
<workingDirectory>WebContent</workingDirectory>
<executable>grunt</executable>
<arguments>
<argument>build</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
view raw pom.xml hosted with ❤ by GitHub

Even if it works fine, there is also an error like
Plugin execution not covered by lifecycle configuration bla bla bla

So instead of this I started to use eirslett/frontend-maven-plugin with this configuration

<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.27</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v0.10.18</nodeVersion>
<npmVersion>1.3.8</npmVersion>
<nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
<npmDownloadRoot>http://pkgs.fedoraproject.org/repo/pkgs/npm/npm-1.3.8.tgz/494b89b1b32fa2f0e653d38b08bee0ae/</npmDownloadRoot>
<installDirectory>WebContent</installDirectory>
</configuration>
</execution>
<execution>
<id>grunt-default</id>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<workingDirectory>WebContent</workingDirectory>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
view raw pom.xml hosted with ❤ by GitHub

It is a better choice!

[1] http://stackoverflow.com/questions/22393785/exec-maven-plugin-says-cannot-run-specified-program-even-though-it-is-on-the-pa

[2] http://stackoverflow.com/questions/3491937/i-want-to-execute-shell-commands-from-mavens-pom-xml

[3] http://stackoverflow.com/questions/27822050/using-maven-to-install-bower-components-with-bower-installed-globally​

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: