Setting repository url programmatically depending on task graph


I have a problem whereby I would like to switch between a local ivy repository for publishing to a “public” one, depending upon whether I am doing a release or not. I am using the new ivy-publish interface.

Now, how would I do that if I want to locate this code to a plugin, which is perhaps only applied in the root project?

The problem appears to me to be that declaring publishing repositories happen at configuration time, but I cannot query the taskgraph until it is ready, which is then at execution time? Now, if I communicate the target repo via an external property I have to have it set to the local default and then change it afterwards when I have interrogated the taskgraph, but I don’t see it changing to the public repo … rather it is always stuck with the local default I had initially.

publishing {

repositories {

url gradle.ext.targetRepo



invocation would be gradlew release :subproject:publish

I assume a closure solution is what I need but I am not clear on how to do that in this case.

(Luke Daley) #2

The most common way to do this is to use the gradle.taskGraph.whenReady hook:


I was doing that but couldn’t get it to work. Got very frustrated and then realised - after looking at the ivy-publish documentation and the 1.5 release notes (which appear to be broken - see other comment, but I can’t blame it on that because I didn’t read them properly this time) that it was the ivy-publish functionality that had changed which meant that nothing was getting published.

I’ll write a separate suggestion to deal with the more frustrating aspects of working with Gradle.