|
| 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