Skip to content

Commit f1528bc

Browse files
authored
feat: scan Maven "provided" scoped dependencies (#21251)
Adds the "provided" scope to the list of Maven dependency scopes considered during class scanning by the Flow maven plugin. Fixes #21192
1 parent c4efb4e commit f1528bc

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

flow-plugins/flow-dev-bundle-plugin/src/main/java/com/vaadin/flow/plugin/maven/Reflector.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import org.apache.maven.artifact.Artifact;
36+
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
3637
import org.apache.maven.plugin.Mojo;
3738
import org.apache.maven.plugin.MojoExecution;
3839
import org.apache.maven.project.MavenProject;
@@ -57,6 +58,8 @@ public final class Reflector {
5758
private static final Set<String> REQUIRED_PLUGIN_DEPENDENCIES = Set.of(
5859
"org.reflections:reflections:jar",
5960
"org.zeroturnaround:zt-exec:jar");
61+
private static final ScopeArtifactFilter PRODUCTION_SCOPE_FILTER = new ScopeArtifactFilter(
62+
Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
6063

6164
private final URLClassLoader isolatedClassLoader;
6265
private List<String> dependenciesIncompatibility;
@@ -269,15 +272,7 @@ private static URLClassLoader createIsolatedClassLoader(
269272
.contains(artifact.getGroupId()))
270273
.filter(artifact -> artifact.getFile() != null
271274
&& artifact.getArtifactHandler().isAddedToClasspath()
272-
&& (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
273-
|| Artifact.SCOPE_RUNTIME
274-
.equals(artifact.getScope())
275-
|| Artifact.SCOPE_SYSTEM
276-
.equals(artifact.getScope())
277-
|| (Artifact.SCOPE_PROVIDED
278-
.equals(artifact.getScope())
279-
&& artifact.getFile().getPath().matches(
280-
INCLUDE_FROM_COMPILE_DEPS_REGEX))))
275+
&& PRODUCTION_SCOPE_FILTER.include(artifact))
281276
.collect(Collectors.toMap(keyMapper, Function.identity())));
282277

283278
if (mojoExecution != null) {

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/Reflector.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.fasterxml.jackson.core.JsonProcessingException;
4242
import com.fasterxml.jackson.databind.ObjectMapper;
4343
import org.apache.maven.artifact.Artifact;
44+
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
4445
import org.apache.maven.plugin.Mojo;
4546
import org.apache.maven.plugin.MojoExecution;
4647
import org.apache.maven.project.MavenProject;
@@ -70,6 +71,8 @@ public final class Reflector {
7071
private static final Set<String> REQUIRED_PLUGIN_DEPENDENCIES = Set.of(
7172
"org.reflections:reflections:jar",
7273
"org.zeroturnaround:zt-exec:jar");
74+
private static final ScopeArtifactFilter PRODUCTION_SCOPE_FILTER = new ScopeArtifactFilter(
75+
Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
7376
private static final Logger log = LoggerFactory.getLogger(Reflector.class);
7477

7578
private final URLClassLoader isolatedClassLoader;
@@ -413,16 +416,10 @@ record FilterableArtifact(Artifact artifact, boolean scan) {
413416
filteredUrls.toArray(new URL[0]), mavenApiClassLoader);
414417
}
415418

416-
// TODO: include also provided scope
417419
private static boolean isProductionDependency(Artifact artifact) {
418420
return artifact.getFile() != null
419421
&& artifact.getArtifactHandler().isAddedToClasspath()
420-
&& (Artifact.SCOPE_COMPILE.equals(artifact.getScope())
421-
|| Artifact.SCOPE_RUNTIME.equals(artifact.getScope())
422-
|| Artifact.SCOPE_SYSTEM.equals(artifact.getScope())
423-
|| (Artifact.SCOPE_PROVIDED.equals(artifact.getScope())
424-
&& artifact.getFile().getPath().matches(
425-
INCLUDE_FROM_COMPILE_DEPS_REGEX)));
422+
&& PRODUCTION_SCOPE_FILTER.include(artifact);
426423
}
427424

428425
/**

flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/ReflectorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ public void reflector_fromProject_getsIsolatedClassLoader()
199199

200200
Set<String> urlSet = Arrays.stream(isolatedClassLoader.getURLs())
201201
.map(URL::toExternalForm).collect(Collectors.toSet());
202-
Assert.assertEquals(4, urlSet.size());
202+
Assert.assertEquals(5, urlSet.size());
203203
Assert.assertTrue(urlSet.contains(toURLExternalForm(outputDirectory)));
204204
Assert.assertTrue(urlSet.contains(
205205
toURLExternalForm("com.vaadin.test-compile-1.0.jar")));
206+
Assert.assertTrue(urlSet.contains(
207+
toURLExternalForm("com.vaadin.test-provided-1.0.jar")));
206208
Assert.assertTrue(urlSet
207209
.contains(toURLExternalForm("com.vaadin.test-system-1.0.jar")));
208210
Assert.assertTrue(urlSet

0 commit comments

Comments
 (0)