I'm using maven-dependency-plugin:copy-dependencies to copy all dependencies into target/dependency directory. My pom.xml is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
version of plugin is latest: 3.1.2 (defined in parent pom).
This definition is working fine with one exception: it copies all test dependencies into target directory, where I need only runtime dependencies required for running target jar.
I tried to exclude it usgin <excludeScope> configuration like described in the documentation:
<configuration>
<excludeScope>test</excludeScope>
</configuration>
But it makes the build failing with message:
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) # app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.006 s
[INFO] Finished at: 2021-02-15T10:32:26+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) on project app: Can't exclude Test scope, this will exclude everything. -> [Help 1]
I don't really understand why excluding the test scope will exclude everything, since without excluding test scope, the target directory contains all runtime dependencies too (along with test deps).
What could be the problem with excluding test dependencies? How to do it correctly?
PS: Please don't suggest me using assembly or other fat-jar plugins here, since I'm copying dependency jars intentionally for Docker image build optimization: one layer for dependencies, another for jar, where dependencies layer is always cached until any dependency changed:
COPY target/dependency /usr/lib/app/lib
COPY target/${JAR_FILE} /usr/lib/app/target.jar
The solution is probably in the includeScope description:
Scope to include. An Empty string indicates all scopes (default). The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom. In summary:
runtime scope gives runtime and compile dependencies,
compile scope gives compile, provided, and system dependencies,
test (default) scope gives all dependencies,
provided scope just gives provided dependencies,
system scope just gives system dependencies.
This means I would try with <includeScope>runtime</includeScope>.
To exclude dependencies which are under test scope is to use includeScope runtime instead of the excludeScope as the plugin documentation for test means 'everything'
Related
I'm still working on a multi-module maven project which I upgraded from openJDK 15 to openJDK 19. I'm working on a MBP with macOS 13 Ventura.
Before the upgrade the unit test are passing with the maven-surefire-plugin without any problems.
After upgrading to openJDK 19 the mvn clean test command fails with the following error-message.
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) # core ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[ERROR] Error occurred during initialization of boot layer
[ERROR] java.lang.module.FindException: Module javafx.graphics not found, required by common
I downloaded the files (openJDK 19 and JavaFX 19), unzipped them to a desired location, added an environment variable pointing to the lib directory of the runtime.
I can run the program from IntelliJ without any problems.
My question is, what did I missed in the configuration to get the test running?
My issues are gone with the advice from #Slavomir Jaranowski.
The changed pom looks like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<!--<skipTests>${skipUnitTests}</skipTests>-->
<testFailureIgnore>false</testFailureIgnore>
<forkCount>1.5C</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<useUnlimitedThreads>true</useUnlimitedThreads>
<perCoreThreadCount>true</perCoreThreadCount>
<reportFormat>plain</reportFormat>
<trimStackTrace>false</trimStackTrace>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
The configuration is not finished yet.
EDIT: This question should absolutely not be closed. I'm NOT asking how to create an executable jar. A jar doesn't need to be executable to be run from the terminal. For example, if I have have this code:
package com.dogzilla.maven.quickstart;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World" );
}
}
...and Maven builds it, it creates quickstart-0.0.1-SNAPSHOT.jar. Which is not, ahem, 'executable'.
I can run it from the terminal quite successfully with this:
java -cp /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar com.dogzilla.maven.quickstart.App
The problem, as I have written below, is experienced when using an external dependency. </end edit>
I have a simple Maven project in Eclipse (2020-6). It was set up by doing the following in Eclipse:
1. File -> New -> Other... Maven -> Maven Project
2. Used the maven-archetype-quickstart archetype
Group ID: com.dogzilla.maven
Artifact ID: quickstart
Right click the pom file -> select Add Dependency -> enter:
Group ID: com.google.code.gson
Artifact ID: gson
Version: 2.8.6
Which I verified on https://search.maven.org/
Here's the POM file:
<?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>
<groupId>com.dogzilla.maven</groupId>
<artifactId>quickstart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>quickstart</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<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>
</build>
</project>
Here's the source code:
package com.dogzilla.maven.quickstart;
import com.google.gson.Gson;
public class App
{
public static void main( String[] args )
{
Gson gson = new Gson();
System.out.println(gson.toJson("Hello World!") );
}
}
I then right-clicked on the POM file -> Run As -> Maven Build...
and here is the output:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/eclipse/java/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/opt/eclipse/java/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/eclipse/java/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/opt/eclipse/java/configuration/org.eclipse.osgi/5/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.dogzilla.maven:quickstart >--------------------
[INFO] Building quickstart 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) # quickstart ---
[INFO] Deleting /opt/workspace/eclipse/java/quickstart/target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # quickstart ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/workspace/eclipse/java/quickstart/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) # quickstart ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/workspace/eclipse/java/quickstart/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) # quickstart ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /opt/workspace/eclipse/java/quickstart/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) # quickstart ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /opt/workspace/eclipse/java/quickstart/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) # quickstart ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.dogzilla.maven.quickstart.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 s - in com.dogzilla.maven.quickstart.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) # quickstart ---
[INFO] Building jar: /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.967 s
[INFO] Finished at: 2020-12-13T20:00:27-07:00
[INFO] ------------------------------------------------------------------------
But if I run:
java -cp /opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar com.dogzilla.maven.quickstart.App
It fails with:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at com.dogzilla.maven.quickstart.App.main(App.java:13)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
The thing is if I change System.out.println(gson.toJson("Hello World!") ); to plain 'ol System.out.println("Hello World"); it works. So I know the porblem isn't with my java command or how I set the project up outside of the dependency getting resolved.
So the question is, I'm not sure how this is failing on the dependency. I was under the impression Maven managed all that for you. Why is this failing to run?
The jar file that created from your project only contains classes that written by you. If you need to run the application, you need to include all the necessary dependencies (either direct or transitive) in your classpath.
If you need a single jar file that you can execute without other dependencies, Please follow this to create a fatjar.
Use the Maven plugin mentioned in comment https://stackoverflow.com/a/65486325/679858 or use the Maven Shade plugin described here: https://maven.apache.org/plugins/maven-shade-plugin/
Your question was "Why does it run from Eclipse and not from console?":
If you run it from Eclipse then the Maven plugin in Eclipse knows the full runtime classpath and so it works. If you run it in console with the created JAR file then that JAR file only contains the classes of your sources but not the transitive dependencies, e.g. Google GSON. But if you use the Maven Assembly plugin or the Maven Shade plugin then you can create a JAR file which contains all the transitive dependencies of your project. That jar could be executed like you wrote it in your example.
try remove gson from .m2 folder then run maven install again.
You are not providing the path to the additional, transitive, dependencies of your project in the java command, which is why it fails.
You are using maven to build your project, not to execute your class: this is not Maven purpose, although it can do it using maven-exec-plugin. Eclipse is different: it uses Maven information (with m2e) and provides a context to run classes, context that includes dependencies.
The option -cp, explained in depth at Oracle Web Site: java (15), accepts one or more path to list of directories, jar and zip to search for class files:
--class-path classpath, -classpath classpath, or -cp classpath
A semicolon (;) separated list of directories, JAR archives, and ZIP archives to search for class files.
Specifying classpath overrides any setting of the CLASSPATH environment variable. If the class path option isn't used and
classpath isn't set, then the user class path consists of the current
directory (.).
As a special convenience, a class path element that contains a base name of an asterisk (*) is considered equivalent to specifying a
list of all the files in the directory with the extension .jar or .JAR
. A Java program can't tell the difference between the two
invocations. For example, if the directory mydir contains a.jar and
b.JAR, then the class path element mydir/* is expanded to A.jar:b.JAR,
except that the order of JAR files is unspecified. All .jar files in
the specified directory, even hidden ones, are included in the list. A
class path entry consisting of an asterisk (*) expands to a list of
all the jar files in the current directory. The CLASSPATH environment
variable, where defined, is similarly expanded. Any class path
wildcard expansion that occurs before the Java VM is started. Java
programs never see wildcards that aren't expanded except by querying
the environment, such as by calling System.getenv("CLASSPATH").
So you need to fix your command to provides gson and any other compile/runtime/provided dependencies you may add later:
CLASSPATH=''
CLASSPATH+=";$HOME/.m2/repository/com/google/code/gson/gson/2.8.6/gson-2.8.6.jar"
CLASSPATH+=";/opt/workspace/eclipse/java/quickstart/target/quickstart-0.0.1-SNAPSHOT.jar"
CLASSPATH="${CLASSPATH:1}" # remove leading ';'
java -cp "${CLASSPATH}" com.dogzilla.maven.quickstart.App
The man says that you can use ; to separate entries; that is true at least for Windows. However on other Linux based OS (which seems to are on due to /opt being used), this can also be :: that what appassembler does when writing CLASSPATH.
Do note that you will have to adapt the path manually to retarget the actual location of gson.jar (I guessed from what maven does by default).
You can also use appassembler or launch4j to do the trick for you. You can also use build-classpath to build the classpath (it may also work from command line).
I am learning about mutation testing with pitest and facing problems when I try to run it with maven. In my pom.xml I have the pitest dependency:
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>1.5.2</version>
</dependency>
I also have the plugin:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>pit-report</id>
<!-- optional, this example attached the goal into mvn test phase -->
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.12</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>mypackage.myClass*</param>
</targetClasses>
<targetTests>
<param>mypackage*</param>
</targetTests>
</configuration>
</plugin>
However, when I run mvnw.cmd verify test -Dverbose it reports that it found the mutation engine, Junit 5 and the Junit plugin, adds the junit 5 plugin to the classpath, adds pitest to the classpath, and then fails to find and load main class org.pitest.coverage.execute.CoverageMinion and doesn't do any mutation testing:
[INFO] --- pitest-maven:1.5.2:mutationCoverage (pit-report) # myProject ---
[...]
[INFO] Found plugin : Mutant export plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Found shared classpath plugin : JUnit 5 test framework support
[INFO] Found shared classpath plugin : JUnit plugin
[INFO] Found shared classpath plugin : TestNG plugin
[INFO] Adding org.pitest:pitest-junit5-plugin to SUT classpath
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from C:\Users\myUser\myWorkspace\myProject\target\classes
[...]
13:20:27 PIT >> FINE : Running report with ReportOptions [targetClasses=[mypackage.myClass*], excludedMethods=[], excludedClasses=[], excludedTestClasses=[], codePaths=[C:\Users\myUser\myWorkspace\myProject\target\classes], reportDir=C:\Users\myUser\myWorkspace\myProject\target\pit-reports, historyInputLocation=null, historyOutputLocation=null, sourceDirs=[C:\Users\myUser\myWorkspace\myProject\src\main\java, C:\Users\myUser\myWorkspace\myProject\src\test\java], classPathElements=[C:\Users\myUser\myWorkspace\myProject\target\test-classes, C:\Users\myUser\myWorkspace\myProject\target\classes, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter\5.7.0\junit-jupiter-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.7.0\junit-jupiter-params-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.7.0\junit-jupiter-engine-5.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-engine\1.7.0\junit-platform-engine-1.7.0.jar, C:\Users\myUser\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.7.0\junit-jupiter-api-5.7.0.jar, C:\Users\myUser\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar, C:\Users\myUser\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar, C:\Users\myUser\.m2\repository\org\junit\platform\junit-platform-commons\1.7.0\junit-platform-commons-1.7.0.jar, C:\Users\myUser\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest\1.5.2\pitest-1.5.2.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest-junit5-plugin\0.12\pitest-junit5-plugin-0.12.jar, C:\Users\myUser\.m2\repository\org\pitest\pitest\1.5.2\pitest-1.5.2.jar], mutators=[], features=[], dependencyAnalysisMaxDistance=-1, jvmArgs=[-Djava.awt.headless=true], numberOfThreads=1, timeoutFactor=1.25, timeoutConstant=3000, targetTests=[^myPackage.*$], loggingClasses=[], maxMutationsPerClass=0, verbose=true, failWhenNoMutations=true, outputs=[HTML], groupConfig=TestGroupConfig [excludedGroups=[], includedGroups=[]], fullMutationMatrix=false, mutationUnitSize=0, shouldCreateTimestampedReports=true, detectInlinedCode=true, exportLineCoverage=false, mutationThreshold=0, coverageThreshold=0, mutationEngine=gregor, javaExecutable=null, includeLaunchClasspath=true, properties={}, maxSurvivors=0, excludedRunners=[], includedTestMethods=[], testPlugin=junit5, useClasspathJar=false, skipFailingTests=false]
13:20:27 PIT >> FINE : System class path is C:\Users\myUser\myWorkspace\myProject\.mvn\wrapper\maven-wrapper.jar
13:20:27 PIT >> FINE : Maximum available memory is 1796 mb
13:20:27 PIT >> FINE : MINION : Installing PIT agent
13:20:27 PIT >> INFO : MINION : Error: Could not find or load main class org.pitest.coverage.execute.CoverageMinion
Initially I thought it would be a problem with the classpath, given the error message, but the above logs show that the classpath being used includes the relevant jars and paths. What else could I be doing wrong? Thanks in advance.
For anyone running into the same problem, my mistake was that I assumed the classpath to be correct, but it wasn't. It seems the logs don't take into account the value of the classpath environment variable, and in my computer that variable had a value, when it shouldn't be set. Unsetting it with set classpath= solved the classpath issues that were causing the error with pitest.
I've added JaCoCo plugin to my Maven plugins, and can generate coverage report successfully locally.
However after I've commited the changed pom.xml and Jenkins tries to build the Maven project (consisting of multiple modules) the build fails with the output like this:
[HUDSON] Collecting dependencies info
[HUDSON] Collecting dependencies info
[HUDSON] Collecting dependencies info
[HUDSON] Collecting dependencies info
[JENKINS] Recording test results
[WARNING] Failed to getClass for org.jacoco.maven.AgentMojo
[JENKINS] Archiving /var/lib/jenkins/jobs/xy xyz1
[JENKINS] Archiving /var/lib/jenkins/jobs/xy xyz2
[JENKINS] Archiving /var/lib/jenkins/jobs/xy xyz3
[JENKINS] Archiving /var/lib/jenkins/jobs/xy xyz4
channel stopped
Finished: FAILURE
The only warning I get is the Failed to getClass for org.jacoco.maven.AgentMojo so I assume this could cause the build failure.
First I've thought that it's because a proxy setting, but I've added the same settings.xml to the Jenkins build as I use locally (with which the plugin is used successfully).
Also I've tried to look up this specific error in several places with no luck.
Also tried to change the pom executions, but since it's working locally I think there's no reason in changing the following Maven pom.xml setting:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Why Jenkins does not log any more errors than that simple [WARNING] line?
What can be the reason Jenkins fails to getClass while locally the Maven build runs successfully?
Can I get JaCoCo coverage without adding the maven plugin to the xml? (From what I've found it is needed to be added for getting to work the Jenkins plugin)
I am using Jenkins JaCoCo plugin to do that. You just need to specify where your java src files, .class files and test classes are. The plugin also enables the html report output to be accessible from Jenkins interface.
The suspicious bit for me is that you have attached the report goal to the test phase, which seems to be wrong: The report about the test coverage can't be done before the tests are performed, so you must chose another of the next phases. For example, the verify phase (which is the default phase for the report goal).
I have a large JEE Maven Multi module project, and share a custom set of rules and suppressions for Checkstyle via build-tools module. I find very hard to release a stable version of this build-tools due to the testing of this same module.
Each time I run a Maven phase, I get a different execution result.
This is Checkstyle configuration in parent pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<configuration>
<skip>${skipQATests}</skip>
<configLocation>qa/checkstyle_rules.xml</configLocation>
<propertiesLocation>${checkstyleDir}/checkstyle.properties</propertiesLocation>
<suppressionsLocation>qa/suppressions.xml</suppressionsLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>checkstyle-compile</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I'm trying to find a pattern in the executions, project is set to fail in one particular check and I cannot find the 'bug'.
I execute compile maven phase (mvn clean compile) and it fails on the given check.
I execute package maven phase (mvn clean package) and it fails too.
I execute again compile phase (mvn clean compile) and it doesn't fail (all SUCCESS)
I execute again package and it fails
It does not fail for a couple of runs and then it fails again on some different execution
I know this behavior is kind of difficult to trace without all project information. But is there any kind of procedure, log, tool that would give more information on debuging this problem so that I can determine if it's a bug or some mis-configuration??
Thanks in advance!!
UPDATE:
I have just executed the same mvn command twice on the sub-module I'm testing Checkstyle (test that forces a rule violation) - mvn checkstyle:check -X
Result was different from each other, the main differences are that the CORRECT EXECUTION (the one that fails the build does not find the files at the first try) and the WRONG EXECUTION (the one that ends in SUCCESS finds the configuration files at the first attempt)
EXEC_1: ...
[DEBUG] The resource 'qa/suppressions.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was not found with resourceLoader org.codehaus.plexus.resource.loader.FileResourceLoader.
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.
[INFO] Starting audit...
[INFO] --------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------
[INFO] Total time: 1.542s
[INFO] Finished at: Thu Feb 20 16:35:22 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] --------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.11:check (default-cli) on project GestionDelContacto-opsa-ejbws: Failed during checkstyle execution: There are 2 checkstyle errors.
EXEC_2:...
[DEBUG] The resource 'qa/suppressions.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/suppressions.xml.
[DEBUG] Adding the outputDirectory file:/C:/LAB/PRJ/prj-ejbws/target/classes/ to the Checkstyle class path
[DEBUG] The resource 'qa/checkstyle_N4_JEE.xml' was found as jar:file:/C:/Users/usuario/.m2/repository/com/company/tools/build-tools/0.0.2-SNAPSHOT/build-tools-0.0.2-SNAPSHOT.jar!/qa/checkstyle_JEE.xml.
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.ThreadContextClasspathResourceLoader.
[DEBUG] The resource 'ubic.properties' was not found with resourceLoader org.codehaus.plexus.resource.loader.JarResourceLoader.
[DEBUG] The resource 'ubic.properties' was found as C:\LAB\PRJ\ubic.properties.
[INFO] Starting audit...
[INFO] --------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------
[INFO] Total time: 1.570s
[INFO] Finished at: Thu Feb 20 16:37:05 CET 2014
[INFO] Final Memory: 8M/20M
[INFO] ---------------------------------------------
any clue?
Stop using Maven, run CheckStyle separately. You already have sufficient "clues": sometimes Maven initializes CheckStyle correctly, sometimes not, and depending on unreliable infrastructure is a bad idea.