sebdehne
sebdehne

Reputation: 382

How to let gradle build dependent sub-project first when using non-compile dependencies

How can I tell gradle to build a certain sub-projects first, even though I don't have a compile dependency to them? How are project dependencies handled internally?

Example:

settings.gradle:

include "app", "schema"

build.gradle:

allprojects {
  apply plugin: 'java'
}

schema/build.gradle:

// empty

app/build.gradle:

configurations {
    schemas
}

dependencies {
    schemas project(":schema")
    schemas "org.example:example-schema:1.0"
}

task extractSchema(type: Copy) {
    from {
        configurations.schemas.collect { zipTree(it) }
    }
    into "build/schemas"
}

//compileJava.dependsOn extractSchema

And when running:

$ cd app
$ gradle extractSchema

I get:

Cannot expand ZIP 'schema/build/libs/schema.jar' as it does not exist.

What I want is that gradle automatically builds all sub-projectes defined in the configurations.schemas dependency list first (if they are projects).

Note: I want to be able to share the extractSchema task across multiple gradle projects, so it is important that gradle takes the list of sub-project to be built first from the configurations.schemas list.

Thanks

Upvotes: 2

Views: 4427

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123960

Gradle build order is never on the project level, but always on the task level. from(configuration.schemas) would infer task dependencies automatically, but in case of from(configuration.schemas.collect { ... }), this doesn't work because the resulting value is no longer Buildable. Adding dependsOn configurations.schemas should solve the problem.

Upvotes: 4

Related Questions