Check out our Angular Book Series.

How do I run a Gulp Script in a different directory from Maven?

If you want to run a Gulp Script from Maven, you use the frontend plugin, right? Unfortunately, that seems to assume that the Gulp script is part of the Java project.

I'm creating a Java Backend to the LearnWith series and am sharing UI code between multiple backend technologies. As such, my directory structure is different and the UI code is not in the web root. I want to run a gulp script in a different directory, and then copy the results into the project's webapp directory. How do you do it?

I was able to do it with the exec Maven Plugin.

First, set up the plugin in the plugins portion of Maven POM:


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>

The groupId, arftifactId, and version are specified. For each script you want to run you'll need an execution statement:


<executions>
<execution>
<id>Build Angular 5</id>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>gulp</executable>
<arguments>
<argument>build</argument>
</arguments>
<workingDirectory>C:\Projects\lw\A5\chapter7\Angular5TypeScript</workingDirectory>
</configuration>
</execution>
</executions>

The id is a unique name for the build script. The phase is validate, because it is. The goal should be set to exec. The configuration is where the real magic happens. We tell it to execute the gulp command with the argument 'build', so this will run:


gulp build

We want to make sure that the script runs in the proper directory and that is specified with the workingDirectory tag. Presumably this directory will be outside the current directory structure.

Finally, close the plugin tag:


</plugin>

That's all you need to do to run an external Gulp Script from a Maven project. This assumes, of course, you have Gulp installed. Next week I'm going to write about copying the processed files into the Java project.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.