25
25
import java .util .ArrayList ;
26
26
import java .util .Arrays ;
27
27
import java .util .Collection ;
28
- import java .util .Collections ;
29
28
import java .util .HashMap ;
30
29
import java .util .HashSet ;
31
30
import java .util .LinkedHashSet ;
@@ -746,15 +745,15 @@ private void executeGoal(PluginExec pluginExec, String goal, Map<String, String>
746
745
747
746
private List <String > readAnnotationProcessors (Xpp3Dom pluginConfig ) {
748
747
if (pluginConfig == null ) {
749
- return Collections . emptyList ();
748
+ return List . of ();
750
749
}
751
750
Xpp3Dom annotationProcessors = pluginConfig .getChild ("annotationProcessors" );
752
751
if (annotationProcessors == null ) {
753
- return Collections . emptyList ();
752
+ return List . of ();
754
753
}
755
754
Xpp3Dom [] processors = annotationProcessors .getChildren ("annotationProcessor" );
756
755
if (processors .length == 0 ) {
757
- return Collections . emptyList ();
756
+ return List . of ();
758
757
}
759
758
List <String > ret = new ArrayList <>(processors .length );
760
759
for (Xpp3Dom processor : processors ) {
@@ -765,21 +764,18 @@ private List<String> readAnnotationProcessors(Xpp3Dom pluginConfig) {
765
764
766
765
private Set <File > readAnnotationProcessorPaths (Xpp3Dom pluginConfig ) throws MojoExecutionException {
767
766
if (pluginConfig == null ) {
768
- return Collections . emptySet ();
767
+ return Set . of ();
769
768
}
770
769
Xpp3Dom annotationProcessorPaths = pluginConfig .getChild ("annotationProcessorPaths" );
771
770
if (annotationProcessorPaths == null ) {
772
- return Collections . emptySet ();
771
+ return Set . of ();
773
772
}
773
+ var versionConstraints = getAnnotationProcessorPathsDepMgmt (pluginConfig );
774
774
Xpp3Dom [] paths = annotationProcessorPaths .getChildren ("path" );
775
775
Set <File > elements = new LinkedHashSet <>();
776
776
try {
777
777
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 ,
783
779
project .getRemoteProjectRepositories ());
784
780
DependencyRequest dependencyRequest = new DependencyRequest ();
785
781
dependencyRequest .setCollectRequest (collectRequest );
@@ -796,6 +792,18 @@ private Set<File> readAnnotationProcessorPaths(Xpp3Dom pluginConfig) throws Mojo
796
792
}
797
793
}
798
794
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
+
799
807
private List <org .eclipse .aether .graph .Dependency > convertToDependencies (Xpp3Dom [] paths ) throws MojoExecutionException {
800
808
List <org .eclipse .aether .graph .Dependency > dependencies = new ArrayList <>();
801
809
for (Xpp3Dom path : paths ) {
@@ -848,7 +856,7 @@ private String toNullIfEmpty(String value) {
848
856
private List <Dependency > getProjectManagedDependencies () {
849
857
DependencyManagement dependencyManagement = project .getDependencyManagement ();
850
858
if (dependencyManagement == null || dependencyManagement .getDependencies () == null ) {
851
- return Collections . emptyList ();
859
+ return List . of ();
852
860
}
853
861
return dependencyManagement .getDependencies ();
854
862
}
@@ -864,7 +872,7 @@ private String getValue(Xpp3Dom path, String element, String defaultValue) {
864
872
865
873
private Set <org .eclipse .aether .graph .Exclusion > convertToAetherExclusions (Xpp3Dom exclusions ) {
866
874
if (exclusions == null ) {
867
- return Collections . emptySet ();
875
+ return Set . of ();
868
876
}
869
877
Set <Exclusion > aetherExclusions = new HashSet <>();
870
878
for (Xpp3Dom exclusion : exclusions .getChildren ("exclusion" )) {
@@ -1489,21 +1497,6 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
1489
1497
throw new MojoExecutionException ("Classpath resource " + pomPropsPath + " is missing version" );
1490
1498
}
1491
1499
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
-
1507
1500
final DefaultArtifact devModeJar = new DefaultArtifact (devModeGroupId , devModeArtifactId , ArtifactCoords .TYPE_JAR ,
1508
1501
devModeVersion );
1509
1502
final DependencyResult cpRes = repoSystem .resolveDependencies (repoSession ,
@@ -1513,7 +1506,7 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
1513
1506
// it doesn't matter what the root artifact is, it's an alias
1514
1507
.setRootArtifact (new DefaultArtifact (IO_QUARKUS , "quarkus-devmode-alias" ,
1515
1508
ArtifactCoords .TYPE_JAR , "1.0" ))
1516
- .setManagedDependencies (managed )
1509
+ .setManagedDependencies (getProjectAetherDependencyManagement () )
1517
1510
.setDependencies (List .of (
1518
1511
new org .eclipse .aether .graph .Dependency (devModeJar , JavaScopes .RUNTIME ),
1519
1512
new org .eclipse .aether .graph .Dependency (new DefaultArtifact (
@@ -1539,6 +1532,24 @@ private void addQuarkusDevModeDeps(MavenDevModeLauncher.Builder builder, Applica
1539
1532
}
1540
1533
}
1541
1534
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
+
1542
1553
private void setKotlinSpecificFlags (MavenDevModeLauncher .Builder builder ) {
1543
1554
Plugin kotlinMavenPlugin = null ;
1544
1555
for (Plugin plugin : project .getBuildPlugins ()) {
0 commit comments