Javascript Maven plugin
Javascript Maven plugins
- javascript-maven-tools plugin (svn)
- compression (Dojo Shrinksafe, YUI compressor)
- assembly
- strip debugging code
- automated unit tests (JsUnit)
- code quality check (JSLint)
- MobilVox Maven JavaScript
- compression
- yuicompressor-maven-plugin
- compression
javascript-maven-tools
We choose the javascript-maven-tools plugin for its rich featureset and active development.
Storage
Js-files are packed in a jar file and stored in the repository.
Dependency
Dependencies between javascript artefacts can be forced. The javascript plugin must therefore be declared as an extension in the POM for these artefacts.
.. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>maven-javascript-plugin</artifactId> <extensions>true</extensions> </plugin> ..
Other js artefacts can than force the dependency as for java artefacts, but with the type set to 'javascript':
.. <dependency> <groupId>..</groupId> <artifactId>..</artifactId> <version>..</version> <type>javascript</type> </dependency> ..
Assembly
It's possible to combine different js-files in one big file during the build
cycle. This prevents the designer to have to include a bunch of javascript
files, and still keeps de code easy to maintain.
An assembler XML-file describes which files to combine, and in what order.
<?xml version="1.0"?>
<assembler>
<scripts>
<script>
<fileName>combined.js</fileName>
<includes>
<include>file1.js</include>
<include>file2.js</include>
</includes>
</script>
</scripts>
</assembler>
The descriptor-tag in the configuration of the plugin points to this file.
<configuration>
..
<descriptor>${basedir}/src/assembler/myAsm.xml</descriptor>
..
</configuration>
Strip debugging code
The pluging provides a goal that strips lines starting with a special token from the code. This is usefull for removing debug code. The token can be set in the plugin configuration with the strip-tag.
Compression
There are three compressors included: Dojo Shrinksafe, YUI compressor and JSMin. JSMin is de deafult one used, this can be changed in he plugin configuration by the compressor-tag. The possible values are: 'shrinksafe', 'yahooui' and 'jsmin'.
Configuration
Compression:
|
Tag |
Default |
Description |
|---|---|---|
|
optimizationLevel |
9 |
Optimization level, from 0 to 9 |
|
languageVersion |
130 |
JS Language version (130 for JS 1.3) |
|
compressor |
jsmin |
The compressor to used. Either "shrinksafe", "yahooui" or "jsmin" for default compressor, or a custom one provided as an artifact in repo org.codehaus.mojo.javascript:<xxx>-compressor. |
|
skipStats |
false |
Don't display compression stats |
|
compressedDirectory |
${project.build.directory}/compressed |
The output directory of the compressed javascript files. |
|
buildDirectory |
${project.build.directory} |
The output directory of the compressed javascript archive. |
|
finalName |
${project.build.finalName} |
The filename of the compressed js file. |
|
classifier |
compressed |
Classifier for the compressed artefact |
|
scriptClassifier |
Optional extension for the compressed artifact. Example "compressed" |
|
|
scriptsDirectory |
${project.build.outputDirectory} |
The intput directory for the source javascript files. |
Strip debugging code:
|
Tag |
Default |
Description |
|---|---|---|
|
strip |
A special token to recognize lines to be removed from scripts (debugging code). |
Assembler:
|
Tag |
Default |
Description |
|---|---|---|
|
sourceDirectory |
${basedir}/src/main/javascript |
Location of the source files. |
|
outputDirectory |
${project.build.outputDirectory} |
The output directory of the assembled js file. |
|
descriptor |
src/assembler/${project.artifactId}.xml |
Descriptor for the strategy to assemble individual scripts sources into destination. |
|
descriptorFormat |
default |
Descriptor file format ("default" or "jsbuilder"). |


There are no comments.