From ccd507ab095180b201485ddd2726f017cbe3ab05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 19 Dec 2023 17:35:49 +0100 Subject: [PATCH] Ignore dependencies if they are not meant to be added to the classpath --- .../compiler/AbstractOsgiCompilerMojo.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tycho-compiler-plugin/src/main/java/org/eclipse/tycho/compiler/AbstractOsgiCompilerMojo.java b/tycho-compiler-plugin/src/main/java/org/eclipse/tycho/compiler/AbstractOsgiCompilerMojo.java index 05598dd3c8..e052d7cc59 100644 --- a/tycho-compiler-plugin/src/main/java/org/eclipse/tycho/compiler/AbstractOsgiCompilerMojo.java +++ b/tycho-compiler-plugin/src/main/java/org/eclipse/tycho/compiler/AbstractOsgiCompilerMojo.java @@ -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; @@ -610,14 +611,26 @@ public List 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;