APIs for reading Maven repositories

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

APIs for reading Maven repositories

Elliotte Rusty Harold
I'm working on code that is **not** in a Maven plugin (e.g. Gradle
plugin or other tools) but that needs to interact with the Maven
repository system. Typically this is what the maven artifact resolver
is for:

https://maven.apache.org/resolver/index.html

Mostly I've figured out how to use this. However I have a couple of
warts I'd like to clean up.

1. Is there an API somewhere for locating the local maven repository
that is often but not always stored in ~/.m2/repository?

2. Is it possible to boostrap the resolver without using the internal
class MavenRepositorySystemUtils?

https://issues.apache.org/jira/browse/MNG-6579

Thoughts?

--
Elliotte Rusty Harold
[hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: APIs for reading Maven repositories

Mickael Istria-2
On Mon, May 4, 2020 at 4:10 PM Elliotte Rusty Harold <[hidden email]>
wrote:

> 1. Is there an API somewhere for locating the local maven repository
> that is often but not always stored in ~/.m2/repository?
>

I didn't find a good code for that. It looks like MavenCli and related
classes are doing most of the job, but they're not so useful as API because
a lot of their goodness is private.
See how we do it in LemMinX-Maven in the meantime: reading settings, then
fallback to system property, then fallback to default location:
https://github.com/eclipse/lemminx-maven/blob/master/lemminx-maven/src/main/java/org/eclipse/lemminx/maven/MavenPlugin.java#L117...L129

2. Is it possible to boostrap the resolver without using the internal
> class MavenRepositorySystemUtils?


If you need a RepositorySystemSession, best seems to be creatin a
MavenExecutionRequest, and then
`container.lookup(DefaultRepositorySystemSessionFactory.class).newRepositorySession(mavenRequest)`.

This is what's used both by Eclipse m2e and LemMinX-Maven, with some
success.
Reply | Threaded
Open this post in threaded view
|

Re: APIs for reading Maven repositories

Manfred Moser-4
In reply to this post by Elliotte Rusty Harold


Elliotte Rusty Harold wrote on 2020-05-04 07:02 (GMT -07:00):


> 2. Is it possible to boostrap the resolver without using the internal
> class MavenRepositorySystemUtils?
>
> https://issues.apache.org/jira/browse/MNG-6579
>

I am using the resolver in my Maven Repository Provisioner and bootstrap it without ..

https://github.com/simpligility/maven-repository-tools/tree/master/maven-repository-provisioner

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]