I'm trying to automatically compress both CSS and JS using maven and this plugin. I want to compress when the goal war is executed but I'm not figuring how:
<build>
<finalName>${artifactId}-${version}-production</finalName>
<plugins>
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<gzip>true</gzip>
<nosuffix>true</nosuffix>
</configuration>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You need to bind the execution to a phase so it will be executed when you run the war packaging. These are the available phases you can bind to for war packaging.
<plugin>
<groupId>net.sf.alchim</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<id>compress</id>
<phase>process-resources</phase>
...<!--rest of config is fine-->
Update: Are the js.gz files not being generated or just not included in the war?
One additional thing to check if you're still not seeing the content in the war is that the resources should be under src/main/resources, not src/main/webapp. The yuicompressor plugin will process the js files in src/main/webapp, but they won't be included in the final war.
Update 2: reread your question after seeing your answer, I'd misread the goal you were running. To avoid running two goals you can do one of these:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With