From 81fb97342186493560dbc7d1613ee9d519adf9cd Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:23:34 +0100 Subject: [PATCH 1/2] Polishing - Register buildSrc version catalog lazily - Tidy DevPublishPlugin formatting --- buildSrc/settings.gradle.kts | 2 +- modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index b83c28b..9534819 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -29,7 +29,7 @@ dependencyResolutionManagement { } versionCatalogs { - create("libs") { + register("libs") { from(files("../gradle/libs.versions.toml")) } } diff --git a/modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt b/modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt index 9c9473e..f0207e6 100644 --- a/modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt +++ b/modules/dev-publish-plugin/src/main/kotlin/DevPublishPlugin.kt @@ -199,7 +199,7 @@ constructor( } devPubTasks.publishAllToDevRepo.configure { - // By name: `tasks.matching {}` and `tasks.named {}` realize every task when resolved. + // By name: `tasks.matching {}` and `tasks.named {}` realise every task when resolved. // Added here because the task only exists once maven-publish has the dev repo. dependsOn("publishAllPublicationsTo${DEV_PUB__MAVEN_REPO_NAME}Repository") } @@ -396,7 +396,6 @@ constructor( } } - private fun getGmm( project: Project, publication: MavenPublication, From 4553c4b166888397cb5eaab7a03360eac255e095 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:30:40 +0100 Subject: [PATCH 2/2] Improve test coverage - Test the repo checksum covers directories and duplicate contents. - Full runs must change when a file changes, moving every file must change the checksum, and files with equal contents in different directories must not be confused. - Test the dev publish service allows one usage at a time. - Test a custom devMavenRepo location. - Also check the repo checksum isn't the checksum of an empty repo. - Test signing when also publishing to Maven local. - Also match the start of Dev Publish's message, so a reworded message still fails the assertion. - Assert the exact deprecation problem in DeprecatedTaskTest. . The old assertions also matched unrelated report text. --- .../test/kotlin/DevPublishServiceUsageTest.kt | 26 +++++++ .../kotlin/DeprecatedTaskTest.kt | 5 +- .../kotlin/DevMavenRepoDependencyTest.kt | 43 ++++++++++- .../kotlin/RepoChecksumIncrementalTest.kt | 75 +++++++++++++++++++ .../src/testIntegration/kotlin/SigningTest.kt | 23 +++++- 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 modules/dev-publish-plugin/src/test/kotlin/DevPublishServiceUsageTest.kt diff --git a/modules/dev-publish-plugin/src/test/kotlin/DevPublishServiceUsageTest.kt b/modules/dev-publish-plugin/src/test/kotlin/DevPublishServiceUsageTest.kt new file mode 100644 index 0000000..e28f300 --- /dev/null +++ b/modules/dev-publish-plugin/src/test/kotlin/DevPublishServiceUsageTest.kt @@ -0,0 +1,26 @@ +package dev.adamko.gradle.dev_publish + +import dev.adamko.gradle.dev_publish.services.DevPublishService.Companion.SERVICE_NAME +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import org.gradle.kotlin.dsl.* +import org.gradle.testfixtures.ProjectBuilder + +/** + * Dev publish tasks in one project share a staging directory, + * so they must not run in parallel. + */ +class DevPublishServiceUsageTest : FunSpec({ + + val project = ProjectBuilder.builder() + .withName("foo-project") + .build() + project.plugins.apply(DevPublishPlugin::class) + + test("expect the service allows only one usage at a time") { + val registration = project.gradle.sharedServices.registrations + .getByName("${SERVICE_NAME}_${project.path}") + + registration.maxParallelUsages.orNull shouldBe 1 + } +}) diff --git a/modules/dev-publish-plugin/src/testIntegration/kotlin/DeprecatedTaskTest.kt b/modules/dev-publish-plugin/src/testIntegration/kotlin/DeprecatedTaskTest.kt index d1405f4..b690836 100644 --- a/modules/dev-publish-plugin/src/testIntegration/kotlin/DeprecatedTaskTest.kt +++ b/modules/dev-publish-plugin/src/testIntegration/kotlin/DeprecatedTaskTest.kt @@ -37,9 +37,8 @@ class DeprecatedTaskTest : FunSpec({ val reportContent = reportFile.readText() withClue("the Problems API entry should be in ${reportFile.name}") { - reportContent shouldContain "deprecated-task" - reportContent shouldContain "Dev Publish" - reportContent shouldContain "is deprecated" + reportContent shouldContain "Task ':generatePublicationHashTask' is deprecated" + reportContent shouldContain "Task 'generatePublicationHashTask', in root project 'deprecated-task', is deprecated. It will be removed in Dev Publish version 2.0." } } diff --git a/modules/dev-publish-plugin/src/testIntegration/kotlin/DevMavenRepoDependencyTest.kt b/modules/dev-publish-plugin/src/testIntegration/kotlin/DevMavenRepoDependencyTest.kt index 9b4d6e2..1bfda4f 100644 --- a/modules/dev-publish-plugin/src/testIntegration/kotlin/DevMavenRepoDependencyTest.kt +++ b/modules/dev-publish-plugin/src/testIntegration/kotlin/DevMavenRepoDependencyTest.kt @@ -4,6 +4,8 @@ import dev.adamko.gradle.dev_publish.test_utils.* import io.kotest.assertions.assertSoftly import io.kotest.core.spec.style.FunSpec import io.kotest.core.test.TestScope +import io.kotest.matchers.paths.shouldExist +import io.kotest.matchers.paths.shouldNotExist import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.matchers.string.* @@ -55,7 +57,7 @@ class DevMavenRepoDependencyTest : FunSpec({ .trim() assertSoftly { - repoChecksum shouldNotBe "no-files" + repoChecksum shouldNotBe EmptyRepoChecksum repoChecksum.shouldBeSingleLine() repoChecksum shouldHaveLength 64 // SHA-256 checksum length repoChecksum.shouldBeHexadecimal() @@ -64,6 +66,33 @@ class DevMavenRepoDependencyTest : FunSpec({ } } + context("a project with a custom devMavenRepo") { + val project = project(devMavenRepo = "custom-repo") + + test("expect the consumer's tests find the publication in the custom repo") { + project.runner + .withArguments(":test") + .forwardOutput() + .build { + shouldHaveTaskWithAnyOutcome(":test", SUCCESS, FROM_CACHE, UP_TO_DATE) + } + } + + test("expect the custom location is recorded") { + val repoLocation = project.projectDir + .resolve("build/tmp/.maven-dev/metadata/dev.publish.metadata.repo-location.txt") + .readText() + .trim() + + repoLocation shouldBe "../../../custom-repo" + } + + test("expect nothing is published to the default location") { + project.projectDir.resolve("build/custom-repo").shouldExist() + project.projectDir.resolve("build/maven-dev").shouldNotExist() + } + } + context("a project where updateDevRepo is disabled") { // the metadata file still records where the repo would be, so the recorded path resolves to a // directory that was never created @@ -98,11 +127,19 @@ class DevMavenRepoDependencyTest : FunSpec({ companion object { - private fun TestScope.project(): GradleProjectTest = + /** SHA-256 of no input, which is the checksum of an empty repo. */ + private const val EmptyRepoChecksum = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + + /** @param[devMavenRepo] `devPublish.devMavenRepo`, relative to the build dir, or `null` for the default. */ + private fun TestScope.project( + devMavenRepo: String? = null, + ): GradleProjectTest = gradleKtsProjectTest( projectName = "dev-maven-repo-dependency", testProjectPath = testCase.descriptor.slashSeparatedPath(), ) { + // an earlier run would have left the default repo behind + file("build").deleteRecursively() buildGradleKts = """ |plugins { @@ -122,6 +159,8 @@ class DevMavenRepoDependencyTest : FunSpec({ | } |} | + |${devMavenRepo?.let { "devPublish.devMavenRepo = layout.buildDirectory.dir(\"$it\")" } ?: ""} + | |dependencies { | testImplementation(devPublish.dependency()) | testImplementation(kotlin("test")) diff --git a/modules/dev-publish-plugin/src/testIntegration/kotlin/RepoChecksumIncrementalTest.kt b/modules/dev-publish-plugin/src/testIntegration/kotlin/RepoChecksumIncrementalTest.kt index c8c416e..ee7b805 100644 --- a/modules/dev-publish-plugin/src/testIntegration/kotlin/RepoChecksumIncrementalTest.kt +++ b/modules/dev-publish-plugin/src/testIntegration/kotlin/RepoChecksumIncrementalTest.kt @@ -5,6 +5,7 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.core.test.TestCaseOrder import io.kotest.core.test.TestScope import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe import kotlin.io.path.* /** @@ -51,6 +52,80 @@ class RepoChecksumIncrementalTest : FunSpec({ } } + context("when one file in a shared directory changes, in a full run") { + val project = project() + + // full runs, because an incremental run only re-hashes the changed file + RepoFiles.forEach { repoFile -> + test("expect modifying $repoFile changes the checksum") { + val file = project.projectDir.resolve("$RepoDir/$repoFile") + val original = file.readText() + + project.runGenerate("--rerun") + val before = project.repoChecksum() + + file.writeText("modified") + project.runGenerate("--rerun") + val after = project.repoChecksum() + + file.writeText(original) + after shouldNotBe before + } + } + } + + context("when every file moves to another directory") { + val project = project() + + // move every file, so only the directory changes, not which contents are present + test("expect the checksum changes") { + project.runGenerate() + val before = project.repoChecksum() + + RepoFiles.forEach { repoFile -> + project.projectDir.resolve("$RepoDir/$repoFile").moveTo( + project.projectDir.resolve("fake-repo/com/example/lib/2.0.0/$repoFile") + .createParentDirectories() + ) + } + project.runGenerate() + + project.repoChecksum() shouldNotBe before + } + } + + context("when two files in different directories have the same contents") { + val project = project() + + // like empty javadoc jars from two modules + val libJavadoc = project.projectDir.resolve("$RepoDir/lib-1.0.0-javadoc.jar") + val otherJavadoc = project.projectDir.resolve("fake-repo/com/example/other/1.0.0/other-1.0.0-javadoc.jar") + listOf(libJavadoc, otherJavadoc).forEach { file -> + file.createParentDirectories().writeText("empty javadoc") + } + + // only contents change, so the file set is unchanged and the second run is incremental + test("expect modifying one of them gives the full-run checksum") { + project.runGenerate() + otherJavadoc.writeText("modified") + project.runGenerate() + val incremental = project.repoChecksum() + + project.runGenerate("--rerun") + project.repoChecksum() shouldBe incremental + } + + test("expect changing a file to match another file's contents gives the full-run checksum") { + project.runGenerate() + otherJavadoc.writeText(libJavadoc.readText()) + project.runGenerate() + val incremental = project.repoChecksum() + + project.runGenerate("--rerun") + project.repoChecksum() shouldBe incremental + } + } + context("when every file is renamed, like a SNAPSHOT re-publish") { val project = project() diff --git a/modules/dev-publish-plugin/src/testIntegration/kotlin/SigningTest.kt b/modules/dev-publish-plugin/src/testIntegration/kotlin/SigningTest.kt index 5742339..37d5389 100644 --- a/modules/dev-publish-plugin/src/testIntegration/kotlin/SigningTest.kt +++ b/modules/dev-publish-plugin/src/testIntegration/kotlin/SigningTest.kt @@ -6,6 +6,7 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.core.test.TestScope import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldNotContain +import kotlin.io.path.invariantSeparatorsPathString import org.gradle.testkit.runner.TaskOutcome.SKIPPED /** @@ -73,7 +74,27 @@ class SigningTest : FunSpec({ output shouldContain "no configured signatory" // signing is genuinely required here, so Gradle's error is the correct one. // Dev Publish must not replace it with advice the build has already followed. - output shouldNotContain "cannot publish to the dev Maven repository without a signatory" + output shouldNotContain "Dev Publish cannot publish" + } + } + } + + context("when the same build also publishes to Maven local") { + // todo also test a custom file-based repo + val project = project(setRequired = "publishingOutsideDevRepo") + + test("expect signing is NOT skipped, and the build fails without a signatory") { + project.runner + .withArguments( + ":updateDevRepo", + ":publishMavenJavaPublicationToMavenLocal", + // keep the real ~/.m2 untouched, in case signing is skipped and the publish succeeds + "-Dmaven.repo.local=${project.projectDir.resolve("maven-local").invariantSeparatorsPathString}", + ) + .forwardOutput() + .buildAndFail { + output shouldContain "no configured signatory" + output shouldNotContain "Dev Publish cannot publish" } } }