list maven modules dependent on another maven module - java

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).

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.

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

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.

Where to run mvn versions:set for a multi-module project (with aggregator)? [duplicate]

I have Maven multi-module project and I would like to update the development versions to a given value using a script. The aggregator POM is only an aggregator and the children do not inherit from it. This is important because the artifacts all inherit from other POM files. Here is my structure
aggregator/
--projectA
--projectB
Also, projectB has a Maven dependency on projectA.
First I tried:
mvn -DnewVersion=0.28-SNAPSHOT -DupdateMatchingVersions=true versions:set
It only updated the aggregator project's version.
If I run the Maven release process, it correctly updates projectB's dependency on projectA to use the new development version after the release build. Because the release process handles this well, I thought that using the release plugin might solve my issue.
So I tried the following:
mvn -DdevelopmentVersion=0.28-SNAPSHOT -DautoVersionSubmodules=true --batch-mode release:update-versions
This updated all of my sub-projects correctly. However it did not update projectB's dependency version for projectA.
What is a simple way to update all the development versions in my project, including projectB's dependency on projectA?
You may have more luck with the release plugin but it may require some tweaking
versions:set is designed to update the version of the pom that it executes against... ie the root of the reactor.
If you follow it's conventions, then it will work... But you need to know its conventions.
When you have /project/parent/version and /project/version both specified but "accidentally" at the same value, the versions plugin assumes that the two versions are just accidentally the same, and so does not update the child project's version when the parent version is being updated. updateMatchingVersions tells the plugin to assume that it us not an accident and that the child should be in lock step.
If you only specify /project/parent/version and leave the project version unspecified, therefore relying on inheritance, the plugin will add the child project to the list of version changes (and hence loop through all the projects again to ensure it catches any additional required changes)
The versions plugin does not currently provide an option to force everything to the one version... Though that might be a good idea.
You can get what you want with three commands, eg
mvn versions:set -DnewVersion=...
cd projectA
mvn versions:set -DnewVersion=...
cd ../projectB
mvn versions:set -DnewVersion=...
This is because versions:set will attempt to "grow" the reactor if the parent directory contains an aggregator pom that references the invoked project...
In other words when you have a reactor with no common parent, versions assumes that the common version number is by accident, but it will pick up the intent from the wider reactor
# for each module into aggregator pom
for module in $(grep "\<module\>" pom.xml | sed 's/<\/module>//g' | sed 's/.*<module>//g' | sed 's/.*\///g')
do
# set the version of the module
# and update reference to this module into others modules
mvn versions:set -DgenerateBackupPoms=false -DartifactId=$module \
-DnewVersion=$newVersion -DupdateMatchingVersions=true
done
# set the version of the aggregator pom
mvn versions:set versions:commit -DnewVersion=$newVersion
i found your same problem ,then i clone versions plugin code , then I found if you set gropuId,artifcatId,oldVersion value tobe * will solve the problem;
like this :
mvn versions:set -DnewVersion=xxx -DgroupId=* -DartifactId=* -DoldVersion=*

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

How to find out why a jar was included by Maven?

We're using Maven 3 with IntelliJ for our IDE. After a compile we get a bunch of spring 2.0 stuff being included in the External Libraries. If I look through Maven Projects dependencies in Intellij I don't see anyone with a dependency on spring 2.0 so I suspect it's something we're depending on which depends on it.
My question is how would I track this down? I tried doing a mvn dependency:tree -Dverbose -Dincludes=spring-aop and even -Dincludes=spring but get no results when ran from the root or a sub module directory that I know is using spring.
It looks like the pattern passed to -Dincludes is incorrect.
From the documentation of Maven Dependency Plugin, the syntax of -Dincludes is defined by StrictPatternIncludesArtifactFilter. From the javadoc of AbstractStrictPatternArtifactFilter from which this is subclassed,
The artifact pattern syntax is of the
form:
[groupId]:[artifactId]:[type]:[version]
Where each pattern segment is optional and supports full and
partial * wildcards. An empty pattern
segment is treated as an implicit
wildcard.
For example, org.apache.* would match all artifacts whose group
id started with org.apache., and :::*-SNAPSHOT would match all snapshot
artifacts.
Maybe you should run mvn dependency:tree without -Dincludes and see if it shows up the spring 2.0 related dependency. Alternately, specify the appropriate pattern for -Dincludes.
The format you are searching for is wrong. Try this:
mvn dependency:tree -Dverbose -Dincludes=:spring*::
(Searches for any artifact with a groupId that starts with spring)
Or this:
mvn dependency:tree -Dverbose -Dincludes=org.springframework
(Searches for any artifact with artifactId org.springframework)
Why not use intellij and easy fix it.
Open your pom.xml, right-click (invoke context menu) and choose UML > show dependencies (assumin you have UML plugin enabled).
Idea will mark all duplicate dependency and you can use ALT+Enter combo to exclude dependencies.
#see also:
http://blogs.jetbrains.com/idea/2010/05/maven-dependencies-diagram/

Categories