Skip to content

Commit d368e04

Browse files
[#560] add a way to exclude artifacts from xjc classpath resolution
defaults to xercesImpl and xml-apis
1 parent 1078f1f commit d368e04

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/AbstractXJCMojo.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,27 @@ public void setPlugins(Dependency[] plugins) {
984984
this.plugins = plugins;
985985
}
986986

987-
@Component
987+
/**
988+
* <p>
989+
* A list of artifacts to exclude from XJC Plugins resolveTransitively function.
990+
* </p>
991+
* <p>
992+
* If left undefined, then <code>xercesImpl</code> and <code>xml-apis</code> will
993+
* be excluded by default from the classpath resolution.
994+
* </p>
995+
*/
996+
@Parameter
997+
private String[] artifactExcludes = new String[] { "xercesImpl", "xml-apis" };
998+
999+
public String[] getArtifactExcludes() {
1000+
return artifactExcludes;
1001+
}
1002+
1003+
public void setArtifactExcludes(String[] artifactExcludes) {
1004+
this.artifactExcludes = artifactExcludes;
1005+
}
1006+
1007+
@Component
9881008
private RepositorySystem repositorySystem;
9891009

9901010
@Component
@@ -1123,6 +1143,7 @@ protected void logConfiguration() throws MojoExecutionException {
11231143
+ getScanDependenciesForBindings());
11241144
getLog().info("xjcPlugins:" + Arrays.toString(getPlugins()));
11251145
getLog().info("episodes:" + Arrays.toString(getEpisodes()));
1146+
getLog().info("artifactExcludes:" + Arrays.toString(getArtifactExcludes()));
11261147
}
11271148

11281149
private static final String XML_SCHEMA_CLASS_NAME = "XmlSchema";

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/RawXJCMojo.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,10 @@ protected void resolveArtifacts() throws MojoExecutionException {
394394
protected void resolveXJCPluginArtifacts()
395395
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException {
396396

397-
this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(getArtifactFactory(), getRepositorySystem(),
398-
getMavenSession().getLocalRepository(), getArtifactMetadataSource(), getPlugins(), getProject());
397+
this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(
398+
getArtifactFactory(), getRepositorySystem(),
399+
getMavenSession().getLocalRepository(), getArtifactMetadataSource(),
400+
getPlugins(), getProject(), getArtifactExcludes());
399401
this.xjcPluginFiles = ArtifactUtils.getFiles(this.xjcPluginArtifacts);
400402
this.xjcPluginURLs = CollectionUtils.apply(this.xjcPluginFiles, IOUtils.GET_URL);
401403
}

maven-plugin/plugin-core/src/main/java/org/jvnet/jaxb/maven/util/ArtifactUtils.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
1616
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
1717
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
18+
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
1819
import org.apache.maven.model.Dependency;
1920
import org.apache.maven.project.MavenProject;
2021
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
@@ -27,13 +28,28 @@ public class ArtifactUtils {
2728
private ArtifactUtils() {
2829

2930
}
31+
public static Collection<Artifact> resolveTransitively(
32+
final ArtifactFactory artifactFactory,
33+
final RepositorySystem artifactResolver,
34+
final ArtifactRepository localRepository,
35+
final ArtifactMetadataSource artifactMetadataSource,
36+
final Dependency[] dependencies, final MavenProject project)
37+
throws InvalidDependencyVersionException,
38+
ArtifactResolutionException, ArtifactNotFoundException {
39+
return resolveTransitively(
40+
artifactFactory, artifactResolver,
41+
localRepository, artifactMetadataSource,
42+
dependencies, project,
43+
null);
44+
}
3045

3146
public static Collection<Artifact> resolveTransitively(
3247
final ArtifactFactory artifactFactory,
3348
final RepositorySystem artifactResolver,
3449
final ArtifactRepository localRepository,
3550
final ArtifactMetadataSource artifactMetadataSource,
36-
final Dependency[] dependencies, final MavenProject project)
51+
final Dependency[] dependencies, final MavenProject project,
52+
final String[] artifactExcludes)
3753
throws InvalidDependencyVersionException,
3854
ArtifactResolutionException, ArtifactNotFoundException {
3955
if (dependencies == null) {
@@ -49,6 +65,10 @@ public static Collection<Artifact> resolveTransitively(
4965
request.setResolveRoot(false);
5066
request.setArtifact(project.getArtifact());
5167
request.setArtifactDependencies(artifacts);
68+
if (artifactExcludes != null && artifactExcludes.length > 0) {
69+
// remove dependencies from resolution
70+
request.setCollectionFilter(new ExclusionSetFilter(artifactExcludes));
71+
}
5272
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
5373
request.setLocalRepository(localRepository);
5474

0 commit comments

Comments
 (0)