Configuring multiple upload repositories in Gradle build

♀尐吖头ヾ 提交于 2019-11-30 10:23:24
Peter Niederwieser

One solution is to add an if-else statement that adds exactly one of the two deployers depending on the circumstances. For example:

// should defer decision until end of configuration phase
gradle.projectsEvaluated {
    uploadArchives {
        repositories {
            mavenDeployer {
                if (version.endsWith("-SNAPSHOT")) { ... } else { ... }
            }               
        }
    }
}

If you do need to vary the configuration based on whether some task is "present", you can either make an eager decision based on gradle.startParameter.taskNames (but then you'll only catch tasks that are specified as part of the Gradle invocation), or use the gradle.taskGraph.whenReady callback (instead of gradle.projectsEvaluated) and check whether the task is scheduled for execution.

user1933178

Correct me if I'm wrong, but shouldn't you use the separate snapshotRepository in this case (as opposed to an if statement)? For example,

mavenDeployer {

  repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
    authentication(userName: sonatypeUsername, password: sonatypePassword)
  }

  snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
    authentication(userName: sonatypeUsername, password: sonatypePassword)
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!