Maven JavaScript Plugin
Maven JavaScript Plugin is a multi-purpose build manager for Javascript projects. It brings two new packaging types javascript and titanium with their own lifecycle to build standalone JavaScript libraries and Appcelerator™ Titanium applications. It also integrate in war projects for integration in web applications. Finally, it allows unit and functional testing using the traditional JsUnit framework or the more adapted Jasmine behavior-driven testing framework.
Goals Overview
For JavaScripts developers :
- javascript:compile prepares your scripts to get packed. An XML descriptor can be used to configure some scripts to get merged into a single new file. Resolve compile-time dependencies and provide them to the assembling processor as well.
- javascript:compress uses a configurable javascript compressor to reduce the weight of JavaScript files resulting from javascript:compile goal. Optionnaly also strip out debugging code from scripts before compression, by removing all lines that start with given special tokens.
- javascript:package packs scripts into a Maven Javascript archive, ready to be installed and deployed in a Maven repository.
- javascript:attach-compressed packs compressed scripts in a Maven JavaScript archive classified compressed, ready to be installed and deployed in a Maven repository with the uncompressed version.
- javascript:install installs the Maven JavaScript archive in the local repository.
- javascript:deploy deploys the Maven JavaScript archive to a remote repository.
For web application developers :
- javascript:inplace Unpacks run-time JavaScript dependencies to your web application source folder, to enable quick development with servlet containers that don't require a packaging phase.
- javascript:war-package prepares scripts and runtime dependencies to get packed in a web application.
- javascript:war-compress uses a configurable JavaScript compressor to reduce the weight of js files present in the webapp packaging folder. Optionnaly also strip out debugging code from scripts before compression, by removing all lines that start with a special token (";;;" for example).
For Titanium Appcelerator™ application developers :
- javascript:titanium-compile prepares your scripts to get packed in a Titanium Appcelerator™ application for a given platform. An XML descriptor can be used to configure some scripts to get merged into a single new file. An app.js file should result from this process. Resolve compile-time dependencies and provide them to the assembling processor as well.
- javascript:titanium-prepare-package uses a configurable JavaScript compressor to reduce the weight of js files present in the application folder. Optionnaly also strip out debugging code from scripts before compression, by removing all lines that start with a special token (";;;" for example). Only proceed to stripping and compression when preparing a production application.
- javascript:titanium-package builds an native application using Titanium Appcelerator™ application builders for the requested device. Optionally install the application on the device, or run it in an emulator/simulator.
For unit and functional testing :
- javascript:prepare-jasmine-tests prepares scripts for testing without assembling or compression. Resolves run-time and provided dependencies. Prepares the Jasmine specs files.
- javascript:prepare-jsunit-tests prepares scripts for testing using JSUnit framework.
- javascript:generateManualRunner resolves run-time and provided dependencies. Generates a Jasmine runner for manual running in an interactive browser, taking script sources directly in the project sources tree, enabling quick development.
- javascript:jasmine Generates a batch Jasmine specs runner and run it under the HtmlUnit engine using one or more browser emulation modes.
- javascript:jsunit Runs JSUnit tests.
- javascript:prepare-titanium-jasmine-tests Prepares scripts for testing without assembling. Resolves run-time and provided dependencies. Prepares the Jasmine specs files and generate an app.js scripts for running tests in a Titanium Appcelerator™ test application.
- javascript:titanium-jasmine Builds an native application using Titanium Appcelerator™ application builders for the requested device and install the application on the device, or runs it in an emulator/simulator.
Lifecycles
The Maven Javascript Plug-in provide two new packaging types javascript and titanium which both associate custom goals to the standard lifecycle:
For javascript packaging :
Usage
The easiest way to use this plug in is to use it with its own specials lifecycles. To ensure that you will be using the these lifecyles, there is two steps:
- Define the plugin as an extension to expose the specials lifecycles to Maven
- Use either javascript or titanium as packaging to select the correct lifecycle for your build
Here is the minimal settings for completing these two requirements in your POM :
<project ...>
...
<packaging>javascript</packaging> OR <packaging>titanium</packaging>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo.javascript</groupId>
<artifactId>javascript-maven-plugin</artifactId>
<version>1.1-softec</version>
<extensions>true</extensions>
<configuration>
...
</configuration>
</plugin>
...
</plugins>
...
</build>
...
<pluginRepositories>
<pluginRepository>
<id>softec-opensource</id>
<url>http://nexus.softec.lu:8081/content/repositories/opensource</url>
</pluginRepository>
</pluginRepositories>
...
</project>
For detailled information on plugin configuration, you should read:
Examples
For those who learn by example, here is some library project using JavaScript Maven tools :
- debug.js - An improved implementation of Ben Alman debug.js, a standalone library
- i18n - A localization library, a simple library with some dependencies
- Carto - A wrapper and enhancer for Google Maps, a dual library with a special assembly for a Titanium classified version
- CartoClic JSAPI - A JS API for CartoClic, a library compatible with Titanium, with Titanium tests
- Improved - An improved version of Prototype.js, a dual library with a Titanium classified version, and Titanium tests
- CartoClic Titanium Application - A Titanium application, with Android and iOS build