I have to create a new maven project old projects migrated to maven. So I got a structure like this
parent
|
\-- project 1
|
\-- project 2
project 1
and project 2
have tons of dependencies and lots of them are common to each other. What I wonder, and I couldn't find in the internet, is if there is a tool that I can find these common dependencies so I can migrate them to the parent pom?
For examplo, if I provide to this tool two poms with elements like
... PROJECT 1 POM
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifcatId>A</artifactId>
<version>1.0.0</artifactId>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifcatId>B</artifactId>
<version>1.0.0</artifactId>
</dependency>
</dependencies>
...
.. PROJECT 2 POM
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifcatId>B</artifactId>
<version>1.0.0</artifactId>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifcatId>C</artifactId>
<version>1.0.0</artifactId>
</dependency>
</dependencies>
...
I want the output to be
.. OUTPUT FROM COMPARING BOTH
<dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifcatId>B</artifactId>
<version>1.0.0</artifactId>
</dependency>
</dependencies>
...
In your project's POM, press Ctrl and hover the mouse over the dependency. Click the dependency to open the dependency's POM. In the dependency POM, view the active dependency, its transitive dependencies and their versions. You can check the origin from which the dependency was pulled in.
project. basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.
2. Maven's Multi-Module Project. A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom.
To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.
I don't know a tool that works like you described but there is a simple workaround:
Make a temporary third project and copy all dependencies from A and B to this pom. Than try to find duplicates with the dependency:analyze-duplicate dependency-plugin goal like this:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:analyze-duplicate
You will get something like this
[INFO] ------------------------------------------------------------------------
[INFO] Building foobar 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:analyze-duplicate (default-cli) @ foobar ---
[INFO] List of duplicate dependencies defined in <dependencies/> in your pom.xml:
o junit:junit:jar
To make sure that the duplicate really comes from both projects you should duplicate check the single projects on there own before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With