Skip to content

Commit

Permalink
Ignore dependencies if they are not meant to be added to the classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Dec 19, 2023
1 parent 62df62b commit ccd507a
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.stream.Stream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
Expand Down Expand Up @@ -610,14 +611,26 @@ public List<String> getClasspathElements() throws MojoExecutionException {
.filter(a -> includedPathes.add(a.getFile().getAbsolutePath())) //
.toList();
for (Artifact artifact : additionalClasspathEntries) {
String path = artifact.getFile().getAbsolutePath();
getLog().debug("Add a pom only classpath entry: " + artifact + " @ " + path);
classpath.add(path);
ArtifactHandler artifactHandler = artifact.getArtifactHandler();
if (artifactHandler.isAddedToClasspath() && inScope(artifact.getScope())) {
String path = artifact.getFile().getAbsolutePath();
getLog().debug("Add a pom only classpath entry: " + artifact + " @ " + path);
classpath.add(path);
}
}
}
return classpath;
}

private boolean inScope(String dependencyScope) {
if (Artifact.SCOPE_COMPILE.equals(getDependencyScope())) {
if (Artifact.SCOPE_TEST.equals(dependencyScope)) {
return false;
}
}
return true;
}

private static boolean isValidLocation(File location) {
if (location == null || !location.exists() || (location.isFile() && location.length() == 0)) {
return false;
Expand Down

0 comments on commit ccd507a

Please sign in to comment.