Skip to content

Commit

Permalink
fix: compute/printDuplicateDependencies works even when not all proje…
Browse files Browse the repository at this point in the history
…cts apply this plugin.
  • Loading branch information
autonomousapps committed Jan 29, 2025
1 parent 523d7bc commit 09b77a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ final class DuplicateDependencyVersionsSpec extends AbstractAndroidSpec {
.containsExactlyElementsIn(project.expectedResolvedDependenciesForLib2)
.inOrder()
and: 'jvm-lib resolved dependencies'
assertThat(project.actualResolvedDependenciesFor('group:jvm-lib'))
.containsExactlyElementsIn(project.expectedResolvedDependenciesForJvmLib)
.inOrder()
and: 'duplicates report'
def report = project.actualDuplicateDependencies()
assertThat(report['junit:junit']).containsExactlyElementsIn('4.11', '4.12', '4.13').inOrder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package com.autonomousapps.android.projects

import com.autonomousapps.kit.GradleProject
import com.autonomousapps.kit.gradle.Dependency
import com.autonomousapps.kit.gradle.dependencies.Plugins

import static com.autonomousapps.AdviceHelper.duplicateDependenciesReport
import static com.autonomousapps.AdviceHelper.resolvedDependenciesReport
Expand Down Expand Up @@ -44,15 +43,23 @@ final class DuplicateDependencyVersionsProject extends AbstractAndroidProject {
]
}
}
.withAndroidLibProject('lib2', 'com.example.lib2') { assets ->
assets.withBuildScript { bs ->
.withAndroidLibProject('lib2', 'com.example.lib2') { lib ->
lib.withBuildScript { bs ->
bs.plugins = androidLibPlugin
bs.android = defaultAndroidLibBlock(false, 'com.example.lib2')
bs.dependencies = [
new Dependency('api', 'junit:junit:4.13')
]
}
}.write()
}
// This "project" only exists for organizational reasons
.withSubproject('group') {}
.withSubproject('group:jvm-lib') { lib ->
lib.withBuildScript { bs ->
bs.plugins = javaLibrary
}
}
.write()
}

Map<String, Set<String>> actualDuplicateDependencies() {
Expand Down Expand Up @@ -105,4 +112,6 @@ final class DuplicateDependencyVersionsProject extends AbstractAndroidProject {
'junit:junit:4.13',
'org.hamcrest:hamcrest-core:1.3',
]

List<String> expectedResolvedDependenciesForJvmLib = []
}
9 changes: 8 additions & 1 deletion src/main/kotlin/com/autonomousapps/subplugin/RootPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ internal class RootPlugin(private val project: Project) {
val paths = RootOutputPaths(this)

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

Expand Down

0 comments on commit 09b77a5

Please sign in to comment.