Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#560] add configuration for artifact exclusions in final classpath (which default to exclude xercesImpl and xml-apis artifacts) #562

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,27 @@ public void setPlugins(Dependency[] plugins) {
this.plugins = plugins;
}

@Component
/**
* <p>
* A list of artifacts to exclude from XJC Plugins resolveTransitively function.
* </p>
* <p>
* If you are using <code>xerces:xercesImpl</code> and / or <code>xml-apis</code>,
* adding them will exclude from the classpath resolution, fixing issue #560.
* </p>
*/
@Parameter
private String[] artifactExcludes = new String[] {};

public String[] getArtifactExcludes() {
return artifactExcludes;
}

public void setArtifactExcludes(String[] artifactExcludes) {
this.artifactExcludes = artifactExcludes;
}

@Component
private RepositorySystem repositorySystem;

@Component
Expand Down Expand Up @@ -1123,6 +1143,7 @@ protected void logConfiguration() throws MojoExecutionException {
+ getScanDependenciesForBindings());
getLog().info("xjcPlugins:" + Arrays.toString(getPlugins()));
getLog().info("episodes:" + Arrays.toString(getEpisodes()));
getLog().info("artifactExcludes:" + Arrays.toString(getArtifactExcludes()));
}

private static final String XML_SCHEMA_CLASS_NAME = "XmlSchema";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ protected void resolveArtifacts() throws MojoExecutionException {
protected void resolveXJCPluginArtifacts()
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException {

this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(getArtifactFactory(), getRepositorySystem(),
getMavenSession().getLocalRepository(), getArtifactMetadataSource(), getPlugins(), getProject());
this.xjcPluginArtifacts = ArtifactUtils.resolveTransitively(
getArtifactFactory(), getRepositorySystem(),
getMavenSession().getLocalRepository(), getArtifactMetadataSource(),
getPlugins(), getProject(), getArtifactExcludes());
this.xjcPluginFiles = ArtifactUtils.getFiles(this.xjcPluginArtifacts);
this.xjcPluginURLs = CollectionUtils.apply(this.xjcPluginFiles, IOUtils.GET_URL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
Expand All @@ -27,13 +28,28 @@ public class ArtifactUtils {
private ArtifactUtils() {

}
public static Collection<Artifact> resolveTransitively(
final ArtifactFactory artifactFactory,
final RepositorySystem artifactResolver,
final ArtifactRepository localRepository,
final ArtifactMetadataSource artifactMetadataSource,
final Dependency[] dependencies, final MavenProject project)
throws InvalidDependencyVersionException,
ArtifactResolutionException, ArtifactNotFoundException {
return resolveTransitively(
artifactFactory, artifactResolver,
localRepository, artifactMetadataSource,
dependencies, project,
null);
}

public static Collection<Artifact> resolveTransitively(
final ArtifactFactory artifactFactory,
final RepositorySystem artifactResolver,
final ArtifactRepository localRepository,
final ArtifactMetadataSource artifactMetadataSource,
final Dependency[] dependencies, final MavenProject project)
final Dependency[] dependencies, final MavenProject project,
final String[] artifactExcludes)
throws InvalidDependencyVersionException,
ArtifactResolutionException, ArtifactNotFoundException {
if (dependencies == null) {
Expand All @@ -49,6 +65,10 @@ public static Collection<Artifact> resolveTransitively(
request.setResolveRoot(false);
request.setArtifact(project.getArtifact());
request.setArtifactDependencies(artifacts);
if (artifactExcludes != null && artifactExcludes.length > 0) {
// remove dependencies from resolution
request.setCollectionFilter(new ExclusionSetFilter(artifactExcludes));
}
request.setRemoteRepositories(project.getRemoteArtifactRepositories());
request.setLocalRepository(localRepository);

Expand Down
Loading