Maven Enforcer plugin identifies Dependency Convergence issue within Camel-CXF - maven

The Maven enforcer plugin is identifying a code convergence issue with a 3rd party library I'm using. How can I ignore this whilst still running the enforcer plugin on the project over the rest of the project or how else should I resolve the issue without changing the library's version?
My project consumes camel-cxf 2.13.2 which it turns out depends on two separate transitive versions of jaxb-impl; 2.1.13 and 2.2.6. The enforcer plugin identifies this and fails the build.
Here is how I'm configuring the plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<rules>
<DependencyConvergence/>
</rules>
</configuration>
</plugin>
When I run mvn enforcer:enforce I get
Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.sun.xml.bind:jaxb-impl:2.2.6 paths to dependency are:
+-com.myModule:module:18.0.0-SNAPSHOT
+-org.apache.camel:camel-cxf:2.13.2
+-org.apache.camel:camel-core:2.13.2
+-com.sun.xml.bind:jaxb-impl:2.2.6
and
+-com.myModule:module:18.0.0-SNAPSHOT
+-org.apache.camel:camel-cxf:2.13.2
+-org.apache.cxf:cxf-rt-bindings-soap:2.7.11
+-org.apache.cxf:cxf-rt-databinding-jaxb:2.7.11
+-com.sun.xml.bind:jaxb-impl:2.1.13
and
+-com.myModule:module:18.0.0-SNAPSHOT
+-org.apache.cxf:cxf-rt-management:2.7.11
+-org.apache.cxf:cxf-rt-core:2.7.11
+-com.sun.xml.bind:jaxb-impl:2.1.13

In the end I added exclusions to the specific sub dependencies which were pulling in the older, clashing versions of jaxb-impl.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>${cxf.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
<scope>${framework.scope}</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-jaxb</artifactId>
<version>${cxf.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
This way I can still run the enforcer plugin on the rest of the project and fail builds if new convergence issues are identified.

I think you don't want maven to fail the build phase when there is convergence error.
In that case you need to set fail = false flag in the configuration so it will just logs out the convergence error and proceeds with next phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>dependency-convergence</id>
<phase>install</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<DependencyConvergence />
</rules>
<fail>false</fail>
</configuration>
</execution>
<executions>
<plugin>
Note: maven-enforcer-plugin version 1.3.1 is very old. consider upgrading it to latest 3.x.x.

Related

What do we meant by "Unresolved requirement: Import-Package: com.google.common.collect_ [Sanitized]" in liferay 7.2

I am creating a hook in liferay 7.2 but unfortunately when I deploy it.I come across this error. I had tried increasing version of "com.google.collections" dependency and also tried adding guauva
a dependency but nothing seems to resolve this error.
My dependencies in Pom.xml is as such:
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0-rc2</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.ant.bnd</artifactId>
<version>3.2.6</version>
</dependency>
</dependencies>
Error :
org.osgi.framework.BundleException: Could not resolve module: com.allen.portal.hook [1272]_ Unresolved requirement: Import-Package: com.google.common.collect_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:428)
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundle(DirectoryWatcher.java:1106)
at com.liferay.portal.file.install.internal.DirectoryWatcher._startBundles(DirectoryWatcher.java:1139)
at com.liferay.portal.file.install.internal.DirectoryWatcher._process(DirectoryWatcher.java:1001)
at com.liferay.portal.file.install.internal.DirectoryWatcher.run(DirectoryWatcher.java:313)
If you have any ways to resolve this error, please help me out
Unrelated: You're using an rc2 version released in October 2009, when a release was made in December 2009? Seriously?
It looks like you're building an OSGi module, which compiles fine (because you provide the dependency). However, that does not mean that the google collections code ends up in your jar as well. The runtime expects to find it though - and as Google collections is not an OSGi bundle itself, you'll have several choices:
repackage it as OSGi bundle (and deploy it to the runtime) (or find someone who did it already)
repackage it within your own bundle
use a different implementation. Chances are that collections utility code from 2009 has found its way into more current implementations and is no longer necessary.
In short: In one way or another, you'll need to make your dependencies available at runtime. Either by fattening your own bundle (but be careful: You can't pass those collections around to other bundles if they bring their own implementation) or by relying on the implementation being available to the runtime.
The third alternative is to switch to an implementation where it's easier to make it available at runtime, preferably as OSGi bundle.

