Skip to content

Commit 7a705b4

Browse files
authored
Only configure dev-publish PublishToMavenRepository tasks (#82)
Configuring all publication tasks can cause issues with other plugins. Example: dev-publish adds outputs to the publication tasks, which means the tasks won't re-run if the inputs haven't changed, which nmcp relied on GradleUp/nmcp#216
1 parent 283636e commit 7a705b4

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/main/kotlin/DevPublishPlugin.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ constructor(
9393
)
9494

9595
project.tasks.withType<PublishToMavenRepository>().configureEach {
96-
configurePublishToMavenRepositoryTask(devPubExtension, devPubService)
96+
if (name.endsWith("To${DEV_PUB__MAVEN_REPO_NAME}Repository")) {
97+
configurePublishToMavenRepositoryTask(devPubExtension, devPubService)
98+
}
9799
}
98100
}
99101

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package dev.adamko.gradle.dev_publish
2+
3+
import dev.adamko.gradle.dev_publish.DevPublishPlugin.Companion.DEV_PUB__MAVEN_REPO_NAME
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.inspectors.forAtLeastOne
6+
import io.kotest.matchers.maps.shouldHaveKey
7+
import io.kotest.matchers.maps.shouldNotHaveKey
8+
import io.kotest.matchers.shouldBe
9+
import io.kotest.matchers.types.shouldBeInstanceOf
10+
import org.gradle.api.plugins.JavaLibraryPlugin
11+
import org.gradle.api.publish.PublishingExtension
12+
import org.gradle.api.publish.maven.MavenPublication
13+
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
14+
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
15+
import org.gradle.kotlin.dsl.*
16+
import org.gradle.testfixtures.ProjectBuilder
17+
18+
class ConfigurePublishTasksTest : FunSpec({
19+
context("given project with multiple publish tasks") {
20+
val project = ProjectBuilder.builder()
21+
.withName("foo-project")
22+
.build()
23+
24+
with(project) {
25+
plugins.apply(JavaLibraryPlugin::class)
26+
plugins.apply(DevPublishPlugin::class)
27+
plugins.apply(MavenPublishPlugin::class)
28+
29+
extensions.configure<PublishingExtension> {
30+
repositories {
31+
maven(layout.buildDirectory.dir("project-local-repo")) {
32+
name = "ProjectLocalRepo"
33+
}
34+
}
35+
publications.create<MavenPublication>("mavenJava") {
36+
from(project.components["java"])
37+
}
38+
}
39+
}
40+
41+
val publishTasks = project.tasks.withType<PublishToMavenRepository>()
42+
43+
test("should have publish tasks") {
44+
publishTasks.forAtLeastOne { task ->
45+
task.repository.name shouldBe "ProjectLocalRepo"
46+
}
47+
publishTasks.forAtLeastOne { task ->
48+
task.repository.name shouldBe DEV_PUB__MAVEN_REPO_NAME
49+
}
50+
}
51+
52+
test("dev-publish should only configure dev-publish tasks") {
53+
publishTasks.forEach { task ->
54+
if (task.name.endsWith("To${DEV_PUB__MAVEN_REPO_NAME}Repository")) {
55+
task.inputs.properties shouldHaveKey "repoIsDevPub"
56+
task.inputs.properties["repoIsDevPub"]
57+
.shouldBeInstanceOf<Boolean>() shouldBe true
58+
} else {
59+
task.inputs.properties shouldNotHaveKey "repoIsDevPub"
60+
}
61+
}
62+
}
63+
}
64+
})

0 commit comments

Comments
 (0)