title: How to minify a filtered javascript file using maven?
body: <p>I have a javascript file that is used to track events using Google analytics. I have created different accounts for the staging and production environment. The script to invoke GA code has a place holder for my account Id. The account Ids have been specified in the filter files. Using the webResources element in the maven-war plugin, we are able to successfully replace the property in the final WAR file.</p>
  
  <p>Now, we are also using maven-yuicompressor plugin to minify and aggregate all our javascript files. The problem is that if I attach the execution of minify goal to the package phase, the WAR is created before the Javascript has been minified. If I attach the minify goal to anything earlier, the filter has been not applied till the time of minification producing an invalid file.</p>
  
  <p>So, I am looking for a way to run the minify goal between the WAR plugin copying the filtered JS files and creating the WAR file. Here are the relevant portions of my pom.xml:</p>
  
  <pre><code>          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1.1&lt;/version&gt;
              &lt;configuration&gt;
                &lt;webResources&gt;
                  &lt;resource&gt;
                    &lt;directory&gt;src/main/webapp/js&lt;/directory&gt;
                    &lt;targetPath&gt;js&lt;/targetPath&gt;
                    &lt;filtering&gt;true&lt;/filtering&gt;
                  &lt;/resource&gt;
                &lt;/webResources&gt;
              &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
              &lt;groupId&gt;net.alchim31.maven&lt;/groupId&gt;
              &lt;artifactId&gt;yuicompressor-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.1&lt;/version&gt;
              &lt;executions&gt;
                &lt;execution&gt;
                  &lt;goals&gt;
                    &lt;goal&gt;compress&lt;/goal&gt;
                  &lt;/goals&gt;
                  &lt;phase&gt;package&lt;/phase&gt;
                &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                &lt;linebreakpos&gt;-1&lt;/linebreakpos&gt;
                &lt;nosuffix&gt;true&lt;/nosuffix&gt;
                &lt;force&gt;true&lt;/force&gt;
                &lt;aggregations&gt;
                  &lt;aggregation&gt;
                    &lt;output&gt;${project.build.directory}/${project.build.finalName}/js/mysite-min.js&lt;/output&gt;
                    &lt;inputDir&gt;${project.build.directory}/${project.build.finalName}/js&lt;/inputDir&gt;
                    &lt;includes&gt;
                      &lt;include&gt;jquery-1.4.2.js&lt;/include&gt;
                      &lt;include&gt;jquery-ui.min.js&lt;/include&gt;
                      &lt;include&gt;ga-invoker.js&lt;/include&gt;
                    &lt;/includes&gt;
                  &lt;/aggregation&gt;
                &lt;/aggregations&gt;
              &lt;/configuration&gt;
            &lt;/plugin&gt;
  </code></pre>