Maven Assembly Validation
A logging implementation story
Logging Implementations
- Abstraction
- Implementations
- Configuration
Abstraction
- We use SLF4J
- Different assemblies use different backing implementation
- Assemblies currently manage implementations
- Chef cookbooks manage implementation configuration
Implementation
- Concept servers use log4j implementation
- Write Back servers use JDK implementation
- Assemblies are responsible for managing the implementation JAR which can conflict with the configuration expectation
bridges: Directing abstractions to implementation
- jcl-over-slf4j
- jul-to-slf4j
- log4j-over-slf4j
Enforcing assemblies
enforce patterns in assemblies
- Write a Maven plugin
- Utilize maven-enforcer-plugin rules and write custom rules where needed
Write a Maven Plugin to do enforcement
- Ecosystem is not great
- Writing code for something that a plugin already supports
- It isn't a simple amount of code
From: http://maven.apache.org/plugin-developers/plugin-testing.html
Use maven-enforcer-plugin
- Has a large standard set of rules to support enforcement
- Is pluggable to write your own custom enforcement rules
- Configuration in POM can get intense
Maven-enforcer-plugin custom rules
- Custom rules are hosted in another JAR that the plugin references
- Requires additional configuration in the plugin to leverage
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>custom-rule</groupId>
<artifactId>custom-rule-sample</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
...
</plugin>
maven-enforcer-plugin
standard rules
All you have to do is copy/paste maven-enforcer-plugin configuration to each assembly project, right?
NO.
Copy/paste code in POMs is bad.
Composition
Rather than sharing through inheritance (parent POM), share through composition of a POM.
A POM can be built by referencing an artifact which composes settings of that POM.
Artifacts are shared vs. forcing inheritence / copy-paste patterns
inheritence
Parent POM which is defined that projects must reference to inherit its settings.
Painful and challenging to re-use code across POMs by requiring inheritance to achieve it.
Copy/paste is typically applied across parent POMs of reactor projects.
Maven tiles
- Compose POMs by injecting in configuration defined by a tile
- Share common configuration sections through tiles
- Consumers can reference a tile, and can specify version range to automatically take newer passive version changes: [1, 2)
Enforcer Tile
Compiler Tile
POM
https://github.com/repaint-io/maven-tiles
Maven tiles
- Tile project contains:
- pom.xml (assembly / release info for the tile)
- tile.xml: Hosts the snippet of the POM you want to integrate (ex. maven-enforcer-plugin settings)
- Side note: It appears that you don't want to reference SNAPSHOT versions of tiles in reactors, as modules can inherit the version it declares
- Reference tiles which are released (can test internally with a non-SNAPSHOT version)
Example
Referencing a Tile (parent POM of reactor)
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>${maventiles.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<filtering>true</filtering>
<tiles>
<tile>com.cerner.sync.ml:sync-ml-enforcer-plugin-tile:xml:1.0</tile>
</tiles>
</configuration>
</plugin>
Maven Assembly Validation
By Carl Chesser
Maven Assembly Validation
- 709