microBean™ Maven CDI


License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

org.microbean
ArtifactId

ArtifactId

microbean-maven-cdi
Last Version

Last Version

0.4.3
Release Date

Release Date

Type

Type

jar
Description

Description

microBean™ Maven CDI
microBean™ Maven CDI
Project URL

Project URL

http://microbean.github.io/microbean-maven-cdi
Project Organization

Project Organization

microBean™
Source Code Management

Source Code Management

https://github.com/microbean/microbean-maven-cdi/

Download microbean-maven-cdi

How to add to project

<!-- https://jarcasting.com/artifacts/org.microbean/microbean-maven-cdi/ -->
<dependency>
    <groupId>org.microbean</groupId>
    <artifactId>microbean-maven-cdi</artifactId>
    <version>0.4.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.microbean/microbean-maven-cdi/
implementation 'org.microbean:microbean-maven-cdi:0.4.3'
// https://jarcasting.com/artifacts/org.microbean/microbean-maven-cdi/
implementation ("org.microbean:microbean-maven-cdi:0.4.3")
'org.microbean:microbean-maven-cdi:jar:0.4.3'
<dependency org="org.microbean" name="microbean-maven-cdi" rev="0.4.3">
  <artifact name="microbean-maven-cdi" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.microbean', module='microbean-maven-cdi', version='0.4.3')
)
libraryDependencies += "org.microbean" % "microbean-maven-cdi" % "0.4.3"
[org.microbean/microbean-maven-cdi "0.4.3"]

Dependencies

compile (10)

Group / Artifact Type Version
org.apache.maven : maven-model-builder jar 3.6.3
org.apache.maven : maven-resolver-provider jar 3.6.3
org.apache.maven : maven-settings jar 3.6.3
org.apache.maven : maven-settings-builder jar 3.6.3
org.apache.maven.resolver : maven-resolver-api jar 1.4.1
org.apache.maven.resolver : maven-resolver-connector-basic jar 1.4.1
org.apache.maven.resolver : maven-resolver-transport-file jar 1.4.1
org.apache.maven.resolver : maven-resolver-transport-http jar 1.4.1
org.apache.maven.resolver : maven-resolver-util jar 1.4.1
org.yaml : snakeyaml jar 1.25

provided (1)

Group / Artifact Type Version
org.microbean : microbean-base-specification pom 0.5.0

test (2)

Group / Artifact Type Version
org.microbean : microbean-weld-se-environment pom 0.7.0
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

microBean™ Maven CDI

Build Status Maven Central

The microBean™ Maven CDI project embeds the Maven machinery responsible for interacting with artifact repositories into your CDI 2.0 environment.

Background and History

The internal Maven machinery for interacting with artifact repositories has gone through several phases of existence.

Its earliest incarnation is in the form of the maven-artifact-resolver artifact, version 1.0, circa 2009 (here in 2019 this artifact should not be used).

This code was subsequently broken out as a standalone project into Sonatype's Æther project in August 2010.

Sonatype Æther then moved to the Eclipse foundation in August 2014, but never really caught on as a standalone project outside of its original Maven-oriented user base, and was archived in January 2015.

The Sonatype Æther project was handed back to the Maven project and reincarnated as the Maven Artifact Resolver project in January 2017, with an overarching artifact identifier of maven-resolver (not maven-artifact-resolver). Somewhat oddly, the package names have not changed, so the classes provided by the maven-resolver project all start with the org.eclipse.aether. prefix.

This project adapts the maven-resolver project to CDI environments.

Installation

Place this project's .jar file on your classpath.

How It Works

The maven-resolver project fortunately was written with dependency injection in mind. Specifically, it was written as a Guice module to be used from within Maven proper, which, at least in recent versions, uses Guice under the covers.

The microBean™ Maven CDI project does just enough work to re-express certain Maven Guice components using CDI constructs so that you may simply inject the parts of maven-resolver that you need.

For example, to work with artifact repositories, you're going to need a RepositorySystem and a RepositorySystemSession. With microBean™ Maven CDI, you simply do this:

@Inject
private RepositorySystem repositorySystem;

@Inject
private RepositorySystemSession repositorySystemSession;

…and the MavenExtension portable extension takes care of setting up the dozens of supporting objects for you behind the scenes.

microBean™ Maven CDI also natively understands your user-level ~/.m2/settings.xml file, and can use it so that you can inject the right remote repositories, even taking its local repository and mirrors settings into consideration:

@Inject
@Resolution // for dependency resolution, as opposed to, say, deployment
private List<RemoteRepository> remoteRepositories;

Usage

Here is some pseudocode showing how you might go about resolving the (arbitrarily chosen for this example) org.slf4j:slf4j-api:1.7.24 artifact from within your CDI bean:

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RepositorySystem;

import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;

import org.eclipse.aether.collection.CollectRequest;

import org.eclipse.aether.repository.RemoteRepository;

import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.resolution.DependencyResult;

import org.eclipse.aether.util.artifact.JavaScopes;

import org.eclipse.aether.util.filter.DependencyFilterUtils;

@Inject
private RepositorySystem repositorySystem;

@Inject
private RepositorySystemSession session;

@Inject
@Resolution
private List<RemoteRepository> remoteRepositories;

public void resolve() throws DependencyResolutionException {
  final CollectRequest collectRequest = new CollectRequest();
  final Artifact artifact = new DefaultArtifact("org.slf4j", "slf4j-api", "jar", "1.7.24");
  collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
  collectRequest.setRepositories(remoteRepositories);

  final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE));
  final DependencyResult dependencyResult = repositorySystem.resolveDependencies(session, dependencyRequest);
  final List<ArtifactResult> artifactResults = dependencyResult.getArtifactResults();
}
org.microbean

microBean™

At the intersection of Java, Kubernetes and the enterprise.

Versions

Version
0.4.3
0.4.2
0.4.0
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.3
0.1.2
0.1.0