Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1577bbf2d8 | |||
988326a8d5 | |||
ad4b06fc4f | |||
94825b9417 |
@@ -129,7 +129,7 @@ Order does not matter. All include specifications are processed, followed by al
|
|||||||
|
|
||||||
## Import
|
## Import
|
||||||
|
|
||||||
The `import` 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 elmenet 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.
|
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.
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ The `excludes` element is a way to provide project-by-project exceptions to impo
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
The recommended us 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.
|
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.
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<configuration>
|
<configuration>
|
||||||
@@ -159,7 +159,7 @@ Once you have that in place, you will want to add the following to every single
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>ban-maven-plugin</artifactId>
|
<artifactId>ban-maven-plugin</artifactId>
|
||||||
<version>1.3.6</version>
|
<version>...</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<import>
|
<import>
|
||||||
|
@@ -15,11 +15,20 @@
|
|||||||
<name>Banned Artifact Configuration</name>
|
<name>Banned Artifact Configuration</name>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>.</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*-config.xml</include>
|
||||||
|
</includes>
|
||||||
|
<targetPath>${project.build.directory}</targetPath>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>ban-maven-plugin</artifactId>
|
<artifactId>ban-maven-plugin</artifactId>
|
||||||
<version>1.3.6</version>
|
<version>1.4.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>purge-maven-repo</id>
|
<id>purge-maven-repo</id>
|
||||||
@@ -33,6 +42,43 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>filter</id>
|
||||||
|
<goals><goal>resources</goal></goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
<file>${project.build.directory}/ban-config.xml</file>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>install-xml</id>
|
||||||
|
<phase>install</phase>
|
||||||
|
<goals><goal>install-file</goal></goals>
|
||||||
|
<configuration>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>${project.artifactId}</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<packaging>xml</packaging>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<file>ban-config.xml</file>
|
||||||
|
<pomFile>pom.xml</pomFile>
|
||||||
|
<packaging>xml</packaging>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>ban-maven-plugin</artifactId>
|
<artifactId>ban-maven-plugin</artifactId>
|
||||||
<version>1.3.6</version>
|
<version>1.4.0</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<import>
|
<import>
|
||||||
|
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>ban-maven-plugin</artifactId>
|
<artifactId>ban-maven-plugin</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.1</version>
|
||||||
<packaging>maven-plugin</packaging>
|
<packaging>maven-plugin</packaging>
|
||||||
|
|
||||||
<name>Ban Dependencies Maven Plugin</name>
|
<name>Ban Dependencies Maven Plugin</name>
|
||||||
|
@@ -86,15 +86,19 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
|||||||
if (!"xml".equals(artifact.getExtension()))
|
if (!"xml".equals(artifact.getExtension()))
|
||||||
artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "xml", artifact.getVersion());
|
artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "xml", artifact.getVersion());
|
||||||
|
|
||||||
Version latestLocalVersion = this.findLatestLocalVersion(artifact, child.getValue());
|
Version latestVersion = this.findLatestVersion(artifact, child.getValue());
|
||||||
Artifact latestArtifact = this.findLatestArtifact(artifact, child.getValue());
|
Artifact latestArtifact = this.findLatestArtifact(artifact, child.getValue());
|
||||||
if (latestArtifact == null && latestLocalVersion != null) {
|
if (latestArtifact == null && latestVersion != null) {
|
||||||
this.logger.debug("A latest version was found locally, but could not resolve the artifact; trying to resolve the artifact with the specific version: {}: {}", latestLocalVersion, 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, child.getValue());
|
||||||
artifact = artifact.setVersion(latestLocalVersion.toString());
|
artifact = artifact.setVersion(latestVersion.toString());
|
||||||
latestArtifact = this.findLatestArtifact(artifact, child.getValue());
|
latestArtifact = this.findLatestArtifact(artifact, child.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artifact != null) {
|
if (latestArtifact != null && latestArtifact.getFile() != null) {
|
||||||
|
this.logger.debug("The latest artifact was found: {}", latestArtifact);
|
||||||
|
File file = latestArtifact.getFile();
|
||||||
|
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file);
|
||||||
|
} else if (artifact != null) {
|
||||||
File file = artifact.getFile();
|
File file = artifact.getFile();
|
||||||
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file);
|
downloader = new BanConfigurationDownloader(this.session, this.artifactResolver, this.versionRangeResolver, file);
|
||||||
}
|
}
|
||||||
@@ -109,16 +113,16 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Version findLatestLocalVersion(Artifact artifact, String logId) {
|
private Version findLatestVersion(Artifact artifact, String logId) {
|
||||||
this.logger.trace("Inspecting the local repository to select the version to import: {}", logId);
|
this.logger.trace("Inspecting the local and remote repositories to select the version to import: {}", logId);
|
||||||
VersionRangeRequest vrrequest = new VersionRangeRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
VersionRangeRequest vrrequest = new VersionRangeRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
||||||
try {
|
try {
|
||||||
VersionRangeResult vrresult = this.versionRangeResolver.resolveVersionRange(this.session.getRepositorySession(), vrrequest);
|
VersionRangeResult vrresult = this.versionRangeResolver.resolveVersionRange(this.session.getRepositorySession(), vrrequest);
|
||||||
if (vrresult.getVersions().isEmpty()) {
|
if (vrresult.getVersions().isEmpty()) {
|
||||||
this.logger.info("The artifact version range could not be resolved locally; trying remote: {}", logId);
|
this.logger.info("The artifact version range could not be resolved: {}", logId);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
this.logger.debug("The artifact version discovered locally: {}; trying remote: {}", vrresult.getHighestVersion(), logId);
|
this.logger.debug("The artifact version discovered: {}: {}", vrresult.getHighestVersion(), logId);
|
||||||
return vrresult.getHighestVersion();
|
return vrresult.getHighestVersion();
|
||||||
}
|
}
|
||||||
} catch (VersionRangeResolutionException vrre) {
|
} catch (VersionRangeResolutionException vrre) {
|
||||||
@@ -132,7 +136,7 @@ public abstract class AbstractBanConfiguration implements BanConfiguration {
|
|||||||
ArtifactRequest arequest = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
ArtifactRequest arequest = new ArtifactRequest(artifact, this.session.getCurrentProject().getRemoteProjectRepositories(), null);
|
||||||
try {
|
try {
|
||||||
ArtifactResult aresult = this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), arequest);
|
ArtifactResult aresult = this.artifactResolver.resolveArtifact(this.session.getRepositorySession(), arequest);
|
||||||
this.logger.debug("This artifact version discovered remotely: {}: {}", aresult.getArtifact().getVersion(), logId);
|
this.logger.debug("This artifact version discovered: {}: {}", aresult.getArtifact().getVersion(), logId);
|
||||||
return aresult.getArtifact();
|
return aresult.getArtifact();
|
||||||
} catch (ArtifactResolutionException are) {
|
} catch (ArtifactResolutionException are) {
|
||||||
this.logger.warn("The artifact could not be resolved; skipping: {}", artifact);
|
this.logger.warn("The artifact could not be resolved; skipping: {}", artifact);
|
||||||
|
Reference in New Issue
Block a user