How to exclude all vulnerabilities of hive-exec, which includes "shaded" dependency itself?

I must remove all "High Severity"-Vulnerabilities in "Dependency-check", which are generated through a maven-plugin. It is difficult to remove vulnerabilities of "hive-exec".
An example of result-html-file is like this.
hive-exec-3.1.0.jar (shaded: org.apache.parquet:parquet-hadoop:1.10.0)
File Path: C:\Users\MYNAME\.m2\repository\org\apache\hive\hive-exec\3.1.0\
hive-exec-3.1.0.jar\META-INF/maven/org.apache.parquet/parquet-hadoop/pom.xml
this "...\hive-exec-3.1.0.jar\META-INF/maven/org.apache.parquet/parquet-hadoop/pom.xml" should be removed!
I could remove most of Vulnerabilities using < exclude > -tag in each < dependency > or changing the version.
I also tried to exclude this "parquet-hadoop" in my pom file...
<dependencies>
...
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.parquet</groupId>
<artifactId>parquet-hadoop-bundle</artifactId>
</exclusion>
...
</exclusions>
</dependency>
</dependencies>
But it couldn't remove this "parquet-hadoop-bundle", because they are "shaded" in the "hive-exec".
A file called hive-exec-3.1.0.pom inside the hive-exec-3.1.0.jar shades this "parquet-hadoop". The hive-exec-3.1.0.pom has the following contents...
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>build-exec-bundle</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.hive:hive-common</include>
...
<include>org.apache.parquet:parquet-hadoop-
bundle</include>
I also tried to remove them with shade-plugin in my pom file. But It doesn't work.
I'll be very happy if someone has experience with this kind of problem.
A college found the solution.
...
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.0</version>
<classifier>core</classifier>
<exclusions>
...
We can specify the jar of the hive-exec with the "classifier"-tag and the value-"core". This "core" includes only the essential part of the "hive-exec". In this way I could remove all high and middle vulnerabilities.

Sonar does not pick up Unit Tests Results even thought Code Coverage is generated

I am running SonarQuebe 6.2 on my local machine, I have Spring Boot Java 8 project with written unit tests that I want to upload to Sonar for static analysis all together with code coverage.
Code coverage is generated - I have my JaCoCo HTML report, JUnit XML test files are generated but my Sonar seems to miss Unit Tests result even thought that Code Coverage is diplayed:
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.facebook4j</groupId>
<artifactId>facebook4j-core</artifactId>
<version>2.4.8</version>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
My sonar-project.properties:
sonar.projectKey=org.eventizer:EventizerServer
sonar.projectName=EventizerServer
sonar.projectVersion=1.0
sonar.log.level=DEBUG
sonar.sources=src/main/
sonar.language=java
sonar.java.source=1.8
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/classes/org/eventizer/eventizerserver/
sonar.java.test.binaries=target/test-classes/org/eventizer/eventizerserver/
sonar.tests=src/test/
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPaths=target/jacoco.exec
sonar.junit.reportPaths=target/surefire-reports/
I am running this mvn command:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -Dmaven.test.failure.ignore=true
As a result I am getting target directory with following output:
Classes directory that is set for sonar.java.binaries:
Test classes directory that is set for sonar.java.test.binaries:
Surefire JUnit test reports directory that is set for sonar.junit.reportPaths:
JaCoCo report output directory:
JaCoCo HTML report in browers:
After that I am running sonar-scanner.bat, below some important (I tihnk so) outputs:
My Sonar web instance project analysis:
And I really do not have idea why this is happening since it looks like everything got generated properly. Since yesterday I think I have tried everything on StackOverflow so please do not mark it as duplicate.
This is even weirder because when I access Coverage metrics for this project I can see that 100% Unit tests passed:
Well... I suppose, that could because of sonar.sources=src/main/... If you set it as sonar.sources=src, it will show again.
And, I just find there's a Sonar Parater:
sonar.tests=src/test will show the junit report in sonar.
here's my sonar-project.properties:
sonar.projectKey=com.test.marslo:marslo-test
sonar.projectName=marslo-test
sonar.projectVersion=1.1.0
sonar.projectBaseDir=.
sonar.sources=src/main
sonar.tests=src/test
sonar.java.binaries=build
sonar.sourceEncoding=UTF-8
sonar.java.source=1.8
sonar.jacoco.reportPaths=./build/jacoco/test.exec
sonar.junit.reportPaths=./build/test-results/test
And the build.gradle:
...
apply plugin: "jacoco"
...
...
jacoco {
toolVersion = "0.8.0"
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled true
html.enabled true
}
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
}
Build with:
gradle clean build test jacocoTestReport
Okay, so I have discovered something that may be a Sonar bug.
Basically, this project has been pushed to Sonar for a long time with basic mvn sonar:sonar configuration. So, it was not even doing test results. Now I wanted to run that via Jenkins, so I filled all necessary fields in sonar-project.properties and pushed via Sonar-Runner not mvn sonar:sonar.
After doing so as you could see, Unit Tests Quality gate was failing with no good reason. Because in my latest screenshoot, you can see that in fact Unit Tests passed 100.0%.
I decide to push that analysis to a separate project by changing projectKey property to something else and all of the sudden everything went smoothly.

