Skip to content

Commit 9013cb8

Browse files
authored
Merge pull request #137 from nebula-plugins/gradle-9
Gradle 9.x support
2 parents 232afef + 61ed0f1 commit 9013cb8

File tree

12 files changed

+130
-26
lines changed

12 files changed

+130
-26
lines changed

.github/workflows/nebula.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
# test against latest update of some major Java version(s), as well as specific LTS version(s)
25-
java: [8, 17, 21]
25+
java: [17, 21]
2626
name: Gradle Build without Publish
2727
steps:
2828
- uses: actions/checkout@v4
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
distribution: 'zulu'
3737
java-version: |
38-
8
38+
17
3939
${{ matrix.java }}
4040
java-package: jdk
4141
- uses: actions/cache@v3
@@ -75,7 +75,7 @@ jobs:
7575
with:
7676
distribution: 'zulu'
7777
java-version: |
78-
8
78+
17
7979
21
8080
java-package: jdk
8181
- uses: actions/cache@v3
@@ -120,7 +120,7 @@ jobs:
120120
with:
121121
distribution: 'zulu'
122122
java-version: |
123-
8
123+
17
124124
21
125125
java-package: jdk
126126
- uses: actions/cache@v3

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
plugins {
17-
id 'com.netflix.nebula.plugin-plugin' version '21.3.3'
17+
id 'com.netflix.nebula.plugin-plugin' version '22.0.2'
1818
}
1919

2020
description = 'Allows projects to leave off version numbers in dependencies section and have versions recommended by other sources'

gradle.lockfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@
44
cglib:cglib-nodep:3.2.2=integTestRuntimeClasspath,testRuntimeClasspath
55
com.google.guava:guava:20.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
66
com.netflix.nebula:nebula-gradle-interop:2.3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
7-
com.netflix.nebula:nebula-test:10.6.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
7+
com.netflix.nebula:nebula-test:11.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
88
javax.inject:javax.inject:1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
99
junit:junit:4.13.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1010
org.apache.commons:commons-lang3:3.8.1=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
11+
org.apache.groovy:groovy:4.0.4=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1112
org.apache.maven:maven-artifact:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1213
org.apache.maven:maven-builder-support:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1314
org.apache.maven:maven-model-builder:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1415
org.apache.maven:maven-model:3.8.3=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1516
org.apiguardian:apiguardian-api:1.1.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
16-
org.codehaus.groovy:groovy:3.0.12=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
1717
org.codehaus.plexus:plexus-interpolation:1.26=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1818
org.codehaus.plexus:plexus-utils:3.3.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1919
org.eclipse.sisu:org.eclipse.sisu.inject:0.3.5=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
2020
org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
2121
org.hamcrest:hamcrest:2.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
2222
org.jetbrains.kotlin:kotlin-stdlib:2.1.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
2323
org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
24-
org.junit.platform:junit-platform-commons:1.9.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
25-
org.junit.platform:junit-platform-engine:1.9.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
24+
org.junit.platform:junit-platform-commons:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
25+
org.junit.platform:junit-platform-engine:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
26+
org.junit.platform:junit-platform-launcher:1.13.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
2627
org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath
27-
org.opentest4j:opentest4j:1.2.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
28-
org.spockframework:spock-core:2.3-groovy-3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
29-
org.spockframework:spock-junit4:2.3-groovy-3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
28+
org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
29+
org.spockframework:spock-core:2.3-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
30+
org.spockframework:spock-junit4:2.3-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
3031
org.xmlunit:xmlunit-core:2.6.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
3132
empty=annotationProcessor,integTestAnnotationProcessor,testAnnotationProcessor

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=7197a12f450794931532469d4ff21a59ea2c1cd59a3ec3f89c035c3c420a6999
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-1-bin.zip
54
networkTimeout=10000
65
validateDistributionUrl=true
76
zipStoreBase=GRADLE_USER_HOME

src/integTest/groovy/netflix/nebula/dependency/recommender/publisher/MavenBomXmlGeneratorIntegrationSpec.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package netflix.nebula.dependency.recommender.publisher
1717

