How to let maven resolve transitive dependency for local dependency - java

We have a project A which depends on project B which depends on library C. A and B are local projects while C is a public library in maven central repo.
pom.xml for A:
<name>ProjA/name>
...
<dependency>
<groupId>com.abc</groupId>
<artifactId>ProjB</artifactId>
<version>1.0</version>
</dependency>
pom.xml for B:
<name>ProjB/name>
...
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>C</artifactId>
<version>2.23.2</version>
</dependency>
When run mvn dependency:tree -Dverbose in A, it does not resolve the dependencies of B and such dependencies used in B is not shown in A's Maven Dependencies as well. This is fine for compilation but will fail in runtime because of NoClassDefFound error.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ProjA 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # ProjA ---
[INFO] com.abc.projA:jar:1.0
[INFO] +- com.abc.projB:jar:1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.326 s
[INFO] Finished at: 2016-09-15T16:29:49-07:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
Is there any way to let maven resolve transitive dependency for such local dependency as B?

I think the problem here is B does not exist in the local repo .m2
You need to run mvn install for B, to install the package into .m2 which can be picked up by A locally.
Then running mvn dependency:tree -Dverbose in A won't cause problem

Related

Maven - display-dependency-updates- list transitive dependency versions

I'd like to be able to see if any of the dependencies of my project - including transitive ones - have updates available.
Take the following 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.me</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</project>
When I run goal versions:display-dependency-updates I get:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------< org.me:test >-----------------------------
[INFO] Building test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.8.1:display-dependency-updates (default-cli) # test ---
[INFO] No dependencies in Dependencies have newer versions.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.939 s
[INFO] Finished at: 2022-01-12T17:09:39Z
[INFO] ------------------------------------------------------------------------
But when I run dependency:tree, I can now see:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # test ---
[INFO] org.me:test:jar:0.0.1-SNAPSHOT
[INFO] \- org.apache.poi:poi:jar:5.1.0:compile
[INFO] +- commons-codec:commons-codec:jar:1.15:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] +- commons-io:commons-io:jar:2.11.0:compile
[INFO] +- com.zaxxer:SparseBitSet:jar:1.2:compile
[INFO] \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
And an outdated version of log4j appears.
Is there a way of doing this that's not manual?
I've also tried dependency-updates-report with the processDependencyManagementTransitive option enabled (which is the default) and the transitive dependencies aren't listed.

Maven is not using dependency version specified in pom.xml

I have a project A, which has B and C dependencies.
The project B also depends on C.
In project A pom, I have:
<dependencyManagement>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>2</version>
</dependency>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>B</artifactId>
<version>BVERSION</version>
</dependency>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>2</version>
</dependency>
<dependencies>
In project B(version BVERSION), I have:
<dependencies>
<dependency>
<groupId>br.com.mygroup</groupId>
<artifactId>C</artifactId>
<version>1</version>
</dependency>
</dependencies>
I have added some methods in C dependency in version 2, but the code doesn't compile when I try to use the new methods. That is, I can't access the new methods. Project A is using version 1(which is inside project B) of C.
If I change the order of the import in project A pom from B, C to C, B, the code compiles, but at execution time a get java.lang.NoSuchMethodError error.
Shouldn't maven dependencyManagement deal with this problem and force project A to use version 2 of C? Does anyone have an idea of what I am getting wrong?
EDIT 1:
mvn dependency:tree returns the following:
[INFO] br.com.mygroup:A:1.0-SNAPSHOT
[INFO] +- br.com.mygroup:B:jar:BVERSION:compile
[INFO] +- br.com.mygroup:C:jar:2:compile
EDIT 2:
mvn dependency:list returns the following:
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< br.com.mygroup:A >---------------------
[INFO] Building A 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) # A ---
[INFO]
[INFO] The following files have been resolved:
[INFO] br.com.mygroup:B:jar:BVERSION:compile
[INFO] br.com.mygroup:C:jar:2:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.639 s
[INFO] Finished at: 2019-10-04T09:03:37-03:00
[INFO] ------------------------------------------------------------------------

maven install with generate POM still produces a POM not found error