Why does jasperreports-maven-plugin needs itext:itext:jar:4.2.0?

Since today we can't build our jasper file any more. We use the jasperreports-maven-plugin for this.
In maven 2.2.1, this was configured like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/reports</sourceDirectory>
<outputDirectory>>${project.build.directory}/classes/reports</outputDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<configuration>
<sourceDirectory>C:\Windows\TEMP/src/main/resources/reports</sourceDirectory>
<outputDirectory>C:\Windows\TEMP\target/classes/reports</outputDirectory>
</configuration>
</plugin>
But, as said, since today, we got this build error:
...
Downloading: http://repo1.maven.org/maven2/itext/itext/4.2.0/itext-4.2.0.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) itext:itext:jar:4.2.0
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=itext -DartifactId=itext -Dversion=4.2.0 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=itext -DartifactId=itext -Dversion=4.2.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.codehaus.mojo:jasperreports-maven-plugin:maven-plugin:1.0-beta-2
2) jasperreports:jasperreports:jar:1.2.0
3) itext:itext:jar:4.2.0
I think another question (Dependency error in jasper-reports from itext) is related to his. And I tried the solution of Meher to use maven 3.2.3. This seems to be a solution, but we can't upgrade (now) to this maven version. So I need another solution to resolve this issue. Any ideas? I already tried to exclude dependencies and use fixed versions, but I haven't managed to succeed my build. What I mean is this:
<!-- Compile jasper reports -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/reports</sourceDirectory>
<outputDirectory>${project.build.directory}/classes/reports</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<exclusions>
<exclusion>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
</plugin>
Why is the plugin still searching for itext:itext:jar:4.2.0? Any ideas or suggestions to solve this?
Thanks!
Background:
iText Group NV is owner of the groupId com.lowagie and com.itextpdf on Maven Central. iText Group NV released com.lowagie:itext version 2.1.7 in July 2009. The next release by iText Group NV was com.itextpdf:itextpdf version 5.0.0, in December 2009. The current version (as of December 2015) is 5.5.8.
iText Group NV never released a version 4.x.x.
Somewhere in 2011, a company called InProTopia "hijacked" com.lowagie and released a fork of iText with version number 4.2.0. According to the [Guidelines of Maven Central][1], they should have published this as com.inprotopia:itext, but they didn't. Later they published a 4.2.1 with their own patches. Recently iText Group NV took ownership of com.lowagie and published a version 4.2.2 with redirection to com.itextpdf:itextpdf version 5.5.6 (the current version at that time).
Possible solutions:
If you need com.lowagie iText, you need to set a fixed version in your pom.xml. The last official release is 2.1.7.
If you need iText 4.x.x, contact InProTopia. Good luck with that, because their website is down, and as far as I could find out, that company no longer exists.
If you don’t mind which version of iText you use, use the current version of iText published by iText Group NV, com.itextpdf:itextpdf 5.5.8 (as of December 2015).
Use the latest version of jasperreports. It has an explicit dependency on iText 2.1.7.js, which a custom iText version for Jasper Reports.
More info at the iText blog.
http://itextpdf.com/maven-update-problem-with-itext-4.2.2
[1] https://maven.apache.org/guides/mini/guide-central-repository-upload.html
I resolved my issue by using ant to build my jasper report. So I skipped the plugin.
My ant task looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<execution>
<id>compile-jasper-reports</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<target>
<echo message="Start compile of jasper reports"/>
<mkdir dir="${project.build.directory}/classes/reports"/>
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask" classpathref="maven.compile.classpath" />
<jrc srcdir="${basedir}/src/main/resources/reports"
destdir="${project.build.directory}/classes/reports"
tempdir="${project.build.directory}/classes/reports"
keepjava="true"
xmlvalidation="true">
<classpath refid="maven.compile.classpath"/>
<include name="**/*.jrxml"/>
</jrc>
</target>
</configuration>
</execution>
</executions>
</plugin>
Try add this repository:
<repository>
<url>https://repository.liferay.com/nexus/content/groups/public/</url>
<id>liferay</id>
<name>Liferay</name>
</repository>
Good luck!

