Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yuicompressor maven plugin and maven-war-plugin

I've been struggling with getting this plugin to play nicely with the maven-war-plugin for a couple of hours now and I thought it was time to ask for help. I have the plugin defined as follows:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.0</version>
    <executions>
        <execution>
            <id>compressyui</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
            <configuration>
                <nosuffix>true</nosuffix>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <jswarn>false</jswarn>
            </configuration>
        </execution>
    </executions>
</plugin>

If I remove nosuffix=true then I can see the compressed/minified -min.js files get into the war as expected, but with this flag on they are being overwritten by the maven-war-plugin (I'm assuming) when it builds the war file. I really need the file names to remain the same though ... does anyone have an idea of what I need to change in order to use the same filenames and still get the minified versions into the final war?

like image 701
Dave Maple Avatar asked Jul 15 '12 19:07

Dave Maple


2 Answers

OK. I finally figured this out. You need to define a <webappDirectory> in the yuicompressor plugin that can then be referenced as a <resource> in the maven-war-plugin. In the example below I'm using <directory>${project.build.directory}/min</directory>

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.3.0</version>
    <executions>
        <execution>
            <id>compressyui</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
            <configuration>
                <nosuffix>true</nosuffix>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <webappDirectory>${project.build.directory}/min</webappDirectory>
                <jswarn>false</jswarn>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>default-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
            <configuration>
                <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
                <encoding>UTF-8</encoding>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
        <encoding>UTF-8</encoding>
        <webResources>
            <resource>
                <directory>${project.build.directory}/min</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>
like image 51
Dave Maple Avatar answered Sep 17 '22 12:09

Dave Maple


Just configure 'warSourceExcludes' on the WAR plugin.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
    </configuration>
</plugin>
like image 27
Thrawn Avatar answered Sep 21 '22 12:09

Thrawn