1

I'm using Samaxes minify maven plugin to minify js and css files. The plugin works fine in creating new files with a minifies js and css, but I'd like that the minified files will have the same name of the original files (overwriting them). So I've tried to add the nosuffix true in the pom.xml, as below:

<plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.2</version>
        <executions>
            <execution>
                <id>default-minify</id>
                <configuration>
                    <charset>UTF-8</charset>
                    <closureCompilationLevel>WHITESPACE_ONLY</closureCompilationLevel>
                    <nosuffix>true</nosuffix>
                    <skipMerge>true</skipMerge>
                    <verbose>true</verbose>
                    <yuiPreserveAllSemiColons>true</yuiPreserveAllSemiColons>
                    <webappSourceDir>${basedir}/WebContent</webappSourceDir>

                    <cssSourceDir>css</cssSourceDir>
                    <cssSourceIncludes>
                        <cssSourceInclude>**/*.css</cssSourceInclude>
                    </cssSourceIncludes>
                    <cssSourceExcludes>
                        <cssSourceExclude>**/*.min.css</cssSourceExclude>
                    </cssSourceExcludes>
                    <jsSourceDir>scripts</jsSourceDir>
                    <jsSourceIncludes>
                        <jsSourceInclude>**/*.js</jsSourceInclude>
                    </jsSourceIncludes>
                    <jsSourceExcludes>
                        <jsSourceExclude>**/*.min.js</jsSourceExclude>
                    </jsSourceExcludes>

                </configuration>
                <goals>
                    <goal>minify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

This is the plugin configuration in the pom.xml, all the options there are working fine (it identifies the sources, skips the merging, etc) but the nosuffix set to true doesn't overwrite the original files. What I don't understand is that the plugin understands perfectly the source and the destination, it even logs that it saved some space, but the output is not minified:

[INFO] Creating the minified file [/mydir/css/styles.css].
[INFO] Uncompressed size: 32490 bytes.
[INFO] Compressed size: 24188 bytes minified (5833 bytes gzipped).

What am I missing?

Rohi
  • 385
  • 6
  • 22

1 Answers1

3

Minify Maven Plugin runs during the Maven phase process-resources by default.
Since you are setting both the options nosuffix and skipMerge to true, which cause the output files to have the same path as the originals, it is causing the output files to be overridden by the source files during the phase package.

To fix this, change the plugin execution phase to package:

<plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>minify-maven-plugin</artifactId>
    <version>1.7.2</version>
    <executions>
        <execution>
            <id>default-minify</id>
            <phase>package</phase>
            <configuration>
                <!-- ... -->
            </configuration>
            <goals>
                <goal>minify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And exclude your source files from the WAR package.

Samuel Santos
  • 391
  • 1
  • 11
  • 1
    I also ran into the same problem but even after setting `package` as the phase in the plugin, the css/js files are not minimized – higuaro May 20 '15 at 20:23
  • You also need exclude your source files from the WAR package. I updated my answer above. – Samuel Santos Oct 30 '16 at 19:47