2

I want to use maven-minify plugin with YUI compressor for compressing JS and css at build time. My JS and CSS are kept in different folders. For instance. 'X' JS files are present in one folder and remaining are present in different folder. Same is the case with CSS files.

Also I want to know, how does reference of JS and CSS gets changed in JSP,if in case the file name changes from jsFileName.js to something like jsFileName-min.js

Please let me know how to use this plugin as I am completely new to this.

1 Answer 1

15

Use Samaxes plug-in, configure like this:

<plugin>
    <groupId>com.samaxes.maven</groupId>
    <artifactId>maven-minify-plugin</artifactId>
    <version>1.3.5</version>
    <executions>
        <execution>
            <id>min-js</id>
            <phase>process-resources</phase>
            <configuration>
                <cssSourceDir>relative/path/to/css/dir</cssSourceDir>
                <cssSourceFiles>
                    <cssSourceFile>subfolder1/1.css</cssSourceFile>
                    <cssSourceFile>subfolder1/3.css</cssSourceFile>
                    <cssSourceFile>subfolder2/2.css</cssSourceFile>
                </cssSourceFiles>
                <cssTargetDir>relative/path/to/final/location</cssTargetDir>
                <cssFinalFile>minified.css</cssFinalFile>

                <jsSourceDir>relative/path/to/js/dir</jsSourceDir>
                <jsSourceFiles>
                    <jsSourceFile>subfolder3/1.js</jsSourceFile>
                    <jsSourceFile>subfolder4/2.js</jsSourceFile>
                </jsSourceFiles>
                <jsFinalFile>minifiedname.js</jsFinalFile>
                <jsTargetDir>rel/path/to/final/location</jsTargetDir>
            </configuration>
            <goals>
                <goal>minify</goal>
            </goals>
        </execution>
        <!-- more execution statements -->
    </executions>                               
</plugin>
Sign up to request clarification or add additional context in comments.

3 Comments

I am trying to use your solution but I am getting the error "plugin execution not covered by lifecycle configuration" in my pom.xml. I am using Eclipse Indigo. Any thoughts?
cnage phase to compile or package <phase>package</phase>
@bhuvan If this answer solved your problem, please mark it as answered by clicking on the up-tick next to this answer. See here how. If you liked the answer, you may also up-vote by clicking on up arrow next to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.