Properties defined by a task as manifest attributes

Hi. I would like to have a task that defines some properties, that are then used as attribute values in the jar.manifest.attributes. I am failing, here is what I have:

task dynprop << {

someprop = ‘some dynamic value’ }

jar {

dependsOn dynprop

manifest {


someprop: dynprop.someprop


} }

It fails saying that: > Could not find property ‘someprop’ on task ‘:scm’.

Which is true, because at the time the attributes are configured, the dynprop task hasn’t run yet. If I change it to this:

task dynprop {

someprop = ‘some dynamic value’ }

it works, but is not really what I would like - it will run every time the build script is executed, not only when needed.

How to achieve what I would like?

Why do you want to set the property at execution time? What’s the use case?

The use case is that is is time consuming to set this property (actually, a few of them), and it doesn’t have to be done for clean, compileJava or others, only for anything from jar onwards. That includes starting processes, like ‘hg id --id’, but also others, to define properties that I eventually would like to store in the manifest.


You have to defer configuration of properties whose values are only available at execution time. For example, you could configure the manifest in ‘jar.doFirst {}’, or wrap attribute values as follows:

attributes(someprop: new Object() { String toString() { dynprop.someprop } })