On Nov 26, 2009, at 2:59 PM, Adam Murdoch wrote:
>
>
> Ross Black wrote:
>> Hi,
>>
>> Is there a way to conditionally add an artifact to a configuration, where
>> the condition is evaluated at runtime?
>> eg. I only want to add an artifact if a specific directory exists.
>>
>> I was hoping the following would work (but it does not):
>> ---
>> project.configurations {
>> api
>> }
>>
>> Task apiTask = project.task('apiJar', type: Jar, dependsOn:
>> 'classes') {
>> fileSet(dir: project.apiClassesDir)
>> }
>> apiTask.onlyIf {project.apiClassesDir.exists()}
>>
>> project.artifacts {
>> api apiTask
>> }
>> ---
>>
>> The apiJar task correctly only generates the jar if the directory exists,
>> but the artifact handler always expects that the file specified by the
>> apiJar task exists even if the task has not run.
>>
>> Is there some other way to achieve this?
>>
>
> Not really. Could you add a JIRA issue for this?
>
> I can't think of a good work-around, either. Is it possible to figure out at
> configuration time whether the api jar is needed?
There is a work around, not a good one though.
// This action only executes if apiTask is not skipped
apiTask << {
project.artifacts {
api apiTask
}
}
uploadApi {
// As we add the apiTask to the api configuration at execution time,
Gradle can't autowire this at configuration time. So we have to create the
dependsOn manually
dependsOn apiJar
repositories.flatDir(dirs: "$buildDir/repo")
}
- Hans
--
Hans Dockter
Gradle Project Manager
http://www.gradle.org
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email