jslint4java maven plugin

If you are using maven to build an application which contains JavaScript, you can arrange for JSLint to run automatically.

Here's an example configuration.

<project>
  …
  <build>
    …
    <plugins>
      …
      <plugin>
        <groupId>com.googlecode.jslint4java</groupId>
        <artifactId>jslint4java-maven-plugin</artifactId>
        <version>2.0.1</version>
        <executions>
          <execution>
            <id>lint</id>
            <phase>process-resources</phase>
            <goals>
              <goal>lint</goal>
            </goals>
            <configuration>
              <failOnError>true</failOnError>
              <options>
                <undef>true</undef>
              </options>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
    

This will arrange for the jslint4java-maven-plugin to execute before the rest of your build. If you would prefer to execute it afterwards, choose <phase>verify</phase> instead.

If you would prefer to run the linter on an ad-hoc basis, you can call the plugin from the command line.

$ mvn jslint4java:lint
    

In order to support this, you should still configure the plugin as part of your project, but not bind it to the lifecycle. e.g.

<project>
  …
  <build>
    …
    <plugins>
      …
      <plugin>
        <groupId>com.googlecode.jslint4java</groupId>
        <artifactId>jslint4java-maven-plugin</artifactId>
        <version>2.0.1</version>
        <configuration>
          <failOnError>true</failOnError>
          <options>
            <undef>true</undef>
          </options>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
    

Configuration

The plugin is mainly controlled via the <configuration> element. It supports these children.

Element Description Default
<encoding> What encoding to read the source files in. UTF-8
<excludes> A comma separated list of patterns to exclude from linting.
<includes> A comma separated list of filename patterns lint. **/*.java
<jslintSource> An alternative jslint.js to use, in case the builtin version is insufficient. The builtin version.
<options> Which options to pass to JSLint. Each option must be specified as child element, e.g.
<maxlen>72</maxlen>
<predef>console, jQuery</predef>
<undef>true</undef>
          
Please see Option for the full list of Options that can be specified.
<outputDirectory> Where to write the jslint.xml report file. /Users/hdm/work/jslint4java/target/checkout/jslint4java-docs/target
<sourceFolders> One or more folders to find the JavaScript files to lint. /Users/hdm/work/jslint4java/target/checkout/jslint4java-docs/src/main/webapp
<timeout> How many seconds JSLint is allowed to run for. infinite