Skip to content

Commit 452169e

Browse files
committed
fix broken non-publish builds outside of git
1 parent 1ba0d11 commit 452169e

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

src/main/kotlin/nebula/plugin/publishing/NebulaOssPublishingPlugin.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac
4848

4949
project.plugins.withId("com.netflix.nebula.release") {
5050
project.afterEvaluate {
51-
project.tasks.withType<PublishToMavenRepository> {
52-
mustRunAfter(project.rootProject.tasks.named("release"))
53-
}
54-
project.rootProject.tasks.named("postRelease") {
55-
dependsOn(project.tasks.withType<PublishToMavenRepository>())
51+
if(project.rootProject.tasks.findByName("release") != null) {
52+
project.tasks.withType<PublishToMavenRepository> {
53+
mustRunAfter(project.rootProject.tasks.named("release"))
54+
}
5655
}
56+
project.rootProject.tasks.findByName("postRelease")
57+
?.dependsOn(project.tasks.withType<PublishToMavenRepository>())
5758
}
5859
}
5960
}
@@ -194,9 +195,11 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac
194195
projectExecutionHasTask(project, "snapshot") || projectExecutionHasTask(project, "devSnapshot") || projectExecutionHasTask(project, "immutableSnapshot") -> {
195196
extension.netflixOssRepository.convention(netflixOssSnapshotsRepository)
196197
}
198+
197199
projectExecutionHasTask(project, "candidate") -> {
198200
extension.netflixOssRepository.convention(netflixOssCandidatesRepository)
199201
}
202+
200203
projectExecutionHasTask(project, "final") -> {
201204
extension.netflixOssRepository.convention(netflixOssReleasesRepository)
202205
}
@@ -207,9 +210,11 @@ open class NebulaOssPublishingPlugin @Inject constructor(private val providerFac
207210
projectExecutionHasTask(project, "snapshot") || projectExecutionHasTask(project, "devSnapshot") || projectExecutionHasTask(project, "immutableSnapshot") -> {
208211
extension.netflixOssRepository.convention(netflixOssSnapshotsRepository)
209212
}
213+
210214
projectExecutionHasTask(project, "candidate") -> {
211215
extension.netflixOssRepository.convention(netflixOssCandidatesRepository)
212216
}
217+
213218
projectExecutionHasTask(project, "final") -> {
214219
extension.netflixOssRepository.convention(netflixOssReleasesRepository)
215220
}

src/test/kotlin/nebula/plugin/publishing/NebulaOssPublishingPluginTest.kt

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package nebula.plugin.publishing
22

3+
import nebula.test.dsl.*
34
import nebula.test.dsl.TestKitAssertions.assertThat
4-
import nebula.test.dsl.plugins
5-
import nebula.test.dsl.rootProject
6-
import nebula.test.dsl.testProject
7-
import nebula.test.dsl.version
85
import org.gradle.testkit.runner.TaskOutcome
96
import org.junit.jupiter.api.Test
107
import org.junit.jupiter.api.io.TempDir
@@ -17,26 +14,23 @@ internal class NebulaOssPublishingPluginTest {
1714
@TempDir
1815
lateinit var remoteGitDir: File
1916

20-
@Test
21-
fun `test single project final`() {
22-
val runner = withGitTag(projectDir, remoteGitDir, "v0.0.1") {
23-
testProject(projectDir) {
24-
rootProject {
25-
plugins {
26-
id("java")
27-
// this plugin has behavior dependent on the existence of the contacts plugin
28-
id("com.netflix.nebula.contacts") version "latest.release"
29-
// this plugin has behavior dependent on the existence of the info plugin
30-
id("com.netflix.nebula.info") version "latest.release"
31-
id("com.netflix.nebula.maven-publish") version "latest.release"
32-
// this plugin has behavior dependent on the existence of the release plugin
33-
id("com.netflix.nebula.release") version "latest.release"
34-
id("com.netflix.nebula.maven-apache-license") version "latest.release"
35-
id("com.netflix.nebula.oss-publishing")
36-
}
37-
//language=kotlin
38-
rawBuildScript(
39-
"""
17+
private fun TestProjectBuilder.sampleSingleProjectSetup() {
18+
rootProject {
19+
plugins {
20+
id("java")
21+
// this plugin has behavior dependent on the existence of the contacts plugin
22+
id("com.netflix.nebula.contacts") version "latest.release"
23+
// this plugin has behavior dependent on the existence of the info plugin
24+
id("com.netflix.nebula.info") version "latest.release"
25+
id("com.netflix.nebula.maven-publish") version "latest.release"
26+
// this plugin has behavior dependent on the existence of the release plugin
27+
id("com.netflix.nebula.release") version "latest.release"
28+
id("com.netflix.nebula.maven-apache-license") version "latest.release"
29+
id("com.netflix.nebula.oss-publishing")
30+
}
31+
//language=kotlin
32+
rawBuildScript(
33+
"""
4034
group = "test"
4135
description = "description"
4236
nebulaOssPublishing {
@@ -53,8 +47,15 @@ contacts {
5347
$DISABLE_PUBLISH_TASKS
5448
$DISABLE_MAVEN_CENTRAL_TASKS
5549
"""
56-
)
57-
}
50+
)
51+
}
52+
}
53+
54+
@Test
55+
fun `test single project final`() {
56+
val runner = withGitTag(projectDir, remoteGitDir, "v0.0.1") {
57+
testProject(projectDir) {
58+
sampleSingleProjectSetup()
5859
}
5960
}
6061
val result = runner.run(
@@ -88,4 +89,15 @@ $DISABLE_MAVEN_CENTRAL_TASKS
8889
assertThat(result.task(":postRelease")).hasOutcome(TaskOutcome.SUCCESS)
8990
assertThat(result.task(":final")).hasOutcome(TaskOutcome.SUCCESS)
9091
}
92+
93+
@Test
94+
fun `test build without git tag`() {
95+
val runner = testProject(projectDir) {
96+
sampleSingleProjectSetup()
97+
}
98+
val result = runner.run("build", "--stacktrace")
99+
assertThat(result.task(":release")).isNull()
100+
assertThat(result.task(":postRelease")).isNull()
101+
assertThat(result.task(":build")).hasOutcome(TaskOutcome.SUCCESS)
102+
}
91103
}

0 commit comments

Comments
 (0)