How to do mvn dependency:tree for an uber jar? - java

I am analysing a repo to determine all the dependencies, mvn dependency:tree -V works great for this. A particular repo includes an unshaded uber jar where all the dependency jars have been unpacked & repacked into a single jar.
Running mvn dependency:tree -V on this repo does not list the nested dependencies in the uber jar.
Looking at the uber jar pom it is not conclusive since the dependencies listed pull in other dependencies (which is where mvn dependency:tree -V is otherwise great).
Any ideas on how I can see all the dependencies (including versions) used in the uber jar since mvn dependency:tree -V does not work for it?

It turns out that mvn dependency:tree -V does not go inside the uber jar. I needed to go to the repo for the uber jar and do a *mvn dependency:tree -V
* there.

Related

Why is this jar on my classpath in a maven project?

I have a maven project with some dependencies, and the resulting artifact contains the dependencies as .jar files inside.
I could check the effective pom, but that does not show the actual .jar filenames / classes for the dependencies.
Is there any way to print dependency .jar names?
Is the name always ${artifactId}-${version}.jar?
You can view the dependencies used in a Maven build with the Maven Dependency Plugin. To view the dependencies as a list, use:
mvn dependency:list
A better representation might be the dependency tree, though, as it clearly shows relationships between imported dependency POMs and transitive dependencies:
mvn dependency:tree
If you want to see a raw list of the JARs bundled together in your build, you can also use the dependency plugin's copy-dependencies goal:
$ mvn dependency:copy-dependencies -DoutputDirectory="\${project.builddir}/bundled-jars"
$ ls -1 target/bundled-jars
Note that the destination is in quotes with the $ escaped so that it can use the Maven property without invoking shell substitution. You could also just write -DoutputDirectory=target/bundled-jars.

maven deploying 3rd pom's without jar to nexus repository

When I want to deploy 3rd jars to my nexus 3 repository I use this command:
mvn deploy:deploy-file
-Dfile=<path-to-jar>
-DpomFile=<path-to-pom>
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml>
-Durl=<url-of-the-repository-to-deploy>
but this command works only on jars with pom, and there is many artifacts that have only pom without jar, so i am looking for a way to deploy only pom without a jar file. My maven version is 3.3.9
mvn deploy:deploy-file
-DgroupId=com.xxx.xxx.xxxx
-DartifactId=xxxxx
-Dversion=x.x.x
-DgeneratePom=false
-DrepositoryId=nexus
-Dpackaging=pom
-Dfile=D:/xxx/xxxxx-x.x.x.pom
-DpomFile=D:/xxx/xxxxx-x.x.x.pom
-Durl=http://xxx.xx.xx.xx:8081/repository/thirdparty
-Dfile, is mandatory for Maven deploy-file. Therefore you have to specify a file.
In this case, you can point the same pom file for both -DpomFile and -Dfile.
This works in Nexus OSS version 3.23.0-03 with Maven 3.5.2

list maven modules dependent on another maven module

How to list all maven modules dependent on another maven module (either directly or indirectly?
For example, mvn -pl :moduleX -amd install actually installs moduleX and all other modules that are dependent on it. What I need is to only list the other modules without any further processing.
mvn dependency:tree (as tunaki said)
mvn dependency:tree -Dverbose
If you want to display conflicting dependencies that were omitted from the resolved dependency tree.
mvn dependency:tree -Dverbose -Dincludes=commons-collections
If you want to specifically see the dependency tree parts involving Commons Collections (for example).

Using third party lib with maven

I'm trying to use Synthetica library with maven but I failed.
There are 2 different jar file I need to import. First one is synthetica.jar and the other one is syntheticablackeye.jar.
I tried mvn install:install-file but it didn't solve the problem.
I can use them with eclipse but currently I do not use any IDE like eclipse also I'm on linux.
Steps I have done:
(This is for synthetica.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/synthetica.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
(This is for syntheticaBlackEye.jar)
mvn install:install-file -Dfile=~/Dropbox/github/ChatAppServer/syntheticaBlackEye.jar -DgroupId=de.javasoft.plaf -DartifactId=synthetica -Dversion=1.0.0 -Dpackaging=jar
the problem is how should I add dependency when the to jar files file structers are same?
I did these and It worked fine but when I check local mvn repos in my pc(.m2/repo/) there were no jar files. synthetica and syntheticablackeye file structers are same is this a problem? If it is what can I do?
What am I missing?
Edit: When I change artifactId and groupId maven trying to download jar files but they are in local repo?
You have not supplied any details about any errors you are getting or what command you used exactly to install the JARs, so it is hard to know what exactly is not working.
You can install 3rd party JAR files in your local Maven repository with a command like this (see also Maven's Guide to installing 3rd party JARs):
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id>
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
For example:
mvn install:install-file -Dfile=synthetica.jar -DgroupId=com.synthetica
-DartifactId=synthetica -Dversion=1.0 -Dpackaging=jar
Then you refer to it in the pom.xml of your project with the same Maven coordinates:
<dependency>
<groupId>com.synthetica</groupId>
<artifactId>synthetica</artifactId>
<version>1.0</version>
</dependency>
edit - Do not use the same groupId, artifactId and version for both JAR files, otherwise Maven cannot tell them apart.

mvn dependency:tree does not list dependencies of a dependency

I have a project that has a dependency, say X.jar, which has its own dependency Y.jar. When I include X.jar as a dependency in my project I expect that all the dependencies of X.jar be available to me in my project.
Indeed this is the case with other dependencies. When I run mvn dependency:tree it lists dependencies and their dependencies as expected but it fails to list any dependencies for X.jar.
X.jar is a custom jar from a project I wrote (I have indeed added X.jar to the local repo) so perhaps the problem lies there. When I run mvn dependency:tree on the X project it lists all dependencies correctly.
I have no idea how to debug this and any help would be appreciated.
The problem is probably that the pom.xml of your X.jar is not properly installed in your repository.
When you install a jar "by hand" in your repo :use the option -DpomFile="<path_to_your_pom>" .
If you don't do that : maven will create (and install !!!) an ultra-simple pom.xml for you (and of course it don't contains any data about dependencies).
More about installing a custom jar here

Categories