yuicompressor maven is not working - maven

I am working in Spring boot web application with maven build. I want to compress all js & css files. I have chosen YUI compression. When I build my application yui compression not happened. I am getting following message for all js & css files.
[INFO] nothing to do, **css\base.css is younger than original, use 'force' option or clean your target
What I am missing ?
Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyApp</groupId>
<artifactId>MyApp</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<!-- <url>http://maven.apache.org</url> -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
my dependencies
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
</configuration>
</plugin>
</plugins>
</build>
</project>
Project structure :

It's not an error and works as expected. The plugin creates a minified version of the resource only when it's minified version doesn't exist or when source file has been changed. When plugin found that minified version was created later than source file, it doesn't do minification and assumes that nothing to be done.
As you can see, message suggests you to use force option (in this case, minified version will be always generated but it will be slower) or clean the target (execute mvn clean to remove all generated files so they will be generated again).
UPDATED:
I was able to reproduce the issue. It happens because yuicompressor-maven-plugin is being executed after maven-resource-plugin. The former was copied all the files from src/main/resources to the target directory and when yuicompressor was being executed, it found that the files already here (non-minified of course) and show this message.
To fix this, first, we need to configure resource plugin to exclude resources:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources/public</directory>
<excludes>
<exclude>*.js</exclude>
<exclude>*/*.js</exclude>
</excludes>
</resource>
</resources>
</build>
But it didn't solve it because after that I found that yuicompressor doesn't process these files. This is because the plugin was looking in the wrong directory and we have to configure it also:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
...
<configuration>
<nosuffix>true</nosuffix>
<sourceDirectory>src/main/resources/public</sourceDirectory>
</configuration>
</plugin>

Use -Dmaven.clean.failOnError=false to mvn command.
example: mvn clean -Dmaven.clean.failOnError=false

Just by adding Force option I resolved this issue:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<force>true</force>
<sourceDirectory>src/main/resources/static</sourceDirectory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
</configuration>
</plugin>

Related

Checkstyle not working in build or verify phase

I cannot get maven checkstyle to run on build or verify, despite copy & pasting the code directly from the checkstyle website.
I can see checkstyle working fine and finding problems when running mvn checkstyle:check, but not on any phase like clean compile verify. These phases just compile fine and find no problems, completely ignoring checkstyle. I set up a minimal example here. The pom.xml is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>checkstyle-test</groupId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>15</java.version>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<version>0.0.2</version>
<packaging>jar</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
You need to bind Checkstyle execution to the verify phase, like this:
...
<execution>
<id>checkstyle-check</id>
<phase>verify</phase>
<configuration>
<sourceDirectories>${project.build.sourceDirectory}</sourceDirectories>
<configLocation>config/checkstyle_checks.xml</configLocation>
<encoding>UTF-8</encoding>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
...
This snippet is taken from one of my projects, you can view the entire pom.xml here.
Figured it out: I had the block in <pluginManagement>. Moving it out of there it instantly worked. I wished, maven would have more complete example on their website.

Inconsistent behaviour between maven-surefire and tycho-surefire, with jacoco not generating reports

I'm working on creating a pom for a project and adding test cases to it. The project is an eclipse plugin.
Compiling the project with tycho works just fine, the only problem is during testing:
If I run both maven-surefire-plugin tests and tycho-surefire-plugin-tests, the former performs all the tests as expected, while the latter gives the following error:
Execution test of goal org.eclipse.tycho:tycho-surefire-plugin:1.7.0:test failed: Tycho build extension not configured for MavenProject
I would be perfectly fine to just add <skipTests>true</skipTests> to the tycho-surefire-plugin while keeping maven-surefire-plugin on; the problem is even that way, jacoco refuses to create the coverage site, with the following (non error) message:
Skipping JaCoCo execution due to missing execution data file.
I tried to look for solutions of both, but any combination of the solutions I found doesn't lead me to having a working coverage site.
Maven really makes me quite confused, especially with tycho around, so I'd apreciate any explanation on top of the actual fix.
Here is my pom:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupid</groupId>
<artifactId>myartifactid</artifactId>
<name>myname</name>
<packaging>eclipse-test-plugin</packaging>
<properties>
<tycho-version>1.7.0</tycho-version>
</properties>
<parent>
<groupId>parentgroupid</groupId>
<artifactId>parent</artifactId>
<version>0.9.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/java/</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<configuration>
<includes>
<include>**/Test_*.java</include>
</includes>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<configuration>
<includes>
<include>**/Test_*.java</include>
</includes>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<configuration>
<output>file</output>
<append>true</append>
<includes>
<include>**/path_to_source/**/*</include>
</includes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>compiletests</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And here is my parent pom:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>parentgroupid</groupId>
<artifactId>parent</artifactId>
<version>0.9.5</version>
<packaging>pom</packaging>
<modules>
<module>moduleid</module>
</modules>
<properties>
<tycho-version>1.7.0</tycho-version>
</properties>
<repositories>
<repository>
<id>eclipse-2020-06</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/2020-06</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>
</plugins>
</build>
</project>
Of course there won't be any test result for the JaCoCo due to you are using very old Surefire version 2.12.4. This version was not created for JUnit5.
Use the latest version 3.0.0-M5 and see the tutorial.
If you want to have tiny POM, remove the dependency junit-jupiter-engine due to you do not need to have an access to the JUnit internals in your test code. The Surefire will download it shortly before the test runtime.
Your POM has several errors. Let's start with the root cause and then other priorities from high to low.
Whole problem is that Surefire does not know about JaCoCo. You have to tel "him" this way (see jacoco.agent) which "wires" both. Pls ead the documentation in the JaCoCo project:
<properties>
<jvm.args.tests>-Xmx2048m -Xms1024m -XX:SoftRefLRUPolicyMSPerMB=50 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</jvm.args.tests>
<properties>
...
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
</configuration>
...
The next error is with the way how you use plugins. The plugin jacoco-maven-plugin must be used only in the plugins section. The problem is that you use it also in the dependencies section. You do not want to have it on the classpath. It is job of the property jacoco.agent to put the jacoco agent on the test classpth only but there the JaCoCo plugin must start before the Surefire plugin.
The next thing i do not understand is the config of the compiler. Why you have this?
<executions>
<execution>
<id>compiletests</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
I have second question regarding the packaging. I have never seen this one. It isn't a standard packaging.
<packaging>eclipse-test-plugin</packaging>
Has the Eclipse plugin any special binary form of the archive file?

