This is a maven plugin that allows for developers and organizations to ban Maven artifacts. We are keenly aware of the capability in the `maven-enforcer-plugin`. Instead of simply generating an error when a banned artifact is referenced, this plugin prevents the artifact from being downloaded as well. This is crucial within certain organizations with strict security scans that crawl the Maven cache.
## Usage
### Prevent Banned Artifacts
## Extension
Here is a pseudo-code example of all the options this plugin provides.
When using as an extension, it will enforce a ban on the configured dependencies and plugins and recursively their dependencies. See the snippet below for how the plugin should be declared in your project's `pom.xml`.
```xml
<project>
@@ -22,31 +20,7 @@ Here is a pseudo-code example of all the options this plugin provides.
@@ -57,60 +31,47 @@ Here is a pseudo-code example of all the options this plugin provides.
</project>
```
The `extensions` elements is critical. Without it, the plugin does nothing as far as banning artifacts/dependencies. With it, the plugin is able to not only detect banned artifacts, but do it before they are downloaded. This works with both dependencies and plugins. This keeps libraries from even reaching your local Maven repository cache.
The `extensions` elements is critical. Without it, the plugin does nothing as far as banning artifacts/dependencies. With it, the plugin is able to not only detect banned artifacts, but do it before they are downloaded. This keeps libraries from even reaching your local Maven repository cache.
### Purge Banned Artifacts
### Configuration
Here is an example of the non-extension use case for the plugin. You could use the same plugin for both preventing banned artifacts and cleaning up previously downloaded ones. Just set `extensions` to `true` in those cases, as highlighted in the previous section.
| Element | Description |
| ------------------- | ----------- |
| `import/file` | Import a ban configuration file from the project. |
| `import/url` | Import a ban configuration file from the URL. |
| `import/artifact` | Import a ban configuration file from the XML artifact of the specified artifact in the notation `groupId:artifactId:version`. |
| `includes/artifact` | Include the specified artifact and version(s) in the list of banned artifacts. See the section below on how to specify the `artifact` element. |
| `excludes/artifact` | Exclude the specified artifact and version(s) from the list of banned artifacts. See the section below on how to specify the `artifact` element. |
When specifying `artifact`, you can use any of the following formats. The example is of this library; just replace the values to match the artifacts you want to ban.
- Exact artifact; all versions: `com.inteligr8:ban-maven-plugin`
- Exact artifact; version range: `com.inteligr8:ban-maven-plugin:[,1.4.0)`
- All artifacts/versions in group: `org.springframework:`
- All artifacts in group; version range: `org.springframework::[,6.0.0)`
- All artifacts in group/subgroups; version range: `org.springframework.*::[,6.0.0)`
The same `artifact` element can use the long notation:
```xml
<project>
...
<build>
...
<plugins>
...
<plugin>
<artifact>
<groupId>com.inteligr8</groupId>
<artifactId>ban-maven-plugin</artifactId>
<version>...</version>
<configuration>
...
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>clean</phase>
<goals><goal>purge-repo</goal></goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
<version>[,1.4.0)</version>
</artifact>
```
The `purge-repo` goal will remove all banned artifacts from your local Maven cache. It does not support `groupIdRegex` or blank `groupId` specifications. So any of those will not be purged/removed.
For instance, you can use the following and expect it to work for preventing and purging banned dependencies and plugins:
It supports the use of regular expressions with `groupIdRegex` and `artifactIdRegex`.
If no `includes` are provided, then no artifacts will be banned. An *included* artifact is a banned artifact. An *excluded* artifact is not banned. It is the opposite of what you may think. If no `excludes` are provided, then no banned artifacts are granted an exception.
The `artifact` element supports the descriptive `groupId`/`artifactId`/`version` elements or the abbreviated colon-based notation. When using the colon-based notation, the group ID and artifact ID may be treated as `groupIdRegex` and `artifactIdRegex` (see below). If you only use acceptable `groupId` and `artifactId` characters (letters/numbers/dashes/underscores/dots), it will not. But if you include any other characters, like `\.` or `*`, then it will be treated as regex. How it is treated will impact the functionality of `purge-repo` goal, if you are using it.
@@ -127,9 +88,9 @@ If you *include* all versions by omitting the `version` element, you can still *
Order does not matter. All include specifications are processed, followed by all exclude specifications.
## Import
### Import
The `import` file, URL, and artifact are to reference XML files that conform to the same `configuration` element as described here. In fact, the root elmenet of that XML should be `configuration`. It will only support the `includes` and `excludes` elements. so you cannot do recursive imports.
The `import` file, URL, and artifact are to reference XML files that conform to the same `configuration` element as described here. In fact, the root element of that XML should be `configuration`. It will only support the `includes` and `excludes` elements. so you cannot do recursive imports.
You can create a Maven `pom` packaging type project that deploys a configuration XML to your Maven repository. Then use an `import` to allow you to change banned dependencies without making changes to each individual project. Just like with the `version` notation in the `includes` and `excludes` elements, your `import``artifact` element supports a version range. This way the latest banned dependencies can be side-loaded into all projects. This means previously functioning builds may eventually start failing. That is by design in this scenario.
@@ -137,7 +98,7 @@ The `import` elements supports multiple `url` or `artifact` declarations. All i
The `excludes` element is a way to provide project-by-project exceptions to imported banned artifacts where warranted.
## Examples
### Examples
The recommended use of this plugin is for its use across whole organizations. First, you will want a simple Maven project that is referenced by all other Maven projects. That simple project will declare the banned artifacts and potentially purge existing ones. See the `examples/ban-config` project for a full example.
@@ -168,3 +129,124 @@ Once you have that in place, you will want to add the following to every single
</configuration>
</plugin>
```
## Goals
Within a project, this is typically only used as an extension with no execution/goal. There is one goal for general execution though.
### `purge-repo`
This goal will purge the local Maven repository of banned artifacts. The most common use is without any real project, but Maven requires one to exist in the directory of execution. This executes in the `clean` phase by default.
This goal does **NOT support**`groupIdRegex` or blank `groupId` specifications. So any of those will be ignored not be purged/removed (if in `includes`).
#### Configuration
The configuration is identical to what is documented above. However, this table focuses on the properties available as you may not be defining this in a `pom.xml`.
| Element | Maven/Java Property |
| ------------------- | ------------------- |
| `import/file` | `ban.file` |
| `import/url` | `ban.url` |
| `import/artifact` | `ban.artifact` |
The following additional elements/properties are supported:
| Element | Maven/Java Property | Default | Description |
Here is an example of the non-extension use case for the plugin. You could use the same plugin for both preventing banned artifacts and cleaning up previously downloaded ones. Just set `extensions` to `true` in those cases, as highlighted in the previous section.
this.logger.debug("A latest version was found, but could not resolve the artifact using the range; trying to resolve the artifact with the specific version: {}: {}",latestVersion,child.getValue());
this.logger.debug("A latest version was found, but could not resolve the artifact using the range; trying to resolve the artifact with the specific version: {}: {}",latestVersion,logId);