On 24/08/2011, at 9:10 PM, Etienne Studer (practicalgradle.org) wrote:

> Hi
> 
> I'd like to set the repository URL used by the mavenDeployer of the 
> uploadArchives task at the time the DAG is ready and not when the 
> uploadArchives task is configured. Does anyone have an idea how I can achieve 
> this?
> 
> gradle.taskGraph.whenReady { taskGraph ->
>    if (!taskGraph.hasTask(':release')) {
>        version += '-SNAPSHOT'
>        // --> calculate the deploymentRepoUrl here based on the tasks 
> available in the DAG
>    }
> }
> 
> …
> 
> uploadArchives {
>    repositories {
>        mavenDeployer { 
>            repository(url: deploymentRepoUrl) {
>                authentication(...)
>            }
>       }
>    }
> }

I'm not quite sure on what is up for mutation after that task graph is 
assembled so this may not work, but try this:

gradle.taskGraph.whenReady { taskGraph ->
    if (!taskGraph.hasTask(':release')) {
        version += '-SNAPSHOT'
        uploadArchives.repositories["mavenDeployer"].repository.url = 
"http://myrepo.org";
    }
}

This will only work if somewhere else in the build you have something like:

uploadArchives {
   repositories {
       mavenDeployer { 
           repository(url: deploymentRepoUrl) {
               authentication(...)
           }
      }
   }
} 

You'll notice that in the taskGraph.whenReady block we use a slightly different 
syntax to get the deployer. This syntax fetches an existing deployer, while the 
one used in uploadArchives creates one (overriding any previous ones). So 
whenever you want to modify the deployer after it's been created you need to 
use the «uploadTask».repositories["mavenDeployer"] syntax (which gives you one 
of these: 
http://gradle.org/current/docs/javadoc/org/gradle/api/artifacts/maven/MavenDeployer.html)

-- 
Luke Daley
Principal Engineer, Gradleware 
http://gradleware.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to