conditional artifact publication

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

conditional artifact publication

Ross Black-2
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?


Thanks,
Ross

Reply | Threaded
Open this post in threaded view
|

Re: conditional artifact publication

Adam Murdoch-2


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?


--
Adam Murdoch
Gradle Developer
http://www.gradle.org


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: conditional artifact publication

hans_d
Administrator

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


Reply | Threaded
Open this post in threaded view
|

Re: conditional artifact publication

Ross Black-2
Thanks for the responses.

I opened http://jira.codehaus.org/browse/GRADLE-756.
It seems related to GRADLE-755.

My current hack-around is to always generate the artifact (by adding some dummy files) which keeps the dependency and artifact declarations simpler.

Ross