I've been struggling with getting this plugin to play nicely with the maven-war-plugin for a couple of hours now and I thought it was time to ask for help. I have the plugin defined as follows:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>compressyui</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<nosuffix>true</nosuffix>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<jswarn>false</jswarn>
</configuration>
</execution>
</executions>
</plugin>
If I remove nosuffix=true then I can see the compressed/minified -min.js files get into the war as expected, but with this flag on they are being overwritten by the maven-war-plugin (I'm assuming) when it builds the war file. I really need the file names to remain the same though ... does anyone have an idea of what I need to change in order to use the same filenames and still get the minified versions into the final war?
OK. I finally figured this out. You need to define a
<webappDirectory>
in the yuicompressor plugin that can then be referenced as a<resource>
in the maven-war-plugin. In the example below I'm using<directory>${project.build.directory}/min</directory>
As Jakob Kruse say, you must deal with the *.js, but no *.min.js, so my configurations is below, please notice the use of %regex[] :
Without pom.xml change
To force compress every js and css files and fail if warning
For more options: http://davidb.github.io/yuicompressor-maven-plugin/usage_compress.html
this is my configuration, and it works fine in my maven web project:
Just configure 'warSourceExcludes' on the WAR plugin.
I would like to add the configuration which worked for me:
First, to fix m2e complaining about the 'Plugin execution not covered by lifecycle' I added the following in the parent pom taken from this post:
Then in the war pom I put:
This generates the minified css and js files in the project build target directory while excluding the original files.
I hope this saves someone time.