Pls are there any Java libraries that can retrieve Maven dependencies from a POM file? Anything that does not require retrieving out put of a mvn command. Thanks
Asked
Active
Viewed 279 times
0
-
Try XML-parsing – nylanderDev Feb 13 '20 at 21:10
-
1Possible duplicate of: https://stackoverflow.com/questions/15598612/simplest-ivy-code-to-programmatically-retrieve-dependency-from-maven-central ? – aslary Feb 13 '20 at 21:45
2 Answers
0
Well, you should parse the pom.xml
with any xml parser of your choice.
Then construct the link to maven central repository by the following algorithm: 1. Each package in group id is translated to a folder: Example:
<groupId>org.foo.bar</groupId> ==> org/foo/bar
- Artifact name is also a folder and append it to the group id: Example:
<artifactId>some-artifact</artifactId> ==> org/foo/bar/some-artifact
- Version also becomes folder: Example:
<version>1.2.3</version> ==> org/foo/bar/some-artifact/1.2.3
- Now construct the jar name as "articatId-version.jar" and append it to the link.
- Prepend the repository and you'll get a full-working path.
Here is a real working example:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
Gets translated to:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/2.2.4.RELEASE/spring-boot-2.2.4.RELEASE.jar
As an alternative if you want some library that can work with dependencies don't want to call maven, take a look at Apache Ivy

Mark Bramnik
- 39,963
- 4
- 57
- 97
-1
Thanks.
I used the MavenProject library. Pretty straight forward. I also used MavenXppReader to get the model that I passed to MavenProject(). The rest was a matter of calling the right methods.

Milton C. Ezeh
- 29
- 1
- 3