Skip to content

Commit ed83732

Browse files
aloubyanskygsmet
authored andcommitted
Support annotationProcessorPathsUseDepMgmt in quarkus:dev
(cherry picked from commit dcffc7d)
1 parent e7c7ba0 commit ed83732

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
2727
import java.util.Collection;
28-
import java.util.Collections;
2928
import java.util.HashMap;
3029
import java.util.HashSet;
3130
import java.util.LinkedHashSet;
@@ -746,15 +745,15 @@ private void executeGoal(PluginExec pluginExec, String goal, Map<String, String>
746745

747746
private List<String> readAnnotationProcessors(Xpp3Dom pluginConfig) {
748747
if (pluginConfig == null) {
749-
return Collections.emptyList();
748+
return List.of();
750749
}
751750
Xpp3Dom annotationProcessors = pluginConfig.getChild("annotationProcessors");
752751
if (annotationProcessors == null) {
753-
return Collections.emptyList();
752+
return List.of();
754753
}
755754
Xpp3Dom[] processors = annotationProcessors.getChildren("annotationProcessor");
756755
if (processors.length == 0) {
757-
return Collections.emptyList();
756+
return List.of();
758757
}
759758
List<String> ret = new ArrayList<>(processors.length);
760759
for (Xpp3Dom processor : processors) {
@@ -765,21 +764,18 @@ private List<String> readAnnotationProcessors(Xpp3Dom pluginConfig) {
765764

766765
private Set<File> readAnnotationProcessorPaths(Xpp3Dom pluginConfig) throws MojoExecutionException {
767766
if (pluginConfig == null) {
768-
return Collections.emptySet();
767+
return Set.of();
769768
}
770769
Xpp3Dom annotationProcessorPaths = pluginConfig.getChild("annotationProcessorPaths");
771770
if (annotationProcessorPaths == null) {
772-
return Collections.emptySet();
771+
return Set.of();
773772
}
773+
var versionConstraints = getAnnotationProcessorPathsDepMgmt(pluginConfig);
774774
Xpp3Dom[] paths = annotationProcessorPaths.getChildren("path");
775775
Set<File> elements = new LinkedHashSet<>();
776776
try {
777777
List<org.eclipse.aether.graph.Dependency> dependencies = convertToDependencies(paths);
778-
// NOTE: The Maven Compiler Plugin also supports a flag (disabled by default) for applying managed dependencies to
779-
// the dependencies of the APT plugins (not them directly), which we don't support yet here
780-
// you can find the implementation at https://github.com/apache/maven-compiler-plugin/pull/180/files#diff-d4bac42d8f4c68d397ddbaa05c1cbbed7984ef6dc0bb9ea60739df78997e99eeR1610
781-
// when/if we need it
782-
CollectRequest collectRequest = new CollectRequest(dependencies, Collections.emptyList(),
778+
CollectRequest collectRequest = new CollectRequest(dependencies, versionConstraints,
783779
project.getRemoteProjectRepositories());
784780
DependencyRequest dependencyRequest = new DependencyRequest();
785781
dependencyRequest.setCollectRequest(collectRequest);
@@ -796,6 +792,18 @@ private Set<File> readAnnotationProcessorPaths(Xpp3Dom pluginConfig) throws Mojo
796792
}
797793
}
798794

795+
private List<org.eclipse.aether.graph.Dependency> getAnnotationProcessorPathsDepMgmt(Xpp3Dom pluginConfig) {
796+
final Xpp3Dom useDepMgmt = pluginConfig.getChild("annotationProcessorPathsUseDepMgmt");
797+
if (useDepMgmt == null || !Boolean.parseBoolean(useDepMgmt.getValue())) {
798+
return List.of();
799+
}
800+
var dm = project.getDependencyManagement();
801+
if (dm == null) {
802+
return List.of();
803+
}
804+
return getProjectAetherDependencyManagement();
805+
}
806+
799807
private List<org.eclipse.aether.graph.Dependency> convertToDependencies(Xpp3Dom[] paths) throws MojoExecutionException {
800808
List<org.eclipse.aether.graph.Dependency> dependencies = new ArrayList<>();
801809
for (Xpp3Dom path : paths) {
@@ -848,7 +856,7 @@ private String toNullIfEmpty(String value) {
848856
private List<Dependency> getProjectManagedDependencies() {
849857
DependencyManagement dependencyManagement = project.getDependencyManagement();
850858
if (dependencyManagement == null || dependencyManagement.getDependencies() == null) {
851-
return Collections.emptyList();
859+
return List.of();
852860
}
853861
return dependencyManagement.getDependencies();
854862
}
@@ -864,7 +872,7 @@ private String getValue(Xpp3Dom path, String element, String defaultValue) {
864872

865873
private Set<org.eclipse.aether.graph.Exclusion> convertToAetherExclusions(Xpp3Dom exclusions) {
866874
if (exclusions == null) {
867-
return Collections.emptySet();
875+
return Set.of();
868876
}
869877
Set<Exclusion> aetherExclusions = new HashSet<>();
870878
for (Xpp3Dom exclusion : exclusions.getChildren("exclusion")) {
@@ -1489,21 +1497,6 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
14891497
throw new MojoExecutionException("Classpath resource " + pomPropsPath + " is missing version");
14901498
}
14911499

1492-
final List<org.eclipse.aether.graph.Dependency> managed = new ArrayList<>(
1493-
project.getDependencyManagement().getDependencies().size());
1494-
project.getDependencyManagement().getDependencies().forEach(d -> {
1495-
final List<Exclusion> exclusions;
1496-
if (!d.getExclusions().isEmpty()) {
1497-
exclusions = new ArrayList<>(d.getExclusions().size());
1498-
d.getExclusions().forEach(e -> exclusions.add(new Exclusion(e.getGroupId(), e.getArtifactId(), "*", "*")));
1499-
} else {
1500-
exclusions = List.of();
1501-
}
1502-
managed.add(new org.eclipse.aether.graph.Dependency(
1503-
new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()),
1504-
d.getScope(), d.isOptional(), exclusions));
1505-
});
1506-
15071500
final DefaultArtifact devModeJar = new DefaultArtifact(devModeGroupId, devModeArtifactId, ArtifactCoords.TYPE_JAR,
15081501
devModeVersion);
15091502
final DependencyResult cpRes = repoSystem.resolveDependencies(repoSession,
@@ -1513,7 +1506,7 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
15131506
// it doesn't matter what the root artifact is, it's an alias
15141507
.setRootArtifact(new DefaultArtifact(IO_QUARKUS, "quarkus-devmode-alias",
15151508
ArtifactCoords.TYPE_JAR, "1.0"))
1516-
.setManagedDependencies(managed)
1509+
.setManagedDependencies(getProjectAetherDependencyManagement())
15171510
.setDependencies(List.of(
15181511
new org.eclipse.aether.graph.Dependency(devModeJar, JavaScopes.RUNTIME),
15191512
new org.eclipse.aether.graph.Dependency(new DefaultArtifact(
@@ -1539,6 +1532,24 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
15391532
}
15401533
}
15411534

1535+
private List<org.eclipse.aether.graph.Dependency> getProjectAetherDependencyManagement() {
1536+
final List<org.eclipse.aether.graph.Dependency> managed = new ArrayList<>(
1537+
project.getDependencyManagement().getDependencies().size());
1538+
project.getDependencyManagement().getDependencies().forEach(d -> {
1539+
final List<Exclusion> exclusions;
1540+
if (!d.getExclusions().isEmpty()) {
1541+
exclusions = new ArrayList<>(d.getExclusions().size());
1542+
d.getExclusions().forEach(e -> exclusions.add(new Exclusion(e.getGroupId(), e.getArtifactId(), "*", "*")));
1543+
} else {
1544+
exclusions = List.of();
1545+
}
1546+
managed.add(new org.eclipse.aether.graph.Dependency(
1547+
new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()),
1548+
d.getScope(), d.isOptional(), exclusions));
1549+
});
1550+
return managed;
1551+
}
1552+
15421553
private void setKotlinSpecificFlags(MavenDevModeLauncher.Builder builder) {
15431554
Plugin kotlinMavenPlugin = null;
15441555
for (Plugin plugin : project.getBuildPlugins()) {

0 commit comments

Comments
 (0)