Hi Matthias,

On Dec 19, 2008, at 8:41 PM, Pfau, Matthias wrote:

Hi together,
I have been playing around with gradle for some time and now it is time for the first real project.

The user guide has a nice example on how to set the version-number in relation to the DAG (chapter 2.11) and this is what I want to do:

version = null
task('init').doLast {
   if (build.taskGraph.hasTask(':release')) {
       version = '1.0'
   } else {
       version = 'SNAPSHOT'
   }
   logger.warn '  Version set to: {}', version
}

My question is: How can I use the version property in libs and dists tasks? E.g. I want to use the version property as part of the path prefix to added files of the archive:
dists {
   zipRoot = "${name}-${version}"
   zip() {
       zipFileSet(dir: buildDir) {
           include('*.jar')
           prefix: "${zipRoot}"
       }
   }
}

The problem is: The second code snippet will be executed during configuration phase whereas the task 'init' will get executed later, during execution phase. Unfortunately, the logic contained in 'init' (setting the version number) can't be executed before because it depends on the population of the DAG which can't be populated before the configuration phase is finished.

Sounds like the dilemma of chicken or egg.

I know this situation, as we use a similar approach in the Gradle build of Gradle. What we do there right now, is to postpone the version configuration of the archives to execution time.

dists {
        zip().doFirst {
                zipFileSet(dir: buildDir) {
                        include('*.jar')
                        prefix: "${zipRoot}"
                }
        }
}

This has at least one potential disadvantage. If at configuration some other task is interested in the zipFileSets of the zip, it wouldn't get the right information. We don't have this use case in our build but it could exists. It can also be a little bit confusing for uninitiated to understand what is going on and why it is done like this. So hopefully we can come up with a more intuitive solution in the future.


For me, the only way around this seems to redefine the dists task:
createTask('dists', overwrite: true) {
   [...]
}

Unfortunately, I was not able to get this done because I couldn't figure out how to use and configure the Bundle "animal".

I guess I'm missing some background information about the "animal" bundle.



Is there an easier solution

see above

and if not, how can you redefine tasks like libs and dists?

You have chosen the right approach for redefining. How would redefining solve this problem?

- Hans



Thanks for your help and keep up the good work!

Kind Regards,
Matthias
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

   http://xircles.codehaus.org/manage_email


Reply via email to