So it turns out my question was somewhat wrong. I'd wrongly assumed that the closure for adding publishing repos for maven would be run at the time of the task. However:
uploadArchives {
addSomeRepos()
}
is configuring the uploadArchives task, and so is run at the time at which it is found in the buildscript. Hence setting the username and password in a task, which will run after the buildscript, means they're null at setup.
I fixed this by changing my getAuth task to a createPublishTargets task which does the configuration of the uploadArchives task inside the task. This works perfectly.
task createPublishTarget << {
ext {
username = System.console().readLine("\nusername: ")
password = System.console().readPassword("password: ").toString()
}
allprojects {
uploadArchives {
repositories {
mavenDeployer {
repository(url: "my-artifactory") {
authentication(userName: createPublishTarget.username, password: createPublishTarget.password)
}
}
}
}
}
}
Although I did still come across an interesting issue that authentication(//blah)
configures a different object than I was expecting, so you have to explicitly get the set properties from the task.