18+
import groovy.xml.XmlSlurper
1819
import nebula.test.IntegrationSpec
1920
import nebula.test.dependencies.DependencyGraphBuilder
2021
import nebula.test.dependencies.GradleDependencyGenerator
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package netflix.nebula.dependency.recommender
2+
3+
import groovy.transform.CompileDynamic;
4+
import org.codehaus.groovy.runtime.GeneratedClosure;
5+
import org.gradle.api.Action;
6+
import org.gradle.internal.Actions;
7+
import org.gradle.internal.metaobject.ConfigureDelegate;
8+
import org.gradle.internal.metaobject.DynamicInvokeResult;
9+
import org.gradle.internal.metaobject.DynamicObject;
10+
import org.gradle.internal.metaobject.DynamicObjectUtil
11+
import org.gradle.util.Configurable;
12+
import org.gradle.util.internal.ClosureBackedAction;
13+
14+
import javax.annotation.Nullable;
15+
16+
@CompileDynamic
17+
class ConfigureUtil {
18+
19+
static class IncompleteInputException extends RuntimeException {
20+
private final Collection missingKeys;
21+
22+
IncompleteInputException(String message, Collection missingKeys) {
23+
super(message);
24+
this.missingKeys = missingKeys;
25+
}
26+
27+
Collection getMissingKeys() {
28+
return missingKeys;
29+
}
30+
}
31+
32+
/**
33+
* <p>Configures {@code target} with {@code configureClosure}, via the {@link Configurable} interface if necessary.</p>
34+
*
35+
* <p>If {@code target} does not implement {@link Configurable} interface, it is set as the delegate of a clone of
36+
* {@code configureClosure} with a resolve strategy of {@code DELEGATE_FIRST}.</p>
37+
*
38+
* <p>If {@code target} does implement the {@link Configurable} interface, the {@code configureClosure} will be passed to
39+
* {@code delegate}'s {@link Configurable#configure(Closure)} method.</p>
40+
*
41+
* @param configureClosure The configuration closure
42+
* @param target The object to be configured
43+
* @return The delegate param
44+
*/
45+
static <T> T configure(@Nullable Closure configureClosure, T target) {
46+
if (configureClosure == null) {
47+
return target;
48+
}
49+
50+
if (target instanceof Configurable) {
51+
((Configurable) target).configure(configureClosure);
52+
} else {
53+
configureTarget(configureClosure, target, new ConfigureDelegate(configureClosure, target));
54+
}
55+
56+
return target;
57+
}
58+
59+
/**
60+
* Creates an action that uses the given closure to configure objects of type T.
61+
*/
62+
static <T> Action<T> configureUsing(@Nullable final Closure configureClosure) {
63+
if (configureClosure == null) {
64+
return Actions.doNothing();
65+
}
66+
67+
return new WrappedConfigureAction<T>(configureClosure);
68+
}
69+
70+
71+
private static <T> void configureTarget(Closure configureClosure, T target, ConfigureDelegate closureDelegate) {
72+
if (!(configureClosure instanceof GeneratedClosure)) {
73+
new ClosureBackedAction<T>(configureClosure, Closure.DELEGATE_FIRST, false).execute(target);
74+
return;
75+
}
76+
77+
// Hackery to make closure execution faster, by short-circuiting the expensive property and method lookup on Closure
78+
Closure withNewOwner = configureClosure.rehydrate(target, closureDelegate, configureClosure.getThisObject());
79+
new ClosureBackedAction<T>(withNewOwner, Closure.OWNER_ONLY, false).execute(target);
80+
}
81+
82+
83+
static class WrappedConfigureAction<T> implements Action<T> {
84+
private final Closure configureClosure;
85+
86+
WrappedConfigureAction(Closure configureClosure) {
87+
this.configureClosure = configureClosure;
88+
}
89+
90+
@Override
91+
void execute(T t) {
92+
configure(configureClosure, t);
93+
}
94+
95+
Closure getConfigureClosure() {
96+
return configureClosure;
97+
}
98+
}
99+
}

src/main/groovy/netflix/nebula/dependency/recommender/DependencyRecommendationsPlugin.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.gradle.api.logging.Logger;
3939
import org.gradle.api.logging.Logging;
4040
import org.gradle.api.plugins.ExtraPropertiesExtension;
41-
import org.gradle.internal.deprecation.DeprecationLogger;
4241

4342
import java.lang.reflect.Method;
4443
import java.util.*;
@@ -101,7 +100,7 @@ public Unit invoke(ResolvableDependencies resolvableDependencies) {
101100
}
102101

