When developing web applications with an abundance of JS, over time you come across the need to automate building and testing, as well as building various reports, documentation, etc. We encountered this problem almost immediately after the start of the project. Due to the fact that the server part is implemented in Java, the choice obviously fell on Maven. It remained to find a plugin that can work with javascript.
Searches were short-lived and led to
mojo.codehaus.org/javascript-maven-tools/ . “What you need,” I thought, and began to fasten it to the project.
Plug-in connection
First,
let's configure maven to use plugins from the sandbox .
Project preparation
Create a project with the
structure described on the site of the plugin. The pom.xml file can be taken from the example from the site.
')
Build Setup
Add the following section to pom.xml:
< build >
< outputDirectory > target/scripts </ outputDirectory >
< testOutputDirectory > target/test-scripts </ testOutputDirectory >
< plugins >
< plugin >
< groupId > org.codehaus.mojo.javascript </ groupId >
< artifactId > javascript-maven-plugin </ artifactId >
< version > 1.0-alpha-1-SNAPSHOT </ version >
< extensions > true </ extensions >
< configuration >
< descriptor > ${basedir}/src/main/assembler/solution.jsb </ descriptor >
</ configuration >
< executions >
< execution >
< goals >
< goal > compile </ goal >
</ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >
* This source code was highlighted with Source Code Highlighter .
Now at the compilation phase, the plugin will merge the files specified in solution.jsb into one (or several) packages.
Report Setup
As usual we add (or change) the section in pom.xml
< reporting >
< plugins >
< plugin >
< groupId > org.codehaus.mojo.javascript </ groupId >
< artifactId > javascript-report-maven-plugin </ artifactId >
< version > 1.0-alpha-1-SNAPSHOT </ version >
< reportSets >
< reportSet >
< reports >
< report > jsdoc </ report >
< report > jslint </ report >
</ reports >
</ reportSet >
</ reportSets >
</ plugin >
</ plugins >
</ reporting >
* This source code was highlighted with Source Code Highlighter .
Now at the stage of site generation (site target), we will generate jsdoc, as well as a report on the correctness of the code (with the help of JSLint). The result of JSLint is especially useful, as it allows to eliminate shortcomings and errors in the code at an early stage (for example, an extra comma in the array is very sad for IE).
Build project
To build a project, just run the
mvn compile
command at the root of the project. After that, we will have an assembled application in the
target/scripts
folder, ready to be uploaded to the site.
To generate reports, you must run the command
mvn site
. The generated reports will be found in the
target/site
folder
target/site
A spoon of tar
Unfortunately, this plugin is in a state of alpha testing. But this is not the worst. Worse, the plugin no longer develops. Last activity is dated the beginning of the 9th year.
A barrel of honey
Due to the fact that this plugin is actively used in our project, we have prepared several patches and are planning to offer their owner javascript-maven-tools.
Ps. Thank God, the license allows you to fork the project, so in case of a negative response, we will definitely take advantage of the Apache License.