diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index 696742ca1e9da..409700ecb15ef 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; @@ -746,15 +745,15 @@ private void executeGoal(PluginExec pluginExec, String goal, Map private List readAnnotationProcessors(Xpp3Dom pluginConfig) { if (pluginConfig == null) { - return Collections.emptyList(); + return List.of(); } Xpp3Dom annotationProcessors = pluginConfig.getChild("annotationProcessors"); if (annotationProcessors == null) { - return Collections.emptyList(); + return List.of(); } Xpp3Dom[] processors = annotationProcessors.getChildren("annotationProcessor"); if (processors.length == 0) { - return Collections.emptyList(); + return List.of(); } List ret = new ArrayList<>(processors.length); for (Xpp3Dom processor : processors) { @@ -765,21 +764,18 @@ private List readAnnotationProcessors(Xpp3Dom pluginConfig) { private Set readAnnotationProcessorPaths(Xpp3Dom pluginConfig) throws MojoExecutionException { if (pluginConfig == null) { - return Collections.emptySet(); + return Set.of(); } Xpp3Dom annotationProcessorPaths = pluginConfig.getChild("annotationProcessorPaths"); if (annotationProcessorPaths == null) { - return Collections.emptySet(); + return Set.of(); } + var versionConstraints = getAnnotationProcessorPathsDepMgmt(pluginConfig); Xpp3Dom[] paths = annotationProcessorPaths.getChildren("path"); Set elements = new LinkedHashSet<>(); try { List dependencies = convertToDependencies(paths); - // NOTE: The Maven Compiler Plugin also supports a flag (disabled by default) for applying managed dependencies to - // the dependencies of the APT plugins (not them directly), which we don't support yet here - // you can find the implementation at https://github.com/apache/maven-compiler-plugin/pull/180/files#diff-d4bac42d8f4c68d397ddbaa05c1cbbed7984ef6dc0bb9ea60739df78997e99eeR1610 - // when/if we need it - CollectRequest collectRequest = new CollectRequest(dependencies, Collections.emptyList(), + CollectRequest collectRequest = new CollectRequest(dependencies, versionConstraints, project.getRemoteProjectRepositories()); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setCollectRequest(collectRequest); @@ -796,6 +792,18 @@ private Set readAnnotationProcessorPaths(Xpp3Dom pluginConfig) throws Mojo } } + private List getAnnotationProcessorPathsDepMgmt(Xpp3Dom pluginConfig) { + final Xpp3Dom useDepMgmt = pluginConfig.getChild("annotationProcessorPathsUseDepMgmt"); + if (useDepMgmt == null || !Boolean.parseBoolean(useDepMgmt.getValue())) { + return List.of(); + } + var dm = project.getDependencyManagement(); + if (dm == null) { + return List.of(); + } + return getProjectAetherDependencyManagement(); + } + private List convertToDependencies(Xpp3Dom[] paths) throws MojoExecutionException { List dependencies = new ArrayList<>(); for (Xpp3Dom path : paths) { @@ -848,7 +856,7 @@ private String toNullIfEmpty(String value) { private List getProjectManagedDependencies() { DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement == null || dependencyManagement.getDependencies() == null) { - return Collections.emptyList(); + return List.of(); } return dependencyManagement.getDependencies(); } @@ -864,7 +872,7 @@ private String getValue(Xpp3Dom path, String element, String defaultValue) { private Set convertToAetherExclusions(Xpp3Dom exclusions) { if (exclusions == null) { - return Collections.emptySet(); + return Set.of(); } Set aetherExclusions = new HashSet<>(); for (Xpp3Dom exclusion : exclusions.getChildren("exclusion")) { @@ -1489,21 +1497,6 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica throw new MojoExecutionException("Classpath resource " + pomPropsPath + " is missing version"); } - final List managed = new ArrayList<>( - project.getDependencyManagement().getDependencies().size()); - project.getDependencyManagement().getDependencies().forEach(d -> { - final List exclusions; - if (!d.getExclusions().isEmpty()) { - exclusions = new ArrayList<>(d.getExclusions().size()); - d.getExclusions().forEach(e -> exclusions.add(new Exclusion(e.getGroupId(), e.getArtifactId(), "*", "*"))); - } else { - exclusions = List.of(); - } - managed.add(new org.eclipse.aether.graph.Dependency( - new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()), - d.getScope(), d.isOptional(), exclusions)); - }); - final DefaultArtifact devModeJar = new DefaultArtifact(devModeGroupId, devModeArtifactId, ArtifactCoords.TYPE_JAR, devModeVersion); final DependencyResult cpRes = repoSystem.resolveDependencies(repoSession, @@ -1513,7 +1506,7 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica // it doesn't matter what the root artifact is, it's an alias .setRootArtifact(new DefaultArtifact(IO_QUARKUS, "quarkus-devmode-alias", ArtifactCoords.TYPE_JAR, "1.0")) - .setManagedDependencies(managed) + .setManagedDependencies(getProjectAetherDependencyManagement()) .setDependencies(List.of( new org.eclipse.aether.graph.Dependency(devModeJar, JavaScopes.RUNTIME), new org.eclipse.aether.graph.Dependency(new DefaultArtifact( @@ -1539,6 +1532,24 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica } } + private List getProjectAetherDependencyManagement() { + final List managed = new ArrayList<>( + project.getDependencyManagement().getDependencies().size()); + project.getDependencyManagement().getDependencies().forEach(d -> { + final List exclusions; + if (!d.getExclusions().isEmpty()) { + exclusions = new ArrayList<>(d.getExclusions().size()); + d.getExclusions().forEach(e -> exclusions.add(new Exclusion(e.getGroupId(), e.getArtifactId(), "*", "*"))); + } else { + exclusions = List.of(); + } + managed.add(new org.eclipse.aether.graph.Dependency( + new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()), + d.getScope(), d.isOptional(), exclusions)); + }); + return managed; + } + private void setKotlinSpecificFlags(MavenDevModeLauncher.Builder builder) { Plugin kotlinMavenPlugin = null; for (Plugin plugin : project.getBuildPlugins()) {