A real maven plugin for jslint4java would be nice. I will write one, but until then, you can always get away with using the antrun plugin. This is fairly simple to do now that jslint4java is available in the central maven repository.
Here’s a plugin definition of how to do it.
org.apache.maven.plugins maven-antrun-plugin 1.3 com.googlecode.jslint4java jslint4java-ant 1.3 jslint test run
Notice how you can add the jslint4java-ant dependency to the antrun plugin without affecting the dependencies of the project.
At the test phase, maven will now run jslint for you. This relies on a small external ant build file to actually perform the jslint task.
We can use the nice antlibs namespace style of declaration because the jslint4java jar is in the classpath already.
Here, I’m assuming that we’re in a war project and want to validate all the files under src/main/webapp
. If this goes wrong, you’ll get an error and the build will stop. For example:
… Tests run: 26, Failures: 0, Errors: 0, Skipped: 0 [INFO] [antrun:run {execution: jslint}] [INFO] Executing tasks jslint: [jsl:jslint] contact.js:1:8:Bad line breaking before '+'. [jsl:jslint] + " Nulla in felis Aliquam luctus Proin tincidunt nisi Donec suscipit" [jsl:jslint] ^ … [jsl:jslint] load.js:17:6:Missing semicolon. [jsl:jslint] }) [jsl:jslint] ^ [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] An Ant BuildException has occured: The following error occurred while executing this line: /Users/dom/work/someproj/jslint.xml:4: 3 files did not pass JSLint
One side note: originally, I tried to fold the jslint.xml
file into the POM as well. But this failed to load the antlib. I suspect that xmlns attributes were not being passed in to the tasks definition. It’s not a big deal..
2 replies on “jslint4maven”
I should add the caveat that “fairly simple to do” assumes you’re comfortable with maven. 🙂
Worked a treat – real easy.
Many thanks