Class MavenLibraryResolver
- All Implemented Interfaces:
ClassPathLibrary
Plugins may create and configure a MavenLibraryResolver
by creating a new one and registering both
a dependency artifact that should be resolved to a library at runtime and the repository it is found in.
An example of this would be the inclusion of the jooq library for typesafe SQL queries:
MavenLibraryResolver resolver = new MavenLibraryResolver();
resolver.addDependency(new Dependency(new DefaultArtifact("org.jooq:jooq:3.17.7"), null));
resolver.addRepository(new RemoteRepository.Builder(
"central", "default", MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR
).build());
Plugins may create and register a MavenLibraryResolver
after configuring it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default Maven Central mirror, configurable through thePAPER_DEFAULT_CENTRAL_REPOSITORY
environment variable. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDependency
(Dependency dependency) Adds the provided dependency to the library resolver.void
addRepository
(RemoteRepository remoteRepository) Adds the provided repository to the library resolver.void
register
(LibraryStore store) Resolves the provided dependencies and adds them to the library store.
-
Field Details
-
MAVEN_CENTRAL_DEFAULT_MIRROR
The default Maven Central mirror, configurable through thePAPER_DEFAULT_CENTRAL_REPOSITORY
environment variable. Use this instead of Maven Central directly when you do not have your own mirror, as using Maven Central as a CDN is against the Maven Central Terms of Service, and you will cause users to hit rate limits.This repository is also used by the legacy
LibraryLoader
.
-
-
Constructor Details
-
MavenLibraryResolver
public MavenLibraryResolver()Creates a new maven library resolver instance.The created instance will use the servers
libraries
folder to cache fetched libraries in. Notably, the resolver is created without any repository, not even maven central. It is hence crucial that plugins which aim to use this api register all required repositories before submitting theMavenLibraryResolver
to thePluginClasspathBuilder
.
-
-
Method Details
-
addDependency
Adds the provided dependency to the library resolver. The artifact from the first valid repository matching the passed dependency will be chosen.- Parameters:
dependency
- the definition of the dependency the maven library resolver should resolve when running- See Also:
-
addRepository
Adds the provided repository to the library resolver. The order in which these are added does matter, as dependency resolving will start at the first added repository.- Parameters:
remoteRepository
- the configuration that defines the maven repository this library resolver should fetch dependencies from
-
register
Resolves the provided dependencies and adds them to the library store.- Specified by:
register
in interfaceClassPathLibrary
- Parameters:
store
- the library store the then resolved and downloaded dependencies are registered into- Throws:
LibraryLoadingException
- if resolving a dependency failed
-