mvn install:install-file -DgroupId=com.oracle
-DartifactId=ojdbc7 -Dfile=ojdbc7.jar -Dpackaging=jar -Dversion=12.1.0.2 -DgeneratePom=true
The installation succeeds...
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< XXXX:XXXX >----------------------------
[INFO] Building XXXX 18.2.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # XXXX ---
[INFO] Installing C:\Projects\XXXX-svn\trunk\XXXX\ojdbc7.jar to C:\Users\QXV0615\.m2\repository\com\oracle\ojdbc7\12.1.0.2\ojdbc7-12.1.0.2.jar
[INFO] Installing C:\Users\QXV0615\AppData\Local\Temp\mvninstall491035374333687338.pom to C:\Users\QXV0615\.m2\repository\com\oracle\ojdbc7\12.1.0.2\ojdbc7-12.1.0.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.096 s
[INFO] Finished at: 2018-07-06T07:30:13+02:00
[INFO] ------------------------------------------------------------------------
But then
mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< XXXX:XXXX >----------------------------
[INFO] Building XXXX 18.2.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[WARNING] The POM for com.oracle.jdbc:ojdbc7:jar:12.1.0.2 is missing, no dependency information available
[WARNING] The POM for com.ibm.mq:jms:jar:7.0.1.9 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.993 s
[INFO] Finished at: 2018-07-06T07:30:26+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project XXXX: Could not resolve dependencies for project XXXX:XXXX:war:18.2.0-SNAPSHOT: The following artifacts could not be resolved: com.oracle.jdbc:ojdbc7:jar:12.1.0.2, com.ibm.mq:jms:jar:7.0.1.9: Failure to find com.oracle.jdbc:ojdbc7:jar:12.1.0.2 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
The dependency is:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
Your project depends on
com.oracle.jdbc:ojdbc7:jar:12.1.0.2
and you are installing the JAR with -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2, so it will be installed as
com.oracle:ojdbc7:jar:12.1.0.2
Note that the Maven coordinates do not match, either you install the JAR with the first Maven coordinates or you make your project depend on the second Maven coordinates.

Maven Versions Plugin: versions:use-releases does nothing

