Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aether-users] How to create custom provider ?

David Bernard wrote:

Context :
I try to create a script (java, scala, ...) runner. The script include info
about dependencies + repositories. I used aether to download artifact from
maven repository and to create the classpath.
Now I would like the script to be able to use other script from local fs or
http (gist, github, ...) . I imagine to use aether to manage dependency
script (recursively) : download, cache (script and build).

I imagine to create a Custom provider to provide :
* Metadata extracted from the script (I don't plan to use pom.xml for
script)
* Artifact (jar or directory) result of script's compiler (compilation done
on demand)
* May be a local repository to store/cache

Questions :

1. Is it a correct usage of aether ?

The one thing that would be a problem is trying to store directories in the local repositories, I mean artifacts are supposed to be a single file (i.e. Artifact.getFile()) and I'm pretty sure existing code will fail if you tried passing in directories instead. Besides that, Aether seems fitting for your requirements.

2. Can I manage dependencies from a maven provider AND from a custom
provider ? Should they share the local repository ?

IIUC, what you refer to as "provider" is what Aether calls an ArtifactDecriptorReader, i.e. the component which tells about the dependencies of a given artifact. That interface exists to allow clients to plug in their own artifact descriptor reader which then allows to read dependencies from whatever metadata file one desires.

The "maven provider" is realized by org.apache.maven.repository.internal.DefaultArtifactDescriptorReader from org.apache.maven:maven-aether-provider. You should be able to craft your own provider that delegates to the maven one if needed and otherwise reads dependency data from your script format.

I don't see a reason why you can't share the local repository. So Maven uses foo-1.pom to describe dependencies, you use bar-1.yourscript, those files can peacefully coexist in the same local repo. For example, there is a Maven plugin called Tycho which supports building Eclipse plugins with Maven and relies mostly on p2 for dependency resolution. The artifacts and metadata fetched by p2 are cached in the same local repository without affecting ordinary Maven usage.

3. How to create a custom provider and to use/register it ?

You essentially have to implement the ArtifactDescriptorReader interface. I suggest to take a look at the existing impl from Maven, especially the method loadPom(). In a nutshell, the steps to perform are

a) Given coordinates for some artifact like gid:aid:1:jar, derive the coordinates of the metadata file describing its dependencies, e.g. gid:aid:1:pom
b) Use the version/artifact resolver to fetch that metadata file
c) Parse the metadata file
d) Convert data from the metadata file into Aether's domain objects

Regarding registering it, that depends on how you initialize Aether in the first place. Say you use the lightweight DefaultServiceLocator class, then you would do

serviceLocator.setService( ArtifactDescriptorReader.class, YourImpl.class)

before calling serviceLocator.getService(RepositorySystem.class).

4. Should I use "SNAPSHOT" or WorkspaceRepository for scripts in local file
system ?

Not sure I follow, "SNAPSHOT" refers to versioning, WorkspaceRepository to some storage, these are quite different things.

A WorkspaceRepository is read-only as far as Aether is concerned, so you can't install/deploy things in there. If that matches your idea, then it's an option. It's especially interesting if you would like to keep your scripts separate from the local repo used to cache the artifacts themselves.

I can't say much more for now without knowning more details about your intended use cases.


Benjamin


Back to the top