Usage
This document is intended to provide instructions for using the Closure Compiler Maven Plugin.
In order for this discussion to be useful, it's critical to cover two topics:
- Configuring your project's
pom.xml
to run the plugin during the project's build cycle - Invoking the plugin from the command-line
Configure Minify Maven Plugin
By tying the goals of the plugin to a phase in the build cycle, the specified goals will run each time that phase of the build cycle is executed. Doing this can make it easier to add the plugin to your project, because it eliminates the need to run the plugin standalone.
To bind the minify goal of the Minify Maven Plugin to a phase in the build cycle, you will need to add the execution
tag with the goal
set to minify
. Optionally, you can bind the plugin to a different build phase by using the phase
option. For instance, using package
in the phase
option will force the minify goal to run each time this phase of the build cycle occurs.
For a complete list of the available configuration options see minify:minify goal overview page.
Merge order
Applies when input JS files are merged and minified into a single output file:
- For each include (input file) defined in
includes
, the list of matching files is created. - The matching files for each
include
are sorted alphabetically. - Matching files from different
include
's are added in the order as specified.
See also Using include/exclude patterns.
<project>
<!-- ... -->
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>com.github.blutorange</groupId>
<artifactId>closure-compiler-maven-plugin</artifactId>
<version>${closure-compiler-maven-plugin.version}</version>
<executions>
<execution>
<id>default-minify</id>
<phase>package</phase><!-- When omitted defaults to 'process-resources' -->
<configuration>
<!-- These are the defaults -->
<encoding>UTF-8</encoding>
<baseSourceDir>${basedir}/src/main/webapp</baseSourceDir>
<baseTargetDir>${project.build.directory}/${project.build.finalName}</baseTargetDir>
<sourceDir>js</sourceDir>
<targetDir>js</targetDir>
<!-- List of files to process. May use wildcards. -->
<includes>
<include>file-1.js</include>
<!-- ... -->
<include>file-n.js</include>
</includes>
<outputFilename>script.js</outputFilename>
</configuration>
<goals>
<goal>minify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ... -->
</plugins>
</build>
<!-- ... -->
</project>
Invoke from the command-line
Create the project archive containing the new files.
mvn package