All jUnit test cases are not running for Maven project using PowerMock with easymock, Surefire

In a Maven Project I am using PowerMock-easymock to run jUnit test cases. but while doing "mvn clean install" , I am getting below output..
T E S T S
Running TestSuite
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.621 sec
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
But I have many other test cases.
Here is a part of pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-easymock-release-full</artifactId>
<version>1.4.12</version>
<type>pom</type>
</dependency>
If I remove, PowerMock dependency and do "mvn clean install" , all test cases are running fine. But I have to use PowerMock. How to solve this issue?
I guess that some of your test cases are not running, did you try this
Use mvn surefire plugin, and include test cases in that.
ensure dependancy of powermock-module-junit4.
check out these link: code.google.com/p/powermock/wiki/EasyMock_maven
http://code.google.com/p/powermock/wiki/GettingStarted
I had the same problem, and it took me a while to figure out. My setup was pulling in an older version of jboss.javassist, which oddly was preventing the PowerMockRunner from working at all.
It's worth noting that I also have a mixed JUnit / TestNG environment. I previously tried the solution of adding multiple surefire providers, and that didn't work either (using surefire 2.14.1). After upgrading to surefire 2.17, both my JUnit and TestNG tests started running without needing to declare any surefire providers. In fact, the JUnit provider threw an error for me, because I'm using groups. Apparently the TestNG provider allows free-form text (e.g. "integration") while the JUnit provider expects a classpath (e.g. "com.example.UnitTests").
Here's my plugin section...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<groups>spring, unit, integration</groups>
<systemPropertyVariables>
<java.awt.headless>true</java.awt.headless>
<org.apache.activemq.default.directory.prefix>target/test/</org.apache.activemq.default.directory.prefix>
<log4j.configuration>file:${project.basedir}/src/test/resources/log4j.properties</log4j.configuration>
</systemPropertyVariables>
<argLine>${surefire.args}</argLine>
</configuration>
</plugin>
... and the relevant testing deps ...
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!--
PowerMock versions are compatible with specific Mockito versions.
https://code.google.com/p/powermock/wiki/MockitoUsage13
-->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.4</version>
<scope>test</scope>
</dependency>
<!-- without this PowerMock tests don't run in maven -->
<dependency>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
<scope>test</scope>
</dependency>
As per Dipak,
Solution 1:
Add below code in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.13</version>
</dependency>
</dependencies>
</plugin>
For Correct ArtifactId in dependency , you can see this link if you are using jUnit.
Then do "mvn clean install"
Solution 2:
Add below code in pom.xml
<properties>
<powermock.version>1.5</powermock.version>
</properties>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
Refer this link for detail
All credits go to Dipak
I had a situation recently where PowerMock tests were run, but not included in the surefire coverage report. We found that the problem had to do with instrumentation.
I'll note that most of our tests run with TestNG. In general, we only use JUnit when we need to leverage PowerMock.
Here is the POM snippet:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<org.apache.activemq.default.directory.prefix>target/test/</org.apache.activemq.default.directory.prefix>
<log4j.configuration>file:${project.basedir}/src/test/resources/log4j.properties</log4j.configuration>
<jacoco-agent.destfile>${project.basedir}/target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<argLine>-Xmx512m -XX:MaxPermSize=256m -Djava.awt.headless=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>instrument</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore</id>
<phase>test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The <systemPropertyVariables> are probably not relevant to the fix.
Also, note that JaCoCo's documentation warns against using this type of configuration unless you find it necessary.
http://www.eclemma.org/jacoco/trunk/doc/instrument-mojo.html
Warning: The preferred way for code coverage analysis with JaCoCo is
on-the-fly instrumentation. Offline instrumentation has several
drawbacks and should only be used if a specific scenario explicitly
requires this mode. Please consult documentation about offline
instrumentation before using this mode.

Resources