Skip to content

Commit

Permalink
Merge pull request #58 from chali/AvoidResolvingDeprecatedConfigs
Browse files Browse the repository at this point in the history
Don't resolve configurations which are emmiting warning that shouldn't resolved
  • Loading branch information
chali authored Feb 6, 2020
2 parents 81fcfdf + b0c1cc3 commit 19a7a4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionP
class DependenciesInfoPlugin implements Plugin<Project>, InfoCollectorPlugin {
private final DefaultVersionComparator versionComparator = new DefaultVersionComparator()
private final VersionParser versionParser = new VersionParser()
private static final List<String> RESOLVABLE_WITH_DEPRECATION_CONF_SUFFIXES = ['compileOnly', 'compile', 'runtime']

@Override
void apply(Project project) {
Expand All @@ -38,20 +39,22 @@ class DependenciesInfoPlugin implements Plugin<Project>, InfoCollectorPlugin {
Map dependencies = [:]
project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin ->
project.configurations.all( { Configuration conf ->
conf.incoming.afterResolve { ResolvableDependencies resolvableDependencies ->
if (project.configurations.contains(conf)) {
String resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll {
it.id instanceof ModuleComponentIdentifier
}*.moduleVersion
.sort(true, { m1, m2 ->
if (m1.group != m2.group)
return m1.group <=> m2.group ?: -1
if (m1.name != m2.name)
return m1.name <=> m2.name // name is required
versionComparator.compare(new VersionInfo(versionParser.transform(m1.version)), new VersionInfo(versionParser.transform(m2.version)))
})*.toString().join(',')
if (resolvedDependencies) {
dependencies.put("Resolved-Dependencies-${resolvableDependencies.name.capitalize()}", resolvedDependencies)
if (canBeResolved(conf)) {
conf.incoming.afterResolve { ResolvableDependencies resolvableDependencies ->
if (project.configurations.contains(conf)) {
String resolvedDependencies = resolvableDependencies.resolutionResult.allComponents.findAll {
it.id instanceof ModuleComponentIdentifier
}*.moduleVersion
.sort(true, { m1, m2 ->
if (m1.group != m2.group)
return m1.group <=> m2.group ?: -1
if (m1.name != m2.name)
return m1.name <=> m2.name // name is required
versionComparator.compare(new VersionInfo(versionParser.transform(m1.version)), new VersionInfo(versionParser.transform(m2.version)))
})*.toString().join(',')
if (resolvedDependencies) {
dependencies.put("Resolved-Dependencies-${resolvableDependencies.name.capitalize()}", resolvedDependencies)
}
}
}
}
Expand All @@ -64,6 +67,10 @@ class DependenciesInfoPlugin implements Plugin<Project>, InfoCollectorPlugin {
}
}

private boolean canBeResolved(Configuration conf) {
conf.isCanBeResolved() && !RESOLVABLE_WITH_DEPRECATION_CONF_SUFFIXES.any { conf.name.toLowerCase().endsWith(it.toLowerCase()) }
}

@CompileDynamic
private void setInfoDependencies(Project project) {
if (!project.rootProject.hasProperty('nebulaInfoDependencies')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ class DependenciesInfoPluginSpec extends PluginProjectSpec {
project.apply plugin: DependenciesInfoPlugin

def guava = project.dependencies.create('com.google.guava:guava:21.0')
def slf4j = project.dependencies.create('org.slf4j:slf4j-api:1.7.30')

project.repositories.add(project.repositories.mavenCentral())

def configurations = project.configurations
def config = configurations.compile
config.dependencies.add(guava)
def compileConfig = configurations.compile
compileConfig.dependencies.add(guava)
configurations.implementation.dependencies.add(slf4j)

def detached = configurations.detachedConfiguration(guava)
configurations.add(detached)
configurations.remove(detached)

config.resolve()
compileConfig.resolve()
detached.resolve()
configurations.compileClasspath.resolve()

when:
brokerPlugin.buildFinished.set(true)
Expand Down

0 comments on commit 19a7a4b

Please sign in to comment.