CDI Plugin Utilities

Provides an abstract Mojo that enables CDI-based dependency injection for Maven Plugins.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.itemis.maven.plugins
ArtifactId

ArtifactId

cdi-plugin-utils
Last Version

Last Version

3.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

CDI Plugin Utilities
Provides an abstract Mojo that enables CDI-based dependency injection for Maven Plugins.
Project URL

Project URL

https://github.com/shillner/maven-cdi-plugin-utils
Project Organization

Project Organization

itemis AG
Source Code Management

Source Code Management

https://github.com/shillner/maven-cdi-plugin-utils

Download cdi-plugin-utils

How to add to project

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

Dependencies

compile (14)

Group / Artifact Type Version
org.eclipse.aether : aether-api jar 1.0.2.v20150114
org.eclipse.aether : aether-impl jar 1.0.2.v20150114
de.vandermeer : asciitable jar 0.2.5
javax.enterprise : cdi-api jar 1.2
com.google.guava : guava jar 19.0
javax.inject : javax.inject jar 1
junit : junit jar 4.12
org.apache.maven : maven-core jar 3.2.1
org.apache.maven : maven-model jar 3.2.1
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4
org.apache.maven : maven-plugin-api jar 3.2.1
org.apache.maven : maven-settings jar 3.2.1
org.slf4j : slf4j-simple jar 1.7.21
org.jboss.weld.se : weld-se jar 2.3.3.Final

test (1)

Group / Artifact Type Version
com.tngtech.java : junit-dataprovider jar 1.10.3

Project Modules

There are no modules declared in this project.

CDI-based Dependency Injection for Maven Plugin Development

Maven Central

This small library enables the usage of CDI-based dependency injection in Apache Maven plugins which changes the way of implementing Maven plugins fundamentally.

Requirements

  • JDK 1.7 or higher
  • Apache Maven 3.x

The Idea Behind It

The explicit desire for dependency injection (DI) in Maven plugins came up during the development of the Unleash Maven Plugin. There it was necessary to dynamically inject an implementation of the ScmProvider interface into the provider registry that isn't even known at compile time. A second wish was to simply add those implementations as plugin dependencies when configuring the plugin for your project.

Since an examination of Maven's DI capabilities did not yield any satisfactory results, this project was brought to life. First there was only the need to enable DI for Maven plugins, without any technological preference. But fast the requirements became more concrete and the choice fell on CDI based on its reference implementation Weld. Here are some of the core requirements that led to the current concepts and implementation:

  • DI in general to decouple components
  • Classpath-based autowiring of components
  • Distributed feature implementation without having to grind parameters through hundreds of classes
  • Ensuring extensibility of the plugins based on this library
  • Safe execution of the various processing steps of the plugin with implicit rollback in case of an error

The Core Concepts

  • CDI-based dependency injection implemented using Weld SE
  • @Inject
  • Qualifiers, Alternatives
  • Producers
  • @PostConstruct, @PreDestroy
  • Events
  • Classpath-based autowiring
  • The plugin's classpath is automatically scanned for beans (plugin and plugin dependencies)
  • No need for declaring beans in any kind of descriptor or manually bind or wire beans
  • Workflow-based architecture
  • Plugins define a default workflow for each Mojo
  • Workflow consisting of several processing steps which results in much smaller and clearer feature implementations
  • Safe workflow processing
  • The plugin processes the workflow step by step
  • Steps can implement one or more rollback methods that are called under certain circumstances
  • If any workflow step fails with an exception all processed steps are rolled-back in their reverse order
  • Each step only needs to rollback its own changes
  • Extensibility by design
  • Classpath scanning enables you to add more processing steps or other implementations to the plugin dependencies
  • Overriding of the default workflow of a Mojo makes it possible to redefine the workflow, f.i. when embedding new steps

Further Information

For more detailed information about how to implement Maven plugins using this library please refer to the Project Wiki. There all concepts and their implementation as well as the general usage is explained in detail.

A reference plugin that bases on this library is available here: Unleash Maven Plugin This plugin provides f.i. an SCM provider API that is implemented in several external projects such as Unleash SCM Provider for Git. These provider implementations can then be added to the plugin dependencies in order to support other SCM types during processing.

A further project is available here: Maven CDI Processing hooks This project provides some additional processing step implementations that can be used to extend processing workflows by simply adding the library to the plugin dependencies and overriding the processing workflow.

Versions

Version
3.4.0
3.3.1
3.3.0
3.2.0
3.1.8
3.1.7
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.0
2.1.0
2.0.0
1.0.0