From 553b8814db8e2488eac569d0a7e045ef27760300 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Tue, 21 Mar 2023 13:44:38 -0700 Subject: [PATCH] Support Gradle 8.1 --- .../ExtendRecommenderConfigurationAction.java | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java b/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java index 7046873..0b36cbd 100644 --- a/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java +++ b/src/main/groovy/netflix/nebula/dependency/recommender/ExtendRecommenderConfigurationAction.java @@ -2,11 +2,21 @@ import netflix.nebula.dependency.recommender.provider.RecommendationProviderContainer; import org.gradle.api.Action; +import org.gradle.api.DomainObjectSet; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencyConstraint; +import org.gradle.api.artifacts.ExcludeRule; +import org.gradle.api.internal.artifacts.DefaultExcludeRule; +import org.gradle.api.internal.artifacts.configurations.DefaultConfiguration; +import org.gradle.api.internal.artifacts.dependencies.DependencyConstraintInternal; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + public class ExtendRecommenderConfigurationAction implements Action { private Logger logger = Logging.getLogger(ExtendRecommenderConfigurationAction.class); @@ -15,6 +25,8 @@ public class ExtendRecommenderConfigurationAction implements ActionNOT a strictly identical copy of the original, as the role + * will be not only a different instance, but also may return different deprecation values. + */ + private DefaultConfiguration createCopy(Set dependencies, Set dependencyConstraints) { + DefaultConfiguration copiedConfiguration = (DefaultConfiguration) project.getConfigurations().create(getNameWithCopySuffix()); + copiedConfiguration.setVisible(false); + copiedConfiguration.setCanBeResolved(false); + copiedConfiguration.setCanBeConsumed(bom.isCanBeConsumed()); + copiedConfiguration.setTransitive(bom.isTransitive()); + copiedConfiguration.setDescription(bom.getDescription()); + copiedConfiguration.getArtifacts().addAll(bom.getAllArtifacts()); + for (ExcludeRule excludeRule : bom.getExcludeRules()) { + copiedConfiguration.getExcludeRules().add(new DefaultExcludeRule(excludeRule.getGroup(), excludeRule.getModule())); + } + DomainObjectSet copiedDependencies = copiedConfiguration.getDependencies(); + for (Dependency dependency : dependencies) { + copiedDependencies.add(dependency.copy()); + } + DomainObjectSet copiedDependencyConstraints = copiedConfiguration.getDependencyConstraints(); + for (DependencyConstraint dependencyConstraint : dependencyConstraints) { + copiedDependencyConstraints.add(((DependencyConstraintInternal) dependencyConstraint).copy()); + } + return copiedConfiguration; + } + + private String getNameWithCopySuffix() { + int count = this.copyCount.incrementAndGet(); + String copyName = bom.getName() + "Copy"; + return count == 1 ? copyName : copyName + count; + } + //we want to apply recommendation only into final resolvable configurations like `compileClasspath` or `runtimeClasspath` across all source sets. private boolean isClasspathConfiguration(Configuration configuration) { return configuration.getName().endsWith("Classpath") || configuration.getName().toLowerCase().endsWith("annotationprocessor");