On 14/02/2012, at 10:02 PM, Joern Huxhorn wrote:
> On 14.02.2012, at 19:06, Luke Daley wrote:
>
>>
>> On 14/02/2012, at 2:24 PM, Joern Huxhorn wrote:
>>
>>> The Release Notes at
>>> http://wiki.gradle.org/display/GRADLE/Gradle+1.0-milestone-8+Release+Notes
>>> contain the following example:
>>>
>>> signing {
>>> required = { gradle.taskGraph.hasTask("uploadArchives") &&
>>> !version.endsWith("SNAPSHOT") }
>>> }
>>
>> I just fixed that up to make it a little clearer, thanks. The hasTask()
>> method requires an absolute path as you found out.
>>
>>> This caused me quite a bit of confusion since in a multi-module project,
>>> the task contained in taskGraph is something like ':foo:uploadArchives' so
>>> the code above wouldn't work. (On a side note, I use the task
>>> uploadPublished instead of uploadArchives.)
>>>
>>> The only way I could find to achieve something like the functionality
>>> intended above was
>>> signing {
>>> required = { gradle.taskGraph.allTasks.any { it instanceof Upload } &&
>>> !version.endsWith("SNAPSHOT") }
>>> }
>>>
>>> Or am I missing something and there is a more elegant way?
>>
>> That will not allow you to `gradle install` (the install task is an Upload
>> task) without signing which may not be what you want. Signing configuration
>> is per project, and hasTask() accepts task objects. So you could do…
>>
>> signing {
>> required = { gradle.taskGraph.hasTask(uploadPublished) &&
>> !version.endsWith("SNAPSHOT") }
>> }
>
> I implemented it differently in the meantime
> signing {
> required = !version.endsWith('SNAPSHOT')
> sign configurations.archives
> }
>
> and then, in the part of my build that is asking for the PW if necessary:
>
> gradle.taskGraph.whenReady { taskGraph ->
> if(taskGraph.allTasks.any { it instanceof Sign } &&
> !version.endsWith("SNAPSHOT")) {
> String pgpPassword = System.properties.'pgpPassword'
> if(!pgpPassword) {
> Console console = System.console()
> pgpPassword = new String(console.readPassword("\nPGP
> Private Key Password: "))
> }
> allprojects*.setProperty('signing.password', pgpPassword)
> }
> }
>
> That way I'll only get asked if a Sign task is actually contained in the
> taskGraph. Neat.
I'd consider doing it slightly differently…
gradle.taskGraph.whenReady { taskGraph ->
if(taskGraph.allTasks.any { it instanceof Sign && it.required }) {
…
}
}
All Sign tasks have a “required” property that is wired to
`project.signing.required` by default, so above is functionally equivalent.
It's also slightly more correct as you could potentially override the
`required` value for a particular task.
>>
>> Actually… I think I'll update the cable to that.
>
> Thank you very much for your fast answer. Did I mention that I really love
> your support?
No problems at all. Thanks for the initial code that went in to this plugin.
--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email