More Than Five
More Than Five

Reputation: 10419

Why won't gradle jar build a jar that gradle build does?

In my Gradle project, I define an additional sourceSet.

sourceSets {
    sample {
        java {
            srcDir 'sample/java'
        }
        compileClasspath += sourceSets.main.output + sourceSets.main.compileClasspath
    }
}

I then add a task:

task sampleJar(type: Jar) {
    classifier 'sample'
    from sourceSets.sample.output
}

artifacts {
    archives sampleJar
}

If I do > gradle build the additional jar file builds from the additional source set. However, if I do > gradle jar, it doesn't. any reason why?

When I go through the output messages, I see:

gradle build has sampleJar in the Tasks to be executed:

but

gradle jar doesn't.

But unsure as to why?

Upvotes: 0

Views: 65

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

Because jar is just the task that assembles the main jar file.

build, on the other hand, is the top-level life-cycle task, which depends on assemble. And assemble is documented as

Depends on: jar, and all other tasks that create artifacts attached to the archives configuration.

Since your sampleJar pecisely creates an artifact attached to the archives configuration, assemble, and thus build depends on it.

Upvotes: 1

Related Questions