Clover failing with "No Clover database found, skipping report generation" - maven

I'm trying to add Clover to my maven (groovy) project in order to get some code coverage results. However it fails to generate the code coverage report.
The report is just empty.
My src files are located in src/main/groovy and my tests are located in src/test/groovy
When I run:
mvn clean clover:setup test clover:instrument clover:aggregate clover:clover
Build log:
[INFO] No Clover instrumentation done on source files in: [/home/xxx/workspace/yyy/src/main/java, /home/xxx/workspace/yyy/target/generated-sources/groovy-stubs/main] as no matching sources files found (JAVA_LANGUAGE)
[INFO] No Clover instrumentation done on source files in: [/home/xxx/workspace/yyy/src/test/java, /home/xxx/workspace/yyy/src/test/groovy] as no matching sources files found (JAVA_LANGUAGE)
...
[WARNING] No Clover database found, skipping report generation
[INFO] No report being generated for this module.
...
And indeed if I look in my tree for any database file,
My pom.xml:
....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<AlwaysPass />
</rules>
<fail>true</fail>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-test-resources</id>
<phase>validate</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}</directory>
<filtering>true</filtering>
<includes>
<include>src/**/*.*</include>
<include>vars/**/*.*</include>
<include>resources/**/*.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- clover -->
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.2.0</version>
</plugin>
<!-- Tests -->
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>
<directory>${project.basedir}/src</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
<testSources>
<source>
<directory>${project.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</testSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<failIfNoTests>true</failIfNoTests>
<includes>
<include>**/*</include>
</includes>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.2.0</version>
</plugin>
</plugins>
</reporting>
</project>

Related

Preparing Tests for upload into Appcenter does not include src classfiles

I hope someone can help. When I am trying to prepare my tests to upload into appcenter for mobile testing, the command they tell me to use to prepare the upload does not include the src class files for my tests. It only adds the test class files that are specified in the "prepare-for-upload" section in the pom file.
when I upload and run the tests, it complains that it can not find the class files in classes.
I think that is because it isn't in the upload folder.
All the things I have tried still only leaves me with the following folders and files
This is all new to me so I have read so much without success.
I have tried to add the resources to the pom.xml and it still does not package them correctly.
I added this section to the pom file in the same tag as the Appcenter stuff.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
I tried the following as well to see if I can copy the resources over.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This is my section that is meant for appcenter:
<profiles>
<profile>
<id>prepare-for-upload</id>
<build>
<plugins>
<!-- Owen Added-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
/Users/owensieber/Projects/mobileautomation/target/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/dependency-jars/</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
<addParentPoms>true</addParentPoms>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-pom</id>
<phase>package</phase>
<goals>
<goal>effective-pom</goal>
</goals>
<configuration>
<output>${project.build.directory}/upload/pom.xml</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-testclasses</id>
<phase>package</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/test-classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.testOutputDirectory}
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Exclude log4j.properties in the generated jar

I am using maven-compiler-plugin to build a JAR from one of my module, and I am not able to exclude log4j.properties from the generated JAR.
I tried:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>8</source>
<target>8</target>
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
But this does not work. I can exclude the file globally:
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</resource>
</resources>
But I don't want to do this as this impact the Eclipse build, and makes it impossible to run code from Eclipse that uses log4j.
I tried to see if the included log4j.properties was mine and not from another module, and it is mine. I've read numerous posts on the issue, including some here, but I still cannot solve it...
If this matters, this module is a submodule of a parent package, with the following <build>:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
<executions>
<execution>
<id>create-javadoc</id>
<phase>javadoc</phase>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>

Maven plugins via profile are not executed in specified phase

My requirement to execute testng.xml file to run the automation scripts and send the mail once execution is completed. I'll define like what tests to run from testng.xml file.
So I've decided to use maven profiles concept for running the testng.xml file and for sending execution reports as below. When i run the command using
"mvn test -P Code_Compile,Run_Tests,Mail_Reports", below mentioned profiles are not executed. Please let me know what I'm missing here.
<profiles>
<profile>
<id>Code_Compile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>codecompile</id>
<phase>test</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>Run_Tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>runtests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>Mail_Reports</id>
<build>
<plugins>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.6</version>
<executions>
<execution>
<id>send a mail</id>
<phase>test</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>false</inherited>
<configuration>
<from>xx#gmail.com</from>
<subject>Latest Automation Report...</subject>
<failonerror>true</failonerror>
<mailhost>smtp.gmail.com</mailhost>
<mailport>465</mailport>
<mailssl>true</mailssl>
<mailAltConfig>true</mailAltConfig>
<mailuser>xx#gmail.com</mailuser>
<mailpassword>xxxxx</mailpassword>
<htmlMessage><![CDATA[<p>Hi, Please find enclosed latest Automation reports.</p>]]></htmlMessage>
<receivers>
<receiver>xxxx#gmail.com</receiver>
</receivers>
<fileSets>
<fileSet>
<directory>${basedir}/TestReports</directory>
<includes>
<include>LatestAutomationReport.zip</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I've tried to include only plugins inside build tag instead of profiles by setting the phase as "test" for each plugin as shown below and tried to run "mvn test" command.As you can see below I've included test in each plugin.This try also didn't pick the execution of plugins. Please help me in solving this problem either via profiles or via plugins.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>codecompile</id>
<phase>test</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<id>runtests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.6</version>
<executions>
<execution>
<id>send a mail</id>
<phase>test</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>false</inherited>
<configuration>
<from>vikascool4#gmail.com</from>
<subject>Latest Automation Report...</subject>
<failonerror>true</failonerror>
<mailhost>smtp.gmail.com</mailhost>
<mailport>465</mailport>
<mailssl>true</mailssl>
<mailAltConfig>true</mailAltConfig>
<mailuser>vikascool4#gmail.com</mailuser>
<mailpassword>vikaschinna</mailpassword>
<htmlMessage><![CDATA[<p>Hi, Please find enclosed latest Automation reports.</p>]]></htmlMessage>
<receivers>
<receiver>vikas.voladri#gmail.com</receiver>
</receivers>
<fileSets>
<fileSet>
<directory>${basedir}/TestReports</directory>
<includes>
<include>LatestAutomationReport.zip</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
If you run mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:1.3:list -P Code_Compile,Run_Tests,Mail_Reportsthis will output the plugins maven is executing and their execution ids, You might see from the output of the command that your executions are probably not overriding the default executions (as these have different ids).
Instead of defining your Code_Compile profile use the default properties defined here: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
Also if you want to use a specific version of the compiler use pluginManagement to define that.

Maven enforcer append in children

I am using the maven enforcer plugin. Given I have a parent and child pom.xml, I would like that the elements in the exclusions and inclusions tags are appended rather than overridden. I have tried using combine.children="append" for this and it works but I am ending up with an extra configuration tag. Am I using combine.children incorrectly and/or how can I avoid the extra configuration tag? See the example below:
In parent pom.xml:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.apache.maven</exclude>
<exclude>org.apache.maven:badArtifact</exclude>
<exclude>*:badArtifact</exclude>
</excludes>
<includes>
<!--only 1.0 of badArtifact is allowed-->
<include>org.apache.maven:badArtifact:1.0</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
In child pom.xml:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<configuration>
<rules>
<bannedDependencies>
<includes combine.children="append">
<include>org.apache.maven:otherArtifact:2.0</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
Expected effective POM:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.apache.maven</exclude>
<exclude>org.apache.maven:badArtifact</exclude>
<exclude>*:badArtifact</exclude>
</excludes>
<includes>
<!--only 1.0 of badArtifact is allowed-->
<include>org.apache.maven:badArtifact:1.0</include>
<include>org.apache.maven:otherArtifact:2.0</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
Actual effective POM:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.apache.maven</exclude>
<exclude>org.apache.maven:badArtifact</exclude>
<exclude>*:badArtifact</exclude>
</excludes>
<includes combine.children="append>
<!--only 1.0 of badArtifact is allowed-->
<include>org.apache.maven:badArtifact:1.0</include>
<include>org.apache.maven:otherArtifact:2.0</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
<configuration>
<rules>
<bannedDependencies>
<includes combine.children="append">
<include>org.apache.maven:otherArtifact:2.0</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
If you really want to get the expected merged configuration you should then have in your child module the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>org.apache.maven:badArtifact:2.0</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
That is, reusing the same execution id value in order to point (override/merge) the same execution with additional configuration.
Then the merged effective pom will be as following:
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes combine.children="append">
<include>org.apache.maven:badArtifact:1.0</include>
<include>org.apache.maven:badArtifact:2.0</include>
</includes>
<excludes>
<exclude>org.apache.maven</exclude>
<exclude>org.apache.maven:badArtifact</exclude>
<exclude>*:badArtifact</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Hence, no need to use it: the default merging behavior will suit your needs.
One important note about the usage of combine.* attributes, from official documentation
Note that these attributes only apply to the configuration element they are declared on, and are not propagated to nested elements. That is if the content of an item element from the child POM was a complex structure instead of text, its sub-elements would still be subject to the default merge strategy unless they were themselves marked with attributes.

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