Eclipse plugin- Maven transitive dependency issue - maven

I am facing issue with velocity jar issue. As one of the eclipse plugin dependent on CXF bundle.
jar dependency defined in pom.xml as below,
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.5</version>
</dependency>
another eclipse plugin dependent on custom bundle jar which has
jar dependency defined in pom.xml as below,
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
On runtime I am geting issue as,
Could not find Velocity template file: org/apache/cxf/tools/wsdlto/frontend/jaxws/template/build.vm
To identify the issue I run the command,
mvn dependency:tree -Dverbose
This shows maven omitting velocity jar from cxf as it loads another velocity in classpath.
How to resolve this jar dependency ?

use the <exclusions> tag for the dependency you not want:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.5</version>
<exclusions>
<exclusion>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<exclusion>
<exclusions>
</dependency>

Related

How to exclude protobuf dependency from monitoring-interceptors dependency in maven

in my project, I am using monitoring-interceptors dependency from io.confluent version 7.2.2. This particular jar is using google protobuf jar but that is some old jar and it is not passing Aqua scan. I am trying to remove this protobuf jar from like below:
<dependency>
<groupId>io.confluent</groupId>
<artifactId>monitoring-interceptors</artifactId>
<version>7.2.2</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>4.0.0-rc-2</version>
</dependency>
But my Aqua scan is still showing older version of protobuf jar coming from monitoring-interceptors-7.2.2 jar.
I tried to put above portion in dependency management tag also but it still not working. Any idea how to make it work?

Stop downloading jar form Repository Maven

In my Maven Project I have dependency for
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
</dependency>
But the downloaded jar is corrupted or it has problem so my application fails. I have a working jar in my hard. So I want to add that instead of downloading form repo. I used this to do that,
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/xalan-xalan-2.7.1.jar</systemPath>
</dependency>
But didn't work :(

How to exclude a dependency from remote mavenpom?

I have a local pom which uses mahout-0.8 dependency. Mahout pom includes hadoop-core dependency with 1.1.2 version. Link to mahout-0.8 pom
But in my project I need the latest hadoop-core, which is 2.2.0 version. As I have read hadoop-core-2.2.0 is built from these dependencies:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.2.0</version>
</dependency>
So I need to exclude dependency from remote mahout-0.8 dependency. How to exclude this dependency (snipped) or it cannot be done remotely?
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>${hadoop.version}</version>
...
</dependency>
If it cannot be done in such way, would like to know how to integrate mahout pom to my local project.
Many thanks!
Copy the hadoop-core dependency in your second snippet into the dependencyManagement section of your pom. This will manage it to whatever version you specify.
Or, if you really really want to stop it from coming from mahout all together, change your mahout dependency to something like the following:
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout</artifactId>
<version>0.8</version>
<exclusions>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
</exclusion>
</exclusions>
</dependency>

Maven exclusion jar is still part of war file

I am using Maven 3.0.5 and I have the following in pom.xml
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>janino</groupId>
<artifactId>janino</artifactId>
</exclusion>
</exclusions>
</dependency>
When I build war using mvn install, I can see that in war file xml-apis-1.0.b2.jar is also included although I have put xml-apis in exclusion list.
Why artifactId which is mentioned in exclusions is part of war file?
How can I make sure that xml-apis-1.0.b2.jar is not part of war the file?
Any help is highly appreciable.
Looking at maven dependency description in maven repo, I do not see any transitive dependency for antlr.
So this means the retrieved dependencies for xml-apis is coming from some other dependency in your project. Please check if this is the case.

Use transitive dependencies and exclusions with Maven

I have this maven hierachy :
sim-java
ejb
web
log4j
...
ejb, web and log4j are modules of sim-java and each of these modules refer to sim-java by parent tag.
I would like to create a log4j module and include it as dependency in sim-java so log4j will be present as dependency in ejb and web modules.
Basically, my pom.xml inside sim-java contains this :
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
(scope is provided as I have an ear module which will include com.sim:log4j in ear file).
Now, my pom.xml inside my log4j module is this one :
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
I have this build error :
30/10/12 18:56:07 CET: Build errors for log4j; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project log4j: Could not resolve dependencies for project com.sim:log4j:jar:0.0.1-SNAPSHOT: Could not find artifact com.sim:log4j:jar:0.0.1-SNAPSHOT
I thought that there was some dependency problem since sim-java use com.sim.log4j as transitive dependency, so I tested that inside log4j pom.xml :
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>sim-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
30/10/12 18:59:22 CET: [WARN] The POM for com.sim:log4j:jar:0.0.1-SNAPSHOT is missing, no dependency information available
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
30/10/12 18:59:22 CET: Missing artifact com.sim:log4j:jar:0.0.1-SNAPSHOT:provided
Perhaps including com.sim.log4j inside modules (ejb, web etc...) would work but I want to use transitive dependency via sim-java project.
How to do this please ?
Olivier
You cannot have the dependency on com.sim:log4j in the parent pom. That dependency will be inherited in the children meaning that com.sim:log4j will depend on itself.
Instead create a <dependencyManagement/> in the parent pom and then declare the use of com.sim:log4j in the children that needs it, here it is web and ejb.
Parent pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
Web and Ejb pom:
<dependencies>
<dependency>
<groupId>com.sim</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Edit
You can still have a transitive dependency by only having the dependency on the log4j module from the ejb project. The web project will then have a dependency on the ejb project and the log4j will be a transitive dependency.

Resources