excluding vendor js files from jslint goal but not the compress goal in yuicompressor-maven-plugin - maven

I have some third party js files in my project that I would like to minify during deployment, but I don't want to see the jslint warnings on those particular js files. How would I achieve this?
When I list both goals and exclude the js in the configuration, even the compress goal excludes them, as expected.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
<goal>jslint</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<webappDirectory>${project.build.directory}/min</webappDirectory>
<excludes>
<exclude>**/*min.js</exclude>
<exclude>**/*min.css</exclude>
<exclude>**/ZeroClipboard.js</exclude>
<exclude>**/TableTools.js</exclude>
<exclude>**/jquery.dataTables.rowGrouping.js</exclude>
</excludes>
</configuration>
</plugin>
But even when I put the configuration in the individual executions, jslint still shows me errors from the excluded js files.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<id>minify</id>
<phase>package</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>jslint</id>
<phase>package</phase>
<goals>
<goal>jslint</goal>
</goals>
<configuration>
<excludes>
<exclude>**/ZeroClipboard.js</exclude>
<exclude>**/TableTools.js</exclude>
<exclude>**/jquery.dataTables.rowGrouping.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
</configuration>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
</configuration>
</plugin>
The above plugin configuration still shows jslint errors from the 3 listed js files. How do I avoid that?
Since they are 3rd party, I am not interested in fixing their jslint errors/warnings, but I'd still like them minified for my deployment purposes.

Found it here : http://alchim.sourceforge.net/yuicompressor-maven-plugin/usage_jslint.html
I could make it work having <configuration> under <plugin> not inside an <execution>

Related

How to provide different set of properties to the different executions of a plugin?

I am using maven-assembly-plugin to assemble different artifacts as following:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>configuration-staging</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>configuration-production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
In assembly.xml, I enabled template filtering:
<fileSets>
<fileSet>
<filtered>true</filtered>
This works great. For example, if I enter ${name} in one of the resources to be assembled, this is replaced by the name of the project. I could also define properties in pom.xml, which will be replaced by the plugin.
Now, I would like to have different properties for each execution of maven-assembly-plugin. For example, I would like to introduce a ${url} which holds the URL to be used on the target environment (staging and production in the example above).
Is this possible? How?
Apparently, it is possible to pass different properties for each execution in the maven-assembly-plugin as following:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>configuration-staging</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>staging</finalName>
<filters>
<filter>src/main/assembly/staging.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>configuration-production</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>production</finalName>
<filters>
<filter>src/main/assembly/production.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Although this does not answer the generic question, it answers the question specifically for maven-assembly-plugin.
More can be found on https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html.
You can try with the properties Maven plugin
https://www.mojohaus.org/properties-maven-plugin/index.html
that allows you read properties from files or URLs.

How can I use Maven fail safe plugin to execute the pre-integration steps

I need to execute a testNG (config) test before the regression suite. This test does some config related tasks and creates users. Can somebody please explain the following POM. I am still trying to understand how to define the step in the POM.xml. The name of my test is CreateUsers.xml. Where should I define this in the following POM.XML. I am using jenkins to run these tests. Please advice. Thanks
What does id, goal and include tags mean ?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>pre-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/PreTest.class</include>
</includes>
</configuration>
</execution>
<execution>
<id>int-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/IntTest.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have added my per-requisite testNG as below. Please advice if this is correct ? Thanks
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<type>maven-plugin</type>
<executions>
<execution>
<id>pre-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>CreateUsers.xml</include>
</includes>
</configuration>
</execution>
</executions>

Compressing selected js folder using yui compressor in Maven

I am trying to compress only js in selected folder in my webapp(impl/amss9/widgets) directory using following code
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<includes>
<include>${amss.webapp.dir}/impl/amss9/widgets/**/*.js</include>
</includes>
</configuration>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
The above code is not compressing anything.
If I remove includes tag then it is compressing all the js of my webapp dir.
I am not understanding what is going wrong.
this part:
<includes>
<include>${amss.webapp.dir}/impl/amss9/widgets/**/*.js</include>
</includes>
will not help you. Instead, you have to use something like this:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<gzip>true</gzip>
<nosuffix>true</nosuffix>
<sourceDirectory>app/assets/javascripts</sourceDirectory>
<outputDirectory>${basedir}/public/javascripts</outputDirectory>
<aggregations>
<aggregation>
<removeIncluded>true</removeIncluded>
<insertNewLine>false</insertNewLine>
<output>${basedir}/public/javascripts/application.js</output>
<inputDir>${basedir}/public/javascripts/</inputDir>
<includes>
<include>jquery-1.7.1.min.js</include>
<include>arborjs/arbor.js</include>
<include>arborjs/arbor-graphics.js</include>
<include>bootstrap.min.js</include>
<include>application.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>

