pom file Build failed found duplicate classes/resources: THIRD_PARTY_LICENSES.txt - build

Maven build fails with the following error. I need all three jars in pom for compilation dependencies. But the duplicate finder throws the following error:
Found duplicate (but equal) resources in [com.oracle.oci.sdk:oci-java-sdk-common-httpclient:3.2.1, com.oracle.oci.sdk:oci-java-sdk-common:3.2.1, com.oracle.oci.sdk:oci-java-sdk-vault:3.2.1]: THIRD_PARTY_LICENSES.txt
pom.xml
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-vault</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common-httpclient</artifactId>
<version>3.2.1</version>
</dependency>
How do I fix this error? Thank you

Related

Can we execute JUnit 5 and TestNG tests in the same project using maven-surefire-plugin?

I am writing unit tests for a project which already has a few TestNG tests. Since I am using JUnit Jupiter (aka JUnit 5) to write new tests, I observed the problem that only TestNG tests are run when i do "mvn clean verify"
Below are my dependencies in pom.xml
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
And since surefire plugin from 2.22.0 onwards provides JUnit 5 support below is my plugin section for surefire
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
Is there any way I can keep both in the project and be able to run all tests through maven ? This is necesary so that code coverage report shows all tests together.
Also I noted that all tests(JUnit + TestNG) run together through maven if I use JUNIT 4 tests with the help of vintage-engine dependency. I am confused why this does not happen with JUnit 5.
It's supported in a "preview feature" style.
(1) Have the TestNGine in your test runtime dependencies.
(2) Help (force) Surefire to use the JUnit Platform provider
See this simple integration test pom.xml for a possible setup:
<dependencies>
<dependency> <!-- (1) -->
<groupId>com.github.testng-team</groupId>
<artifactId>testng-junit5</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency> <!-- (2) -->
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>2.22.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

Wildlfy 10 deployement - NoClassDefFoundError: org/picketlink/common/exceptions/ProcessingException

I'm overriding a server filter class from a jar in the Wildlfy 10 modules.
It's a quick and dirty solution : copied/pasted the content of the class in my custom class and referenced my custom class instead.
My parent pom is like this :
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-api</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-federation</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-common</artifactId>
<version>${picketlink-version}</version>
<scope>provided</scope>
</dependency>
And I have the following section in the war pom containing the custom class :
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-federation</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.picketlink</groupId>
<artifactId>picketlink-common</artifactId>
<scope>provided</scope>
</dependency>
I also have a jboss-deployment-description.xml file in my war where the package containing the missing class is already referenced (this is from an instruction on how to use the package for other things) :
<jboss-deployment-structure>
<deployment>
<!-- You must configure the PicketLink dependency to your deployment. The dependency above is a reference to a static module
from JBoss EAP modules directory. -->
<dependencies>
<module name="org.picketlink"/>
<module name="org.picketlink.common"/>
</dependencies>
</deployment>
and the main package "org.picketlink" is also in my ear's manifest file which packages the war :
<manifestEntries>
<Dependencies>
com.docapost.configuration,org.picketlink
</Dependencies>
</manifestEntries>
This was also done to solve some past ClassNotFoundException in the past if i recall correctly.
The jar version in the pom is the same as the version in my Wildfly (picketlink 2.7.0.Final)
At deployment, I get the exception from my custom class ZephirSPFilter :
Error getting reflective information for class com.docapost.zephir.filters.ZephirSPFilter with ClassLoader ModuleClassLoader
And :
Caused by: java.lang.NoClassDefFoundError: org/picketlink/common/exceptions/ProcessingException
Caused by: java.lang.ClassNotFoundException: org.picketlink.common.exceptions.ProcessingException from [Module \"deployment.zephir-ear.ear.zephir-web.war:main\" from Service Module Loader]"},
As far as I understand you have ear and included in it war. And you added jboss-deployment-description.xml to your war. But this file should be placed in the top level deployment, i.e. in your case to ear.
See https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

Maven dependencies for Hadoop: MiniDFSCluster & MiniMRCluster

I want to implement a maven project, that helps me unit test a Hadoop MapReduce job. My biggest problem is defining the Maven dependencies to be able to make use of the test classes: MiniDFSCluster & MiniMRCluster.
I am using Hadoop 2.4.1. Any ideas?
In case someone else is still searchinf for an answer:
MiniMRCluster is now deprecated.
You can get MiniDFSCluster and MiniMRCluster in the dependency (shown for Gradle)
compile group: 'org.apache.hadoop', name: 'hadoop-minicluster', version: '2.7.2'
The dependency is basically just a pom file that lists out the dependencies in this package. For those who want to look this up, MiniDFSCluster is in the artifact hadoop-hdfs:tests
You don't have to use the dependencies from the Cloudera repository
Guess I figured it out. In your Maven pom file, first add a new repository:
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
</repository>
</repositories>
Then add the following to your project dependencies
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-test</artifactId>
<version>2.0.0-mr1-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.0.0-cdh4.3.0</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.0.0-cdh4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.0.0-cdh4.3.0</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>2.0.0-mr1-cdh4.3.0</version>
</dependency>
In case someone is interested to get the whole project (unit test for the famous WordCount MapReduce job, I am willing to share it)

How to unit test classes with bean validation? (Java EE)

I'm unit testing some classes annotated with jsr303 constraints, but I can't find a proper maven dependency for javax.validation.Validation in order to create the ValidatorFactory used in my tests. And the weird thing is I've got that problem only with the Validationclass. The constraints and the validation factory itself resolve just fine.
NetBeans (7.3) gives me a "Java EE API is missing on project classpath" message for every dependency I've tried so far (both hibernate-validator and validation-api).
Here's some of the pom (including both dependencies):
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Turns out I had to declare the validation-api test dependency before the javaee-api, otherwise Maven would try to use it for tests, wich is not possible. Declaring it after does not override the broader scope dependency.
Let's try changing validation-api's groupID to javax.validation
Reference

Getting java.lang.NoClassDefFoundError while using solr-solrj-3.6.1.jar

Using Solrj to connect to solr indexes. Used jar solr-solrj-3.6.1.jar which I got by adding below maven dependency
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.6.1</version>
</dependency>
I see that CommonsHttpSolrServer is deprecated and hence using HttpSolrServer . During run time i get the below error,
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
Just adding solr-solrj-3.6.1.jar is not sufficient? Should I have to add more dependencies? I also tried adding httpclient 4.1, It started asking for org/apache/http/HttpRequestInterceptor.
Add this package to your maven dependencies:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
Added below dependencies to get this working
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
My simple project of solrj uses the following dependencies:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
Between, Maven can automatically download them (for example, I started the Java Application of Maven in NetBeans, and then just added the dependencies). Additionally, I needed just to download the library of commons-logging 1.1.3 (http://commons.apache.org/proper/commons-logging/download_logging.cgi). You can read more about libraries and dependencies here: (http://wiki.apache.org/solr/Solrj).