title: YUI Compressor Maven plugin executed at wrong time and tomcat plugin not using yui-compressor output
body: <p>I am trying to use the YUI Compressor plugin for maven to compress my CSS and JavaScript, but I'm experiencing two problems.</p>
  
  <ol>
  <li><p>My configuration properly compresses and aggregates the JavaScript files, but if I run <code>mvn package</code> to make a war file, maven will compress the JavaScript files BEFORE it copies over the <code>src/main/webapp</code> folder. This overwrites all of the compressed css and JavaScript files. How can I fix this?</p></li>
  <li><p>How do I get the tomcat maven plugin to use the compressed JavaScript files rather than the ones in my <code>src/main/webapp/scripts</code> folder? When my application is trying to read <code>all.js</code>, it is failing because it is located in the <code>target/</code> directory and not in my <code>src/main/webapps</code> folder.</p>
  
  <pre><code>    &lt;!-- Tomcat --&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
          &lt;artifactId&gt;tomcat-maven-plugin&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
          &lt;configuration&gt;
              &lt;warFile&gt;target/myapp-1.0.war&lt;/warFile&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;
  
      &lt;!-- YUI Compressor --&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;net.alchim31.maven&lt;/groupId&gt;
          &lt;artifactId&gt;yuicompressor-maven-plugin&lt;/artifactId&gt;
          &lt;executions&gt;
              &lt;execution&gt;
                  &lt;goals&gt;
                      &lt;goal&gt;compress&lt;/goal&gt;
                  &lt;/goals&gt;
              &lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
              &lt;excludes&gt;
                  &lt;exclude&gt;**/jwplayer.js&lt;/exclude&gt;
                  &lt;exclude&gt;**/audio-player-noswfobject.js&lt;/exclude&gt;
                  &lt;exclude&gt;**/audio-player-uncompressed.js&lt;/exclude&gt;
                  &lt;exclude&gt;**/audio-player.js&lt;/exclude&gt;
                  &lt;exclude&gt;**/jscharts.js&lt;/exclude&gt;
                  &lt;exclude&gt;**/jquery-ui-1.8.16.custom.min.js&lt;/exclude&gt;
              &lt;/excludes&gt;
              &lt;nosuffix&gt;true&lt;/nosuffix&gt;
              &lt;jswarn&gt;false&lt;/jswarn&gt;
              &lt;force&gt;false&lt;/force&gt;
              &lt;aggregations&gt;
                  &lt;aggregation&gt;
                      &lt;removeIncluded&gt;false&lt;/removeIncluded&gt;
                      &lt;insertNewLine&gt;true&lt;/insertNewLine&gt;
                      &lt;output&gt;${project.build.directory}/${project.build.finalName}/scripts/all.js&lt;/output&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/json/json2.js&lt;/include&gt;
                          &lt;include&gt;**/jwplayer/jwplayer.js&lt;/include&gt;
                          &lt;include&gt;**/font/font.js&lt;/include&gt;
                          &lt;include&gt;**/underscore/underscore.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery-1.7.1.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery-ui-1.8.16.custom.min.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery.cookie.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery.fancybox.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery.highlight.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery.jcrop.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/jquery.tmpl.js&lt;/include&gt;
                          &lt;include&gt;**/jquery/farbtastic.js&lt;/include&gt;
                          &lt;include&gt;**/jscharts/jscharts.js&lt;/include&gt;
  
                          &lt;include&gt;**/myapp/homepage.js&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/aggregation&gt;
              &lt;/aggregations&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;
  </code></pre></li>
  </ol>
  
  <p>Or am I just going about my goal the wrong way? </p>
  
  <p>Here is the maven output when packaging the war. You can see that even if I tell the <code>yui:compress</code> goal to in the pre-package phase, it still occurs before the copying of the resources since this occurs in the <code>package</code> phase:</p>
  
  <pre><code>[INFO] ------------------------------------------------------------------------
  [INFO] Building My App 1.0
  [INFO] ------------------------------------------------------------------------
  Downloading: http://repo1.maven.org/maven2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
  Downloading: http://snapshots.repository.codehaus.org/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
  Downloading: http://download.java.net/maven/2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
  Downloading: http://oss.sonatype.org/content/groups/public/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml
  Downloaded: http://oss.sonatype.org/content/groups/public/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml (442 B at 2.1 KB/sec)
  Downloaded: http://repo1.maven.org/maven2/net/alchim31/maven/yuicompressor-maven-plugin/maven-metadata.xml (403 B at 0.9 KB/sec)
  [INFO] 
  [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ myapp ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] Copying 26 resources
  [INFO] Copying 4 resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myapp ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO] 
  [INFO] --- maven-compiler-plugin:2.3.2:compile (default) @ myapp ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO] 
  [INFO] --- aspectj-maven-plugin:1.3:compile (default) @ myapp ---
  [INFO] 
  [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ myapp ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] Copying 11 resources
  [INFO] 
  [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myapp ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO] 
  [INFO] --- aspectj-maven-plugin:1.3:test-compile (default) @ myapp ---
  [INFO] No modifications found skipping aspectJ compile
  [INFO] 
  [INFO] --- maven-surefire-plugin:2.6:test (default-test) @ myapp ---
  [INFO] Tests are skipped.
  [INFO] 
  [INFO] --- yuicompressor-maven-plugin:1.2:compress (default) @ myapp ---
  [INFO] 960.css (9989b) -&gt; 960.css (5897b)[59%]
  [INFO] base.css (24210b) -&gt; base.css (16437b)[67%]
  [INFO] reset.css (2062b) -&gt; reset.css (1096b)[53%]
  [INFO] text.css (1270b) -&gt; text.css (598b)[47%]
  [INFO] tinymce.css (1994b) -&gt; tinymce.css (1277b)[64%]
  [INFO] jquery.fancybox-1.3.4.css (8852b) -&gt; jquery.fancybox-1.3.4.css (6975b)[78%]
  [INFO] farbtastic.css (1362b) -&gt; farbtastic.css (478b)[35%]
  [INFO] jquery.jcrop.css (748b) -&gt; jquery.jcrop.css (582b)[77%]
  [INFO] base.css (34567b) -&gt; base.css (25034b)[72%]
  [INFO] jquery-ui-1.8.11.custom.css (33994b) -&gt; jquery-ui-1.8.11.custom.css (25351b)[74%]
  .... (tons of javascript files)
  [INFO] why.js (515b) -&gt; why.js (354b)[68%]
  [INFO] underscore.js (26960b) -&gt; underscore.js (9472b)[35%]
  [INFO] total input (1832512b) -&gt; output (1198425b)[65%]
  [INFO] generate aggregation : C:\Users\egervari\IdeaProjects\myapp-development\target\myapp-1.0\scripts\all.js
  [INFO] all.js (564342b)
  [INFO] nb warnings: 0, nb errors: 0
  [INFO] 
  [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ myapp ---
  [INFO] Packaging webapp
  [INFO] Assembling webapp [myapp] in [C:\Users\egervari\IdeaProjects\myapp-development\target\myapp-1.0]
  [INFO] Processing war project
  [INFO] Copying webapp resources [C:\Users\egervari\IdeaProjects\myapp-development\src\main\webapp]
  </code></pre>
  
  <p>Even if changing the phase did work, then I would also have to get this compression to run before <code>tomcat:run</code> as well.</p>
  
  <p>Is maven just the wrong tool for the job you think? Or is maven/java just not up-to-snuff with heavy javascript development? Why is this so hard?</p>