javascriptbuild-processbuild-automationmavenmaven-1

Running JS minification as a maven goal?


I'm trying to use YUI compressor in a maven goal, but I'm pretty new to the inner workings of maven. I see that I can copy all js to a new directory with the following:

<copy todir="blah">
  <fileset>
     <!-- A bunch of file extension types -->
  </fileset>
</copy>

Now, for each css and js file, I want to run the run the yui compressor and output the file to the final locations of the files copied above. Not that directory structure is maintained in the copy given above, so that may be something to consider when creating the maven goal.

Where do I start? I essentially need to run

java -jar yuicompressor input.js -o output.js

on all files. I'm restricted to maven 1.x, so where do I start? I want to make this a maven goal to avoid having to compress js by hand before a build, as that would be sloppy. If I could execute an external python/perl script to do this, that would be fine also, but I think that there is perhaps a better maveny way to do this.


Solution

  • Use YUI compressor ant task and follow the tutorial.

    YUI ant task.