Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven yui compression on war:war

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>
like image 330
dfa Avatar asked Aug 08 '09 09:08

dfa


1 Answers

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:

  1. Try instead of running the war goal, run install or package, this will invoke the standard lifecycle, and the yuicompressor plugin will be invoked in the process-resources phase.
  2. Alternatively change the phase the yuicompressor goal is bound to in the example above to package so it is activated when you run the war:war goal.
like image 196
Rich Seller Avatar answered Nov 26 '22 17:11

Rich Seller