How do I use inputs.property on a Gradle task, but with a closure for a value?
gradle
Solution
I would remove `project.afterEvaluate` in the first closure. This is for adding a closure that gets executed after the project has been configured.
What is actually going on is when gradle resolves the inputs, it calls the first closure, which then calls `project.afterEvaluate`, which adds a closure to the list that will be called when the project is done configuring... which will never be called because it is now in the execution phase.
Problem
I'm trying to add an installer builder to my build configuration and I'm having a little trouble getting task inputs set up properly. I have the configuration split into a separate .gradle file and I add it to my project by doing the following. ``` project.ext.i4jArgs = [ "--verbose" ] apply from: rootProject.projectDir.absolutePath + "/gradle/install4j.gradle" ``` To build the installers I'm calling a command line tool via `exec`. Almost everything is based on convention, but I want to optionally add a couple arguments / switches to the command from my main build file. I do it using the `project.ext.i4jArgs` property (above). If I set the `project.ext.i4jArgs` property before applying my `install4j.gradle` file, I can use the following for inputs and everything seems to work. ``` inputs.property("i4jArgs", project.ext.has('i4jArgs') ? project.ext.i4jArgs : null) ``` However, if I apply my `install4j.gradle` file first and set the `project.ext.i4jArgs` property second, the `project.ext.i4jArgs` property is always `null` when I'm declaring inputs in my task (obviously). The API for `TaskInputs` (here) says I can pass a closure as a value. Is there a way I can use a closure to delay the evaluation of the `project.ext.i4jArgs` long enough to guarantee it's been initialized? I though the following would work, but the closure never gets called. ``` inputs.property("i4jArgs", { project.afterEvaluate { println "has args ${project.ext.has('i4jArgs')}" project.ext.has('i4jArgs') ? project.ext.i4jArgs : null } }) ``` I know writing a plugin that supports all the configuration I want might be a better option for the specific example I've given, but I'd like to figure out what I'm misunderstanding here anyway.