3

I am using Eclipse Indigo with M2E to deploy a local web app using WTP. I am also using the yui-compressor plugin, which seems to work fine on the exploded war directory under target, but doesn't work with eclipse WTP. Is there a recommended way to set this up so I can develop locally and use the minified files?

Here is my yui config:

<plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.3.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
                <force>true</force>
                <jswarn>false</jswarn>
                <linebreakpos>-1</linebreakpos>
                <excludes>
                    <exclude>**/lib/*</exclude>
                </excludes>
                <aggregations>
                    <aggregation>
                        <insertNewLine>true</insertNewLine>
                        <output>${project.build.directory}/${project.build.finalName}/static/js/script-${timestamp}.min.js</output>
                        <includes>
                            <include>**/script/*.js</include>
                        </includes>
                        <excludes>
                            <exclude>**/lib/*</exclude>
                        </excludes>
                    </aggregation>
                </aggregations>
            </configuration>
        </plugin>

<pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>net.alchim31.maven</groupId>
                                    <artifactId>yuicompressor-maven-plugin</artifactId>
                                    <versionRange>[1.2,)</versionRange>
                                    <goals>
                                        <goal>compress</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
ant-depalma
  • 2,006
  • 4
  • 26
  • 34

2 Answers2

1

Did you try <runOnIncremental>true</runOnIncremental>?

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>net.alchim31.maven</groupId>
                                <artifactId>yuicompressor-maven-plugin</artifactId>
                                <versionRange>[1.3.0,)</versionRange>
                                <goals>
                                    <goal>compress</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <execute>
                                    <runOnIncremental>true</runOnIncremental>
                                </execute>
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

To have M2E output the files into the /src/ directory rather than the /target/ directory, I use the following:

<plugins>
    <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <version>1.3.0</version>
        <executions>
            <execution>
                <goals>
                    <goal>compress</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <sourceDirectory>${project.basedir}/src/main/webapp/resources/js</sourceDirectory>
            <outputDirectory>${project.basedir}/src/main/webapp/resources/js-min</outputDirectory>
        </configuration>
    </plugin>
</plugins>

In my HTML I then reference the JavaScript file(s) in [...]/resources/js-min/.

Jack
  • 1,881
  • 24
  • 29
1

The problem, I think, is that you are not telling to maven-war-plugin where to find generated resources.

You should try to add webResources section to the maven-war-plugin configuration, e.g.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <webResources>
        <resource>
          <filtering>true</filtering>
          <directory>${basedir}/src/main/webapp</directory>
          <excludes>
            <exclude>**/pattern-for-non-minified-scripts</exclude>
          </excludes>
        </resource>
        <resource>
          <filtering>true</filtering>
          <directory>${project.build.directory}/${project.build.finalName}</directory>
          <includes>
            <include>static/js/script-${timestamp}.min.js</include>
          </includes>
        </resource>
      </webResources>
    </configuration>
  </plugin>

To see that WTP has picked up the minified files, check .settings/org.eclipse.wst.common.component file has the following line:

    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
Alexander Pogrebnyak
  • 44,836
  • 10
  • 105
  • 121
  • Thanks, after doing this I can see that the resources are put in the web-resources folder and minified. However it seems I can't have this done incrementally..Even though the yui plugin can run after any resources are saved, the changes arent pushed to the web-resources folder unless I do a build again. Is there any way around this so I can use it with WTP? – ant-depalma Apr 01 '12 at 17:51