1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
26
26
import java .util .TreeSet ;
27
27
28
28
import org .gradle .api .DefaultTask ;
29
+ import org .gradle .api .Project ;
29
30
import org .gradle .api .Task ;
30
31
import org .gradle .api .artifacts .ComponentMetadataDetails ;
31
32
import org .gradle .api .artifacts .Configuration ;
32
33
import org .gradle .api .artifacts .DependencyConstraint ;
33
34
import org .gradle .api .artifacts .DependencyConstraintMetadata ;
35
+ import org .gradle .api .artifacts .DependencyConstraintSet ;
34
36
import org .gradle .api .artifacts .dsl .DependencyHandler ;
35
37
import org .gradle .api .tasks .Internal ;
36
38
import org .gradle .api .tasks .TaskAction ;
37
39
import org .gradle .platform .base .Platform ;
38
40
39
41
import org .springframework .boot .build .bom .BomExtension ;
42
+ import org .springframework .boot .build .bom .BomPlugin ;
40
43
import org .springframework .boot .build .bom .Library ;
41
44
42
45
/**
@@ -55,7 +58,9 @@ public class ExtractVersionConstraints extends DefaultTask {
55
58
56
59
private final Set <VersionProperty > versionProperties = new TreeSet <>();
57
60
58
- private final List <String > projectPaths = new ArrayList <>();
61
+ private final List <DependencyConstraintSet > dependencyConstraintSets = new ArrayList <>();
62
+
63
+ private final List <BomExtension > boms = new ArrayList <>();
59
64
60
65
public ExtractVersionConstraints () {
61
66
DependencyHandler dependencies = getProject ().getDependencies ();
@@ -68,7 +73,12 @@ public void enforcedPlatform(String projectPath) {
68
73
.add (getProject ().getDependencies ()
69
74
.enforcedPlatform (
70
75
getProject ().getDependencies ().project (Collections .singletonMap ("path" , projectPath ))));
71
- this .projectPaths .add (projectPath );
76
+ Project project = getProject ().project (projectPath );
77
+ project .getPlugins ().withType (BomPlugin .class ).all ((plugin ) -> {
78
+ this .boms .add (project .getExtensions ().getByType (BomExtension .class ));
79
+ this .dependencyConstraintSets
80
+ .add (project .getConfigurations ().getByName ("apiElements" ).getAllDependencyConstraints ());
81
+ });
72
82
}
73
83
74
84
@ Internal
@@ -89,12 +99,9 @@ public Set<VersionProperty> getVersionProperties() {
89
99
@ TaskAction
90
100
void extractVersionConstraints () {
91
101
this .configuration .resolve ();
92
- for (String projectPath : this .projectPaths ) {
93
- extractVersionProperties (projectPath );
94
- for (DependencyConstraint constraint : getProject ().project (projectPath )
95
- .getConfigurations ()
96
- .getByName ("apiElements" )
97
- .getAllDependencyConstraints ()) {
102
+ this .boms .forEach (this ::extractVersionProperties );
103
+ for (DependencyConstraintSet constraints : this .dependencyConstraintSets ) {
104
+ for (DependencyConstraint constraint : constraints ) {
98
105
this .versionConstraints .put (constraint .getGroup () + ":" + constraint .getName (),
99
106
constraint .getVersionConstraint ().toString ());
100
107
this .constrainedVersions .add (new ConstrainedVersion (constraint .getGroup (), constraint .getName (),
@@ -103,9 +110,7 @@ void extractVersionConstraints() {
103
110
}
104
111
}
105
112
106
- private void extractVersionProperties (String projectPath ) {
107
- Object bom = getProject ().project (projectPath ).getExtensions ().getByName ("bom" );
108
- BomExtension bomExtension = (BomExtension ) bom ;
113
+ private void extractVersionProperties (BomExtension bomExtension ) {
109
114
for (Library lib : bomExtension .getLibraries ()) {
110
115
String versionProperty = lib .getVersionProperty ();
111
116
if (versionProperty != null ) {
0 commit comments