Recently,
we've decided to migrate to Eclipse Indigo and uses m2e 1.0.
But, we have problems trying to tackle the lifecycle mapping problem.
As I understood, we have to define in pom.xml lifecycle mapping metadata to
instruct Eclipse which executions should be executed when sources are
changed.

In our WAR project, we want to write many small javascript source files and
these files would be merged in an unique file (minified or not). For this
task, we've planned to use yuicompressor-maven-plugin.
I didn't find too many docs instructing how to develop a connector for this
plugin. Just found an example inside m2e-core sources defining a lyfecicle
mapping metadata to instruct m2e to ignore the execution of this plugin.
However, we would want to use and reference the merged file while deploying
the artifact using Eclipse WTP.

The solution (I found googling) looks like to be instruct the plugin to
generate the merged javascript file inside m2e-wtp/web-resources/ directory.
So, we have to define two executions for this plugin. One to generate the
merged file inside target (to be packaged) by maven (yuicompressor-default
execution id) another to generate the merged file inside
m2e-wtp/web-resources/ directory(yuicompressor-
eclipse execution id).
The second step would be to create the lifecycle metadata to instruct the
execution of the plugin that generates the merged file inside
m2e-wtp/web-resources.
One problem in this approach is that for each source file changed, both
yuicompressor-maven-plugin are executed since we didn't find a way to ignore
just the yuicompressor-default execution.

Here I present my pom.xml relevant sections:
Metadata filecycle mapping:

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e
settings only. It has no influence on the Maven build itself.-->
                <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>
                                        <id>yuicompressor-eclipse</id>
                                        <goals>
                                            <goal>compress</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute></execute>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>




Yui Compreessor maven Plugin configuration

        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <id>yuicompressor-default</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <aggregations>
                                <aggregation>
                                    <!-- remove files after aggregation
(default: false) <removeIncluded>true</removeIncluded> -->
                                    <!-- insert new line after each
concatenation (default: false) -->
                                    <insertNewLine>true</insertNewLine>

<output>${project.build.directory}/${project.build.finalName}/resources/js/0_1_2/script.js</output>
                                    <!-- base directory for non absolute
includes, default to parent dir of output -->

<inputDir>${basedir}/src/main/webapp/resources/js/0_1_2</inputDir>
                                    <!-- files to include, path relative to
output's directory or absolute path -->
                                    <includes>
                                        <include>file1.js</include>
                                        <include>file2.js</include>
                                        <include>file3.js</include>
                                        <include>file4.js</include>
                                        <include>file5.js</include>
                                        <include>file6.js</include>
                                        <include>file7.js</include>
                                    </includes>
                                    <!-- files to exclude, path relative to
output's directory <excludes> <exclude>**/*.pack.js</exclude>
<exclude>**/compressed.css</exclude>
                                        </excludes> -->
                                </aggregation>
                                <aggregation>
                                    <!-- remove files after aggregation
(default: false) <removeIncluded>true</removeIncluded> -->
                                    <!-- insert new line after each
concatenation (default: false) -->
                                    <insertNewLine>true</insertNewLine>

<output>${project.build.directory}/${project.build.finalName}/resources/js/0_1_2/script-min.js</output>
                                    <!-- base directory for non absolute
includes, default to parent dir of output -->

<inputDir>${project.build.directory}/${project.build.finalName}/resources/js/0_1_2</inputDir>
                                    <!-- files to include, path relative to
output's directory or absolute path -->
                                    <includes>
                                        <include>file1-min.js</include>
                                        <include>file2-min.js</include>
                                        <include>file3-min.js</include>
                                        <include>file4-min.js</include>
                                        <include>file5-min.js</include>
                                        <include>file6-min.js</include>
                                        <include>file7-min.js</include>
                                    </includes>
                                    <!-- files to exclude, path relative to
output's directory <excludes> <exclude>**/*.pack.js</exclude>
<exclude>**/compressed.css</exclude>
                                        </excludes> -->
                                </aggregation>
                            </aggregations>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yuicompressor-eclipse</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <aggregations>
                                <aggregation>
                                    <!-- remove files after aggregation
(default: false) <removeIncluded>true</removeIncluded> -->
                                    <!-- insert new line after each
concatenation (default: false) -->
                                    <insertNewLine>true</insertNewLine>

<output>${project.build.directory}/m2e-wtp/web-resources/resources/js/0_1_2/script.js</output>

                                    <!-- base directory for non absolute
includes, default to parent dir of output -->

<inputDir>${basedir}/src/main/webapp/resources/js/0_1_2</inputDir>
                                    <!-- files to include, path relative to
output's directory or absolute path -->
                                    <includes>
                                        <include>file1-min.js</include>
                                        <include>file2-min.js</include>
                                        <include>file3-min.js</include>
                                        <include>file4-min.js</include>
                                        <include>file5-min.js</include>
                                        <include>file6-min.js</include>
                                        <include>file7-min.js</include>
                                    </includes>
                                    <!-- files to exclude, path relative to
output's directory <excludes> <exclude>**/*.pack.js</exclude>
<exclude>**/compressed.css</exclude>
                                        </excludes> -->
                                </aggregation>
                                <aggregation>
                                    <!-- remove files after aggregation
(default: false) <removeIncluded>true</removeIncluded> -->
                                    <!-- insert new line after each
concatenation (default: false) -->
                                    <insertNewLine>true</insertNewLine>

<output>${project.build.directory}/m2e-wtp/web-resources/resources/js/0_1_2/script-min.js</output>
                                    <!-- base directory for non absolute
includes, default to parent dir of output -->

<inputDir>${project.build.directory}/${project.build.finalName}/resources/js/0_1_2</inputDir>
                                    <!-- files to include, path relative to
output's directory or absolute path -->
                                    <includes>
                                        <include>file1-min.js</include>
                                        <include>file2-min.js</include>
                                        <include>file3-min.js</include>
                                        <include>file4-min.js</include>
                                        <include>file5-min.js</include>
                                        <include>file6-min.js</include>
                                        <include>file7-min.js</include>
                                    </includes>
                                    <!-- files to exclude, path relative to
output's directory <excludes> <exclude>**/*.pack.js</exclude>
<exclude>**/compressed.css</exclude>
                                        </excludes> -->
                                </aggregation>
                            </aggregations>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <!-- <disableOptimizations>false</disableOptimizations>
-->

                    <!-- <encoding></encoding> -->
                    <!-- <failOnWarning>true</failOnWarning> -->
                    <!-- Zip the files. Defaults to false -->
                    <!-- <gzip>true</gzip> -->
                    <!-- force the compression of every files, else if
compressed file already exists and is younger than source file, nothing is
done. -->
                    <!-- <force>true</force> -->
                    <!-- Unable JavaScript warnings  -->
                    <jswarn>false</jswarn>
                </configuration>
            </plugin>
        </plugins>


Is there another better way to integrate merging and minifying javascript or
css files inside m2e lifecycle deploying phase?


Best regards,
Orair.
_______________________________________________
m2e-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/m2e-users

Reply via email to