Skip to content

Commit 0e3efd6

Browse files
committed
Fix root publishing script
When making changes to publishing of the fatJar artifacts to the download raw repo instead of the maven repo (#777), I removed some code that was necessary for passing credentials to the code that handles publishing to the maven repo. This PR restores that code and now things work again.
1 parent c7499ae commit 0e3efd6

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

gradle/root/publishing.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,21 @@ def publishFatJarsTask = tasks.register('publishFatJars', PublishToRawRepoTask)
105105
}
106106

107107
publish.dependsOn publishFatJarsTask
108+
109+
// The "publish" tasks for all subprojects require credentials for our Nexus server, which they look for in Gradle
110+
// properties. If those properties (i.e. NEXUS_USERNAME_KEY and NEXUS_PASSWORD_KEY) haven't been provided, the build
111+
// will fail. Therefore, we only want to configure credentials when a "publish" task is part of the execution plan.
112+
// Otherwise, unavailable credentials could cause a build to fail even if we aren't doing any publishing. The
113+
// TaskExecutionGraph allows us to do that.
114+
gradle.taskGraph.whenReady {TaskExecutionGraph taskGraph ->
115+
// This won't find any publishToMavenLocal tasks. Those are of type PublishToMavenLocal
116+
Collection<Task> mavenPublishTasks = taskGraph.allTasks.findAll {
117+
it instanceof PublishToMavenRepository
118+
}
119+
mavenPublishTasks.each {
120+
it.repository.credentials.with {
121+
username = getPropertyOrFailBuild NEXUS_USERNAME_KEY
122+
password = getPropertyOrFailBuild NEXUS_PASSWORD_KEY
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)