103102
for (Dependency dependency : resolvableDependencies.getDependencies()) {
104-
applyRecommendationToDependency(rsFactory, dependency, new ArrayList<ProjectDependency>());
103+
applyRecommendationToDependency(rsFactory, dependency, new ArrayList<ProjectDependency>(), project);
105104

106105
// if project dependency, pull all first orders and apply recommendations if missing dependency versions
107106
// dependency.getProjectConfiguration().allDependencies iterate and inspect them as well
@@ -160,7 +159,7 @@ private boolean isExcludedConfiguration(String confName) {
160159
return false;
161160
}
162161

163-
private void applyRecommendationToDependency(final RecommendationStrategyFactory factory, Dependency dependency, List<ProjectDependency> visited) {
162+
private void applyRecommendationToDependency(final RecommendationStrategyFactory factory, Dependency dependency, List<ProjectDependency> visited, Project rootProject) {
164163
if (dependency instanceof ExternalModuleDependency) {
165164
factory.getRecommendationStrategy().inspectDependency(dependency);
166165
} else if (dependency instanceof ProjectDependency) {
@@ -171,10 +170,11 @@ private void applyRecommendationToDependency(final RecommendationStrategyFactory
171170
try {
172171
ProjectDependency.class.getMethod("getTargetConfiguration");
173172
String targetConfiguration = projectDependency.getTargetConfiguration() == null ? Dependency.DEFAULT_CONFIGURATION : projectDependency.getTargetConfiguration();
173+
Project dependencyProject = rootProject.findProject(projectDependency.getPath());
174+
if (dependencyProject != null) {
175+
configuration[0] = dependencyProject.getConfigurations().getByName(targetConfiguration);
176+
}
174177

175-
DeprecationLogger.whileDisabled(() -> {
176-
configuration[0] = projectDependency.getDependencyProject().getConfigurations().getByName(targetConfiguration);
177-
});
178178
} catch (NoSuchMethodException ignore) {
179179
try {
180180
Method method = ProjectDependency.class.getMethod("getProjectConfiguration");
@@ -183,9 +183,11 @@ private void applyRecommendationToDependency(final RecommendationStrategyFactory
183183
throw new RuntimeException("Unable to retrieve configuration for project dependency", e);
184184
}
185185
}
186-
DependencySet dependencies = configuration[0].getAllDependencies();
187-
for (Dependency dep : dependencies) {
188-
applyRecommendationToDependency(factory, dep, visited);
186+
if (configuration[0] != null) {
187+
DependencySet dependencies = configuration[0].getAllDependencies();
188+
for (Dependency dep : dependencies) {
189+
applyRecommendationToDependency(factory, dep, visited, rootProject);
190+
}
189191
}
190192
}
191193
}

src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void execute(Configuration configuration) {
4343
Configuration toExtend = bom;
4444
if (!project.getRootProject().equals(project)) {
4545
toExtend = createCopy(bom.getDependencies(), bom.getDependencyConstraints());
46-
project.getConfigurations().add(toExtend);
46+
// No need to add to configurations - createCopy already handles this
4747
}
4848
configuration.extendsFrom(toExtend);
4949
} else {

src/main/groovy/netflix/nebula/dependency/recommender/provider/IvyRecommendationProvider.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package netflix.nebula.dependency.recommender.provider
22

33
import groovy.transform.CompileDynamic
4+
import groovy.xml.XmlSlurper
45
import org.gradle.api.Project
56

67
class IvyRecommendationProvider extends FileBasedRecommendationProvider {

src/main/groovy/netflix/nebula/dependency/recommender/provider/RecommendationProviderContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
package netflix.nebula.dependency.recommender.provider;
1717

1818
import groovy.lang.Closure;
19+
import netflix.nebula.dependency.recommender.ConfigureUtil;
1920
import netflix.nebula.dependency.recommender.DependencyRecommendationsPlugin;
2021
import netflix.nebula.dependency.recommender.RecommendationStrategies;
2122
import org.gradle.api.*;
2223
import org.gradle.api.artifacts.Dependency;
2324
import org.gradle.api.internal.ConfigureByMapAction;
2425
import org.gradle.api.internal.DefaultNamedDomainObjectList;
2526
import org.gradle.api.model.ObjectFactory;
26-
import org.gradle.util.ConfigureUtil;
2727
import org.gradle.util.GradleVersion;
2828

2929
import java.io.File;

0 commit comments

Comments
 (0)