views:

792

answers:

2

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>
+3  A: 

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.
Rich Seller
done, but it doesn't works under maven 2.2.0 nor maven 2.1.0
dfa
this worked fine on my test project, the compressed files are output to target/classes
Rich Seller
fixed thanks anyway :)
dfa
+1  A: 

for some weird reason war:war doesn't call the plugin in the phase process-resources: I just added a custom menu on nb 6.7 that call first compile, then war:war

dfa