Reputation: 33307
I have two Gradle projects with the following directory structure:
/baseDir
/first
/first/build.gradle
/second
/second/build.gradle
/second/settings.gradle
settings.gradle looks like this:
includeFlat "first"
When I do gradle build
the second project is compiled after the first (main) project. I tried in the first project's build.gradle:
dependencies {
compile project(':first')
}
When doing gradle build
I get an error that dependencies declared in the first project could not be found in the second one.
What I need is the following. When I do gradle build
on the second project I want that the first project will be build first and that first.jar
is used as a dependency in the second project.
How can I do that?
Edit: When I set the following in my second project's settings.gradle:
includeFlat "first", "second"
then I get the following error while doing graddle clean
:
FAILURE: Build failed with an exception.
* What went wrong:
Could not select the default project for this build. Multiple projects in this build have project directory '/Users/mg/Documents/Grails/GGTS3.6.3-SR1/second': [:, :second]
> Multiple projects in this build have project directory '/Users/mg/Documents/Grails/GGTS3.6.3-SR1/second': [:, :second]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Edit: I create a sample project form demonstration: https://github.com/confile/Gradle-MultiProject-Test
Upvotes: 1
Views: 2894
Reputation: 418
dependencies {
implementation files( project(‘:first’).tasks.jar )
}
Upvotes: -1
Reputation: 2192
you can let the build task depend on the build task of another project:
build{
dependsOn ':first:build'
}
Try this project settup:
root
settings.gradle
gradle.build
first
gradle.build
second
gradle.build
and put this in settings.gradle of your root:
include 'first'
include 'second'
Upvotes: 2
Reputation: 29
You should move the block
dependencies {
compile project(':first')
}
to the second project's build.gradle. This will build the first project and before the second project and second project could use first project's classes.
Upvotes: 0