joshualan
joshualan

Reputation: 2140

How do I make one subproject depend on another subproject in gradle via configurations?

I have a multi-project build that looks like this:

helloworld
- projecta
  - build.gradle
- projectb
  - build.gradle
- build.gradle

projecta creates some files and projectb zips them up. I want projectb to depend on projecta.

Right now, I simply have a dependsOn ':projecta:build in my projectb's build.gradle. But this feels like a hack.

I want to use configurations instead to make it look like this:

// projectb build.gradle
dependencies {
  compile project(':projecta')
}

But I cannot find any documentation on how to define a compile task. How would I go do this?

Upvotes: 0

Views: 358

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14500

The philosophy in Gradle is to model exactly what you are aiming for:

  • Are the files produced by projecta a real output of the project itself, like a JAR in the Java world?

    If yes, then work with a configuration indeed that will give you access to these files, assuming they are properly registered as a production of projecta

  • Are the files a by product of building projecta but not made for general consumption?

    If that's the case, then the most explicit dependency is across tasks where the zipping task in projectb simply depends on the task from projecta that produces these files. build here feels like a hack in the sense that it most likely cause much more work in projecta compared to what projectb really needs.

Upvotes: 1

Related Questions