@@ -82,7 +82,7 @@ def createChecksumsTask = tasks.register('createChecksums') {
8282 }
8383 }
8484 }
85- dependsOn buildDap4Lib, buildNcIdv, buildNetcdfAll, buildToolsUI
85+ dependsOn buildNcIdv, buildNetcdfAll, buildToolsUI
8686}
8787
8888def publishFatJarsTask = tasks. register(' publishFatJars' , PublishToRawRepoTask ) {
@@ -105,3 +105,21 @@ def publishFatJarsTask = tasks.register('publishFatJars', PublishToRawRepoTask)
105105}
106106
107107publish. 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