Checkstyle uses unpredictable config file

We have a maven project which includes checkstyle as well as pmd as analysers.
The problem is checkstyle sometimes takes my configured and modified google_checks.xml file, sometimes it uses a vanilla goole_checks.xml file and throws checkstyle errors, which are valid for the file it uses but I have no idea where it gets that file from. My pom looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<!-- checkstyle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- google checks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.20</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.12.0</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
</configuration>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- PMD -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.12.0</version>
<configuration>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
<!-- JXR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</reporting>
</project>
I removed some parts from the pom that are unrelevant I think.
The full project lies here: https://code.toold.xyz/Hochschule/WebAnServer/src/branch/mavenSetup/CueBox_source
When first executing a mvn clean it works reliably, but when I do a mvn compile and then without changing anything do a mvn compile again. It sometimes throws a lot of errors, about indents... which I removed from the google_checks.xml. It creates a checkstyle-checker.xml in the target folder, and it sometimes contains stuff that isn't in my google_checks.xml file, it looks more like the original google_checks.xml file.
Do you have any idea what causes this problem?
It seems like the issue was with the name google_checks.xml I renamed it and tested it now it works flawless all the time. It seems like maven interpreted the google_checks.xml not as a file name but as a refernce and downloaded it or extracted it from somewhere
If someone is here that knows exactly if this happened... please explain, I'll accept your answer :)

Tycho Compiler not picking up generated source code

I am fairly new to the world of maven and tycho, so hopefully this is just something obvious that I am missing. I am trying to build a plugin using tycho but I am unable to get the tycho-compiler-plugin to recognise source code that is generated as a part of the build process.
Here is a copy of a test pom that I've put together to demonstrate:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rt</groupId>
<artifactId>rt.webservice</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tycho-version>0.16.0</tycho-version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<verbose>true</verbose>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>generate-ws-code</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/wsdl</wsdlDirectory>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have a java class in the src folder that references some of the generated source code, which then fails to compile.
If I remove tycho and use the standard maven-compiler-plugin, it automatically picks up the code generated during the build and the java class mentioned above compiles as expected.
Can someone tell me what I am doing wrong?
tycho compiler plugin uses source dirs configured in build.properties
you have to make sure the generated source dir is referenced in build.properties
http://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html#sourceDestDir
You have to add additional source folders for generated sources, in your case the wsdl dir.
See this question for help on that.
Tycho will then pick up those additional directories during compile.

Maven install plugin with depedency packaging

I have Project A and Project B. ProjectB just has only proprietary jars or third party libs that ProjectA needs which cannot be found in maven repository. I intended to package all the related ( grouping dependencies) jars of Project B into one/more jar files. Question is, how do I install these jars and shade/assemble them in to one jar at the same time using POM. I am getting proprietary jars installed separately but I cannot get them packaged them in to one jar. M2 eclipse is also not helping much , so I decide to use mvn commands inside eclipse. What is the best practice to do this?. I think shading them since I want to use these dependencies in other projects as well.Can I install and shade/assemble jars( logically group the related dependencies in to one jar) at the time using POM?.
I followed this( from stack over flow forum) , it did not work- as this is creating one project jar which doesn't have anything + proprietary jars separately but not shading all jars in to one. I want them installed and combined in to one jar at the same time.
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.projectdeps</groupId>
<artifactId>sharedlibs</artifactId>
<version>1.0-SNAPSHOT</version>
<name>shared-libs</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install activationjar</id>
<goals><goal>install-file</goal></goals>
<phase>validate</phase>
<configuration>
<file>${basedir}/src/main/libs/activation.jar</file>
<groupId>com.mycompany.activation</groupId>
<artifactId>activation</artifactId>
<version>12.8</version>
<packaging>jar</packaging>
</configuration>
</execution>
<execution>
<id>install opsjar</id>
<goals><goal>install-file</goal></goals>
<phase>validate</phase>
<configuration>
<file>${basedir}/src/main/libs/Operations.jar</file>
<groupId>com.mycompany.gcs.ops</groupId>
<artifactId>Operations</artifactId>
<version>12.8</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>Operations</artifact>
<includes>
<include>/**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</project>

Resources