I need change all snapshots dependency of my project before pass to release. I'm trying versions:use-releases from commandline mvn versions:use-releases, but it doesn't work for me. I'm using Nexus repository for releases and the releases versions are deployed correcly and with public access
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.efx.util</groupId>
<artifactId>efx-util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
When I execute: mvn versions:use-releases, it does nothing.
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-api ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-impl 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-impl ---
[INFO] Ignoring reactor dependency: com.efx.clientesocket:efx-clientesocket-api:jar:0.0.1-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building efx-clientesocket-conf 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:use-releases (default-cli) # efx-clientesocket-conf ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] efx-clientesocket .................................. SUCCESS [ 1.539 s]
[INFO] efx-clientesocket-api .............................. SUCCESS [ 0.031 s]
[INFO] efx-clientesocket-impl ............................. SUCCESS [ 0.016 s]
[INFO] efx-clientesocket-conf ............................. SUCCESS [ 0.015 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
However versions:display-dependency-updates detect the corresponding release
------------------------------------------------------------------------
[INFO] Building efx-clientesocket-conf 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-dependency-updates (default-cli) # efx-clientesocket-conf ---
[INFO] artifact junit:junit: checking for updates from nexus
[INFO] The following dependencies in Dependency Management have newer versions:
[INFO] com.efx.util:efx-util ................ 0.0.1-SNAPSHOT -> 1.0.0-RELEASE
[INFO] junit:junit ............................................. 4.11 -> 4.12
[INFO]
[INFO] ------------------------------------------------------------------------
And I'm also trying versions:use-last-releases as alternative and it goes OK. I'm using -Dincludes= in this case to avoid updating no-snapshot versions. But, I would like to use versions:use-releases to assure updating only all-snapshot versions and cover versions in property at once
Maven version I'm using is 3.3.1 the plugin version is 2.2
Someone have any idea why does not working??
1- versions:use-releases searches the pom for all -SNAPSHOT versions which have been released and replaces them with the corresponding release version.
com.efx.util:efx-util ................ 0.0.1-SNAPSHOT -> 1.0.0-RELEASE
This means efx-util-0.0.1-SNAPSHOT should have a corresponding Release efx-util-0.0.1-RELEASE or efx-util-0.0.1 (a released version of 0.0.1) otherwise it won't work. 1.0.0-RELEASE is not a corresponding release
2- versions:use-latest-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
In this case it's not restricted to the corresponding release of (0.0.1-SNAPSHOT). So the release may have a different version number (1.0.0-RELEASE).
hope this helps.

Dom4J IllegalAccessError - Seam on JBoss 7 deployment error

I'm migrating a legacy application to Maven (and hopefully later away from Seam). There already have been many hitches and glitches, AFAIK Seam is really fickle concerning dependency versions it will work with.
This latest error I can't figure out. So I have an EAR with my (EJB) Jar, a War and the Seam.jar, plus lib/ folder. Now I actually have Dom4J as a dependency with scope=provided, since JBoss AS 7.1 provides version 1.6.1. It gets included into lib/ anyway, which I haven't figured out why yet.
But I get the same error when deleting all superfluous jars from lib/.
Just to reiterate, this application was running before, when built with the Ant build files. The Maven produced EAR won't deploy though. I have heard about similar errors (but not the exact same) with dependencies doubled in the classpath. I have checked (after removing it from lib/) and there should be none but the one in JBoss' modules.
Update: POM structure:
Super-POM is parent of all modules, has DependencyManagement and also contains modules (for now).
Modules: Core-ejb has code and tons of dependencies, mostly with provided since they are in JBoss/modules. Core-web produces WAR, has dep on Core-EJB. Project-Web includes Core-Web, Project-EJB depends on Core-EJB and uses shade-plugin to merge them together (!).
Core-EAR generates ear from shaded-project-ejb and project-web.
(Structure is crazy, but dictated by legacy app).
12:42:37,694 INFO [javax.servlet.ServletContextListener] (MSC service thread 1-6) Welcome to Seam 2.3.1.Final
12:42:38,745 INFO [org.jboss.seam.init.Initialization] (MSC service thread 1-6) reading /WEB-INF/components.xml
12:42:38,749 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (MSC service thread 1-6) Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener: java.lang.IllegalAccessError: tried to access class org.dom4j.io.SAXHelper from class org.dom4j.io.SAXReader
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894) [dom4j-1.6.1.jar:1.6.1]
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715) [dom4j-1.6.1.jar:1.6.1]
at org.dom4j.io.SAXReader.read(SAXReader.java:435) [dom4j-1.6.1.jar:1.6.1]
at org.dom4j.io.SAXReader.read(SAXReader.java:343) [dom4j-1.6.1.jar:1.6.1]
at org.jboss.seam.util.XML.getRootElement(XML.java:24) [jboss-seam-2.3.1.Final.jar:2.3.1.Final]
at org.jboss.seam.init.Initialization.initComponentsFromXmlDocument(Initialization.java:227) [jboss-seam-2.3.1.Final.jar:2.3.1.Final]
at org.jboss.seam.init.Initialization.create(Initialization.java:133) [jboss-seam-2.3.1.Final.jar:2.3.1.Final]
at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36) [jboss-seam-2.3.1.Final.jar:2.3.1.Final]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80]
mvn dependency:tree output, after cleanin up one mistake (but same error still):
[INFO] ------------------------------------------------------------------------
[INFO] Building Core Framework 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # Core ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Core EJB module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # Core-ejb ---
[INFO] com.mycomp:Core-ejb:ejb:1.0-SNAPSHOT
[INFO] +- org.hibernate:hibernate-core:jar:4.2.0.Final:provided
[INFO] | \- (dom4j:dom4j:jar:1.6.1:provided - omitted for duplicate)
[INFO] +- dom4j:dom4j:jar:1.6.1:provided
[INFO] \- org.jdom:jdom:jar:1.1.2:provided
[INFO] \- jaxen:jaxen:jar:1.1.3:provided
[INFO] \- (dom4j:dom4j:jar:1.6.1:provided - omitted for duplicate)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Core Web module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # Core-web ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Project EJB module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # project-ejb ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Project Web module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # project-web ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Core EAR module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) # Core-ear ---
[WARNING] Using Maven 2 dependency tree to get verbose output, which may be inconsistent with actual Maven 3 resolution
core-ear POM:
...
<dependencies>
<!-- project specific dependencies -->
<dependency>
<groupId>com.mycomp</groupId>
<artifactId>project-web</artifactId>
<version>${logis.artifact.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.mycomp</groupId>
<artifactId>project-ejb</artifactId>
<version>${logis.artifact.version}</version>
<type>ejb</type>
</dependency>
<!-- Seam dependency -->
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- Tell Maven we are using Java EE 6 -->
<version>6</version>
<!-- Use Java EE ear libraries as needed. Java EE ear libraries are
in easy way to package any libraries needed in the ear, and automatically
have any modules (EJB-JARs and WARs) use them -->
<defaultLibBundleDir>lib</defaultLibBundleDir>
<!-- See maven docs; Necessary because we CAN'T have 2 jboss-seam.jars
in the same EAR -->
<skinnyWars>true</skinnyWars>
<initializeInOrder>true</initializeInOrder>
<modules>
<!-- Explicitly excluding core framework artifacts, as they get merged
(shaded) into the project artifacts -->
<ejbModule>
<groupId>com.mycomp</groupId>
<artifactId>core-ejb</artifactId>
<excluded>true</excluded>
</ejbModule>
<!-- <webModule>
<groupId>com.mycomp</groupId>
<artifactId>core-web</artifactId>
<excluded>true</excluded>
</webModule> -->
<!-- Project specific part -->
<ejbModule>
<groupId>com.mycomp</groupId>
<artifactId>project-ejb</artifactId>
<!-- Manually set jar name, because many JndiNames in logis hard-code
that name -->
<bundleFileName>core.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>com.mycomp</groupId>
<artifactId>project-web</artifactId>
<contextRoot>/</contextRoot>
</webModule>
<!-- Need to include Seam as a module so it will be "executed" and
can initialize itself -->
<jarModule>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
<bundleDir>/</bundleDir>
</jarModule>
</modules>
</configuration>
</plugin>
...
It looks like it was some conflict with multiple versions on the classpath anyway.
There was a company specific module, which was just a bunch of jars rolled into one module. After making sure, that only one jdom-*.jar was on the path, it worked.

Categories

Resources