0

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

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135

2 Answers2

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
  1. Artifact name is also a folder and append it to the group id: Example:
<artifactId>some-artifact</artifactId> ==>  org/foo/bar/some-artifact
  1. Version also becomes folder: Example:
<version>1.2.3</version> ==>  org/foo/bar/some-artifact/1.2.3
  1. Now construct the jar name as "articatId-version.jar" and append it to the link.
  2. 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.