S. O. Chaos
S. O. Chaos

Reputation: 146

Building dependencies tree in Gradle

I have two projects which are not linked in any way. I need them to have the same dependency and this dependency is another project, which can be edited anytime. So dependency tree must look like that (well, I'm not really good in drawing): enter image description here

How do I do that?

Upvotes: 1

Views: 139

Answers (2)

Jince Martin
Jince Martin

Reputation: 311

Here you have three projects. I think its better to keep these three projects in an archive, say EAR which is the root project. This will be easy to handle. So we can keep the root project name as Project. The structure will be: two independent projects, Project2 and Project3, with one common dependent Project1.

So we need to update the settings.gradle as:

rootProject.name = 'Project'
include 'Project2',':Project3'
include ':Project1'

And update the build.gradle of Project2 and Project3. Add the below code in both build.gradle file.

dependencies{
compile project(':Project1');
}

This will work.

Upvotes: 1

Alexiy
Alexiy

Reputation: 2030

Project 1 settings.gradle:

rootProject.name = 'Project1'
include 'Project2, Project3'

Project 2 and 3 build.gradle:

sourceSets.main{
    compileClasspath=rootProject.sourceSets.main.output
}

Upvotes: 0

Related Questions