Skip to content

Commit

Permalink
Merge pull request #6 from usefulness/updates
Browse files Browse the repository at this point in the history
Ignore dependenceis without versions
  • Loading branch information
mateuszkwiecinski authored Mar 30, 2024
2 parents 3d473ab + dd04dff commit 8728fab
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
2 changes: 0 additions & 2 deletions maven-sympathy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ gradlePlugin {
}

dependencies {
compileOnly(libs.kotlin.gradle.api)

testRuntimeOnly(libs.junit.platform.launcher)
testRuntimeOnly(libs.junit.jupiter.engine)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ public class MavenSympathyPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = with(target) {
val reportingExtension = extensions.getByType(ReportingExtension::class.java)
val task = tasks.register("sympathyForMrMaven", SympathyForMrMavenTask::class.java) {
outputFile.set(reportingExtension.baseDirectory.map { it.dir("sympathyForMrMaven").file("output.txt") })
outputFile.set(reportingExtension.baseDirectory.map { it.dir(name).file("output.txt") })
}
configurations.configureEach {
if (!isCanBeResolved) return@configureEach

configurations.matching { it.isCanBeResolved }.configureEach {
task.configure {
if (!isCanBeResolved) return@configure
configurationWithDependencies.put(this@configureEach.name, incoming.resolutionResult.rootComponent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,26 @@ public open class SympathyForMrMavenTask @Inject constructor(objectFactory: Obje
public fun run() {
var fail = false
configurationWithDependencies.get().forEach { (name, root) ->
root.dependencies.filterIsInstance<ResolvedDependencyResult>().forEach { rdr ->
val requested = rdr.requested as? ModuleComponentSelector ?: return@forEach
val selected = rdr.selected
val requestedVersion = requested.version
val selectedVersion = selected.moduleVersion?.version
if (requestedVersion != selectedVersion) {
logger.error("[$name] requested: $requested changed to $selectedVersion")
fail = true
root.dependencies.asSequence()
.filterIsInstance<ResolvedDependencyResult>()
.filter { it.requested is ModuleComponentSelector }
.forEach { rdr ->
val requested = rdr.requested as? ModuleComponentSelector
val selected = rdr.selected
val requestedVersion = requested?.version
val selectedVersion = selected.moduleVersion?.version
if (!requestedVersion.isNullOrBlank() && requestedVersion != selectedVersion) {
logger.error("[$name] dependency $requested version changed $requestedVersion -> $selectedVersion")
fail = true
}
}
}
}
val report = outputFile.get().asFile
if (fail) {
report.writeText("NOT OK")
error("Declared dependencies were upgraded transitively. See task output above. Please update their versions.")
} else {
report.writeText("OK")
}
outputFile.get().asFile.writeText("OK")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ class IntegrationTest {
// language=groovy
writeText(
"""
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
}
}
""".trimIndent(),
)
}
Expand All @@ -41,6 +48,15 @@ class IntegrationTest {
id("java-library")
id("io.github.usefulness.maven-sympathy")
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.2")
}
""".trimIndent(),
)
}
Expand Down Expand Up @@ -96,6 +112,6 @@ class IntegrationTest {
}
val result = runGradle(projectDir = rootDirectory, shouldFail = true)

assertThat(result.output).contains("com.squareup.okhttp3:okhttp:3.14.8 changed to 3.14.9")
assertThat(result.output).contains("com.squareup.okhttp3:okhttp:3.14.8 version changed 3.14.8 -> 3.14.9")
}
}

0 comments on commit 8728fab

Please sign in to comment.