Build multiple artifacts with different classifiers at once

W want my maven project to produce three artifacts with different classifiers at once. I know that I can produce it with modules etc. This is actually a resources project that I want to produce configuration for DEV, STAGE and PROD environment.
What I want to have is to run mvn:install once and have my.group:resources:1.0:dev, my.group:resources:1.0:stage and my.group:resources:1.0:prod in my repo.
This can be done without profiles if you specify multiple plugin executions and resource filtering.
Create a properties file for each version in ${basedir}/src/main/filters (e.g. prod.properties, dev.properties) holding appropriate values for each environment.
Turn on filtering for your resources:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Now add the resource plugin executions. Note the different filter file and output directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/dev</outputDirectory>
<filters>
<filter>${basedir}/src/main/filters/dev.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>prod</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/prod</outputDirectory>
<filters>
<filter>${basedir}/src/main/filters/prod.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Finally, the jar plugin; note classifier and input directory:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dev</classifier>
<classesDirectory>${project.build.outputDirectory}/dev</classesDirectory>
</configuration>
</execution>
<execution>
<id>jar-prod</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>prod</classifier>
<classesDirectory>${project.build.outputDirectory}/prod</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
Running mvn clean install should produce the properly filtered resources in artifacts with dev and prod classifiers like you want.
In the example, I used execution IDs of default-resources and default-jar for the dev versions. Without this you would also get an unclassified jar artifact when you build.
Just an FYI - put the version number in there to make sure you have the version supporting custom filters. In maven 3 I set mine up like this for example. Without version it didn't work.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
...
</plugin>

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?
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>
Just configure 'warSourceExcludes' on the WAR plugin.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
</configuration>
</plugin>
I would like to add the configuration which worked for me:
First, to fix m2e complaining about the 'Plugin execution not covered by lifecycle' I added the following in the parent pom taken from this post:
<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.0.0,)</versionRange>
<goals>
<goal>compress</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Then in the war pom I put:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<linebreakpos>300</linebreakpos>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<nosuffix>true</nosuffix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
This generates the minified css and js files in the project build target directory while excluding the original files.
I hope this saves someone time.
this is my configuration, and it works fine in my maven web project:
<!-- js/css compress -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<jswarn>false</jswarn>
<nosuffix>true</nosuffix>
</configuration>
<executions>
<execution>
<id>compress_js_css</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/${project.build.finalName}/resources</directory>
<targetPath>/resources</targetPath>
<filtering>false</filtering>
</resource>
</webResources>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
The approach I use is a bit different.
First, I've configured my IDE to run mvn process-resources before the compilation/packaging. This way the files are created before the war is assembled.
It is very important to set <nosuffix>false</nosuffix> and <outputDirectory>${basedir}/src/main/resources/</outputDirectory> so the files can be created in the same directory without replacing your original source files.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<preProcessAggregates>false</preProcessAggregates>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<jswarn>false</jswarn>
<nosuffix>false</nosuffix> <!-- VERY IMPORTANT WILL REPLACE YOUR FILES IF YOU SET nosuffix TO TRUE OR DONT SET IT AT ALL -->
<outputDirectory>${basedir}/src/main/resources/</outputDirectory> <!-- by default the plugin will copy the minimized version to target directory -->
<failOnWarning>false</failOnWarning>
</configuration>
<executions>
<execution>
<id>compress_js_css</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
As Jakob Kruse say, you must deal with the *.js, but no *.min.js, so my configurations is below, please notice the use of %regex[] :
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.4.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>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
<exclude>**/jquery.window.js</exclude>
......
<exclude>**/compile.js</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<packagingExcludes>servlet-api*.jar,target/test-classes/*</packagingExcludes>
<warSourceExcludes>test/**,%regex[.*(!min).js],%regex[.*(!min).css]</warSourceExcludes>
<webResources>
<resource>
<directory>${project.build.directory}/min</directory>
</resource>
</webResources>
</configuration>
</plugin>
Without pom.xml change
mvn net.alchim31.maven:yuicompressor-maven-plugin:compress
To force compress every js and css files and fail if warning
mvn net.alchim31.maven:yuicompressor-maven-plugin:compress \
-Dmaven.yuicompressor.force=true \
-Dmaven.yuicompressor.failOnWarning=true \
For more options:
http://davidb.github.io/yuicompressor-maven-plugin/usage_compress.html

Resources