How to can I conditionally build certain artifacts?

(Emil Sit) #1

I have a set of artifacts that are somewhat expensive to build that developers do not need to build regularly during an edit-compile-test cycle. I’m trying to do this with a ‘configuration { occasionally }’ plus ‘artifact { occasionally myTask }’ in my projects to declare the tasks that produce these artifacts. (‘myTask’ is typically a Copy or some sort of bundling task to build up some packages for export.)

However, once I use ‘artifact’, the assemble task starts to pick up this configuration which causes ‘gradle build’ to always build these artifacts, even though I’d rather it only happen when the user explicitly runs something like ‘buildOccasionally’.

I can’t quite figure out what codepath is being executed that causes this to happen (the base plugin seems to suggest that assemble should only depend on the archives configuration; DefaultArtifactHandler doesn’t seem to do anything that would cause this either).

Is there a better approach?

(I am using Gradle 1.0. I do see that the Gradle build declares an ‘ext.outputs’ but that seems to be forgoing bits of existing infra?)

(Emil Sit) #2

Self bump.

(Luke Daley) #3

I can’t see why this would be happening.

Please post a full example build script that I can use to reproduce it.

(Emil Sit) #4

Here you go…

apply plugin: ‘java-base’

configurations {



task optional(type: Copy, dependsOn: configurations.optional.buildDependencies) {

into “${buildDir}/optional”

from configurations.optional.allArtifacts.files


task sampleFile(type: Tar) {

archiveName = “sample.tar.gz”

compression = Compression.GZIP

into(“sample”) {

from “/etc”

include “services”



// The addition of this stanza causes sampleFile to be built when “gradle build”

artifacts {

optional sampleFile


You can see that without the artifacts stanza, “gradle build” does nothing. With the stanza, it executes the sampleFile task. (In either case, “gradle optional” works to copy sample.tar.gz from build/distributions into the build/optional directory.)


(Emil Sit) #5

Any luck? Can you propose any work-around? Would you like me to file a ticket to track this?


(Luke Daley) #6

I can see what’s going on now. I think it’s a bug in ‘DefaultArtifactPublicationSet’, just need to confer with another developer about it. If it’s a bug I’ll open an issue.

A workaround is:

task assemble(overwrite: true) {
    dependsOn { configurations.archives.allArtifacts - configurations.optional.allArtifacts }

(Luke Daley) #7

Raised as GRADLE-2411.

(Emil Sit) #8

Thanks, work-around applied, developers happy.