Yaven plugin for maven does not compress js files

I am using yui compressor to compress js files in my web application.

I configured the plugin as indicated on the yui maven plugin site yui plugin for the maven compressor .

This is the pom conf plugin

<plugin> <groupId>net.sf.alchim</groupId> <artifactId>yuicompressor-maven-plugin</artifactId> <version>0.7.1</version> <executions> <execution> <phase>compile</phase> <goals> <goal>jslint</goal> <goal>compress</goal> </goals> </execution> </executions> <configuration> <failOnWarning>true</failOnWarning> <nosuffix>true</nosuffix> <force>true</force> <aggregations> <aggregation> <!-- remove files after aggregation (default: false) --> <removeIncluded>false</removeIncluded> <!-- insert new line after each concatenation (default: false) --> <insertNewLine>false</insertNewLine> <output>${project.basedir}/${webcontent.dir}/js/compressedAll.js</output> <!-- files to include, path relative to output directory or absolute path--> <!--inputDir>base directory for non absolute includes, default to parent dir of output</inputDir--> <includes> <include>**/autocomplete.js</include> <include>**/calendar.js</include> <include>**/dialogs.js</include> <include>**/download.js</include> <include>**/folding.js</include> <include>**/jquery-1.4.2.min.js</include> <include>**/jquery.bgiframe.min.js</include> <include>**/jquery.loadmask.js</include> <include>**/jquery.printelement-1.1.js</include> <include>**/jquery.tablesorter.mod.js</include> <include>**/jquery.tablesorter.pager.js</include> <include>**/jquery.dialogs.plugin.js</include> <include>**/jquery.ui.autocomplete.js</include> <include>**/jquery.validate.js</include> <include>**/jquery-ui-1.8.custom.min.js</include> <include>**/languageDropdown.js</include> <include>**/messages.js</include> <include>**/print.js</include> <include>**/tables.js</include> <include>**/tabs.js</include> <include>**/uwTooltip.js</include> </includes> <!-- files to exclude, path relative to output directory--> </aggregation> </aggregations> </configuration> <dependencies> <dependency> <groupId>rhino</groupId> <artifactId>js</artifactId> <scope>compile</scope> <version>1.6R5</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>2.0.7</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> <version>2.0.7</version> <scope>provided</scope> </dependency><dependency> <groupId>net.sf.retrotranslator</groupId> <artifactId>retrotranslator-runtime</artifactId> <version>1.2.9</version> <scope>runtime</scope> </dependency> </dependencies> </plugin> 

And here is the log in compression mode

  These will use the artifact files already in the core ClassRealm instead, to allow them to be included in PluginDescriptor.getArtifacts ().

[DEBUG] Setting mojo 'net.sf.alchim: yuicompressor-maven-plugin: 0.7.1: jslint' [DEBUG] (f) failOnWarning = true [DEBUG] (f) jswarn = true [DEBUG] (f) outputDirectory = C: \ test \ target \ classes [DEBUG] (f) project = MavenProject: com.test.test1: test2: 19-SNAPSHOT @C: \ test \ pom.xml [DEBUG] (f) resources = [Resource {targetPath : null, filtering: false, FileSet {directory: C: \ test \ src, PatternSet [includes: {}, excludes: { / *. Class, ** /. Java, site /}]}}] [DEBUG] (f) sourceDirectory = C: \ test \ src .. \ js [DEBUG] (f) warSourceDirectory = C: \ test \ src \ main \ webapp [DEBUG] (f ) webappDirectory = C: \ test \ target \ test2-19-SNAPSHOT [DEBUG] - final configuration - [INFO] [yuicompressor: jslint {execution: default}] [INFO] nb warnings: 0, errors nb: 0 [DEBUG ] Setting mojo 'net.sf.alchim: yuicompressor-maven-plugin: 0.7.1: compress' β†’ [DEBUG] (f) removeIncluded = false [DEBUG] (f) insertNewLine = false [DEBUG] (f) output = C : \ test \ WebContent \ js \ compressAll.js [DEBUG] (f) includes = [ /autocomplete.js, /calendar.js , ** / dialogs.js, ** / download.js, ** / folding .js, ** / jquery-1.4.2.min.js, ** / jquery.bgifram e.min.js, ** / jquery.loadmask.js, ** / jquery.printelement-1.1.js, ** /jquery.tablesorter.mod.js, ** / jquery.tablesorter.pager.js, ** / jquery.dialogs.p lugin.js, ** / jquery.ui.autocomplete.js, ** / jquery.validate. js, ** / jquery-ui-1.8.custom .min.js, ** / languageDropdown.js, ** / messages.js, ** / print.js, * * / tables.js, ** / tabs.js, ** / uwTooltip.js] [DEBUG] (f) aggregations = [ net.sf.alchim.mojo.yuicompressor.Aggregation@65646564 ] [DEBUG] (f) disableOptimizations = false [DEBUG] (f) encoding = Cp1252 [DEBUG] (f) failOnWarning = true [DEBUG] (f) force = true [DEBUG] (f) gzip = false [DEBUG] (f) jswarn = true [DEBUG] (f) linebreakpos = 0 [DEBUG] (f) nomunge = false [DEBUG] (f) nosuffix = true [DEBUG] (f) outputDirectory = C: \ test \ target \ classes [DEBUG] (f) preserveAllSemiColons = false [DEBUG] (f) project = MavenProject: com.test.test1: test2: 19-SNAPSHOT @C: \ test \ pom.xml [DEBUG] (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: C: \ test \ src, PatternSet [includes: {}, excludes: { /. Class, /. Java, site /}]}}] [DEBUG] (f) sourceDirectory = C: \ test \ src .. \ js [DEBUG] (f) statistics = true [DEBUG] (f) suffix = -min [DEBUG] ( f) warSourceDirectory = C: \ test \ src \ main \ webapp [DEBUG] (f) webappDirectory = C: \ test \ target \ test2-19-SNAPSHOT [DEBUG] - final configuration - [INFO] [yuicompressor: compress {execute : default}] [INFO] generate aggregation: C: \ test \ WebContent \ js \ compressAll.js [INFO] compressAll.js (407505b) [INFO] nb warnings: 0, errors nb: 0 [DEBUG] Configuring mojo 'org .apache.maven.plugins: maven-resources-plugin: 2.2: testResources' β†’ [DEBUG] (f) filters = [] [DEBUG] (f) outputDirectory = C: \ test \ target \ test-classes [DEBUG] ( f) project = MavenProject: com.test.test1: test2: 19-SNAPSHOT @C: \ test \ pom.xml [DEBUG] (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: C : \ test \ test, PatternSet [includes: {}, except {/. Class, ** / *. Java}]}}] [DEBUG] - final configuration -

The problem is that the files are combined into one file, but without compression.

The link above uses version 1.1, and the plugin version that I use is 0.7.1. Will this make any difference.

Can someone say what is wrong here.

PS: I obfuscated some text in the magazine to monitor compliance at my firm. Thus, you may find that it is incompatible somewhere.

+6
maven-2 yui-compressor
source share
4 answers

From what I read, you are not setting the place where the js file should be checked or compressed (since you are not using the default configuration). You set up aggregation only.

For a quicker answer, use the yuicompressor-maven-plugin tracking questionnaire

Solution (copy / paste from the project FAQ )

Because:

  • you set <nosuffix>true</nosuffix>

  • your script in the src / main / webapp and maven-war-plugin sections copy all the files from src / main / webapp to the target (regardless of the timestamp ...) and make a war (in the same execution).

Workarounds:

  • move your script dir from webapp

     <plugin> <groupId>@ project.groupId@ </groupId> <artifactId>yuicompressor-maven-plugin</artifactId> ... <configuration> <!-- default ${project.build.sourceDirectory}/../js == src/main/js --> <sourceDirectory>src/main/javascript</sourceDirectory> 
  • OR exclude "scripts" from the list of files to copy

     <!-- adapted from https://github.com/davidB/yuicompressor-maven-plugin/blob/master/src/it/demo01/pom.xml --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <warSourceExcludes>scripts/**</warSourceExcludes> </configuration> </plugin> 
+5
source share

I know this post is very old, but I came across the same thing, and this is what I found. Hope this helps another.

It's complicated. This is due to the nosuffix configuration option. If you remove the nosuffix option, minimization will work as expected.

If you really need nosuffix, you need to change the execution phase to "package".

  <executions> <execution> <phase>package</phase> <goals> ...... ..... 

Any phase before preparing the resources does not work, because when the war is built, it picks up js from the source source location and thereby overwrites mini-js (created during the preparation-resources stage) in the target directory.

Minimization works when you delete nosuffix because the file names are different during the batch phase, so there is no file rewriting, and you will see both mini and non-minified js files in your target directory.

At least my understanding.

+2
source share

Can you try defining a separate execution for jslint and compress and see if this works?

 <executions> <execution> <goals> <goal>jslint</goal> </goals> <configuration> ... </configuration> </execution> <execution> <goals> <goal>compress</goal> </goals> <configuration> ... </configuration> </execution> </executions> 
0
source share

The YUI compressor (included as a dependency in this maven plugin) uses the β€œfixed” version of Mozilla Rhino for

:
  • javascript interpretation
  • compression of local variable names ("patch")

Having added a dependency on Rhino ( in your previous question ), I think that these β€œpatches” were overwritten, turning this maven plugin into something useless: the name compression, the erasure of the spaces disappeared.

So, remove the rhino from your pomp and go back to solving the first problem!

0
source share

All Articles