Skip to content

Commit 09b77a5

Browse files
fix: compute/printDuplicateDependencies works even when not all projects apply this plugin.
1 parent 523d7bc commit 09b77a5

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/functionalTest/groovy/com/autonomousapps/android/DuplicateDependencyVersionsSpec.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ final class DuplicateDependencyVersionsSpec extends AbstractAndroidSpec {
3535
.containsExactlyElementsIn(project.expectedResolvedDependenciesForLib2)
3636
.inOrder()
3737
38+
and: 'jvm-lib resolved dependencies'
39+
assertThat(project.actualResolvedDependenciesFor('group:jvm-lib'))
40+
.containsExactlyElementsIn(project.expectedResolvedDependenciesForJvmLib)
41+
.inOrder()
42+
3843
and: 'duplicates report'
3944
def report = project.actualDuplicateDependencies()
4045
assertThat(report['junit:junit']).containsExactlyElementsIn('4.11', '4.12', '4.13').inOrder()

src/functionalTest/groovy/com/autonomousapps/android/projects/DuplicateDependencyVersionsProject.groovy

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package com.autonomousapps.android.projects
44

55
import com.autonomousapps.kit.GradleProject
66
import com.autonomousapps.kit.gradle.Dependency
7-
import com.autonomousapps.kit.gradle.dependencies.Plugins
87

98
import static com.autonomousapps.AdviceHelper.duplicateDependenciesReport
109
import static com.autonomousapps.AdviceHelper.resolvedDependenciesReport
@@ -44,15 +43,23 @@ final class DuplicateDependencyVersionsProject extends AbstractAndroidProject {
4443
]
4544
}
4645
}
47-
.withAndroidLibProject('lib2', 'com.example.lib2') { assets ->
48-
assets.withBuildScript { bs ->
46+
.withAndroidLibProject('lib2', 'com.example.lib2') { lib ->
47+
lib.withBuildScript { bs ->
4948
bs.plugins = androidLibPlugin
5049
bs.android = defaultAndroidLibBlock(false, 'com.example.lib2')
5150
bs.dependencies = [
5251
new Dependency('api', 'junit:junit:4.13')
5352
]
5453
}
55-
}.write()
54+
}
55+
// This "project" only exists for organizational reasons
56+
.withSubproject('group') {}
57+
.withSubproject('group:jvm-lib') { lib ->
58+
lib.withBuildScript { bs ->
59+
bs.plugins = javaLibrary
60+
}
61+
}
62+
.write()
5663
}
5764

5865
Map<String, Set<String>> actualDuplicateDependencies() {
@@ -105,4 +112,6 @@ final class DuplicateDependencyVersionsProject extends AbstractAndroidProject {
105112
'junit:junit:4.13',
106113
'org.hamcrest:hamcrest-core:1.3',
107114
]
115+
116+
List<String> expectedResolvedDependenciesForJvmLib = []
108117
}

src/main/kotlin/com/autonomousapps/subplugin/RootPlugin.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ internal class RootPlugin(private val project: Project) {
9696
val paths = RootOutputPaths(this)
9797

9898
val computeDuplicatesTask = tasks.register<ComputeDuplicateDependenciesTask>("computeDuplicateDependencies") {
99-
resolvedDependenciesReports.setFrom(resolvedDepsResolver.internal)
99+
resolvedDependenciesReports.setFrom(resolvedDepsResolver.internal.map { c ->
100+
c.incoming.artifactView {
101+
// Not all projects in the build will have DAGP applied, meaning they won't have any artifact to consume.
102+
// Setting `lenient(true)` means we can still have a dependency on those projects, and not fail this task when
103+
// we find nothing there.
104+
lenient(true)
105+
}.artifacts.artifactFiles
106+
})
100107
output.set(paths.duplicateDependenciesPath)
101108
}
102109

0 commit comments

Comments
 (0)