Root project override the subproject dependencies and local repo dependency


(Alan Lee) #1

I have 2 questions.

  1. Root Project override the subproject dependencies

In the subProject “sub” build.gradle, there is a dependency ’

dependencies {

compile group: “com.abc”, name: “test”,version: “2.1.+” } ’

In the rootProject build.gradle, i want to set the subproject with this dependency

project(“sub”){

dependencies{

compile group: “com.abc”, name:“test”,version:“2.2.0-SNAPSHOT”

} }

Since I want to have different dependencies when running at different directory. If running from root project, i want to use the snapshot one. If running from the subproject directory, i want to use the latest release version.

Apart from the version, sometimes I may need to completely override the subproject one or edit the dependencies in the subproject from the rootProject perspective?

Is there any ways to do so?

In fact, which dependencies will load first?

If they are no overlap packages, they will combine each others?

If there are repeated packages, what will be the final result?

  1. Another question about the local repo

Since I have several subprojects locally, so i want to directly use them instead of publishing the project and downloading the packages from the maven sever/local repo. Is there any ways to perform my action without any publish?

I have tried to change it from

'dependencies {

compile group: “com.abc”, name:“root”,version:“2.2.0-SNAPSHOT” }’

to

'dependencies {

compile project(“root”) }’

But there is no publish in that project and no jar…fail to compile…

How to solve it?


(Peter Niederwieser) #2

ad 1. If ‘group’ and ‘name’ are the same, conflict resolution will select a version. It doesn’t matter which build script and order the dependencies are declared in, as long as they are declared for the same project and configuration.

If you really want to use a different version depending on where the build is started from, you’ll need to check ‘gradle.startParameter.currentDir’, and configure the dependency accordingly.

ad 2. See the “multi-project builds” chapter in the Gradle User Guide.


(Alan Lee) #3

Thanks for your reply.

I have read about the guide. Just want to confirm for the question 2.

when dependencies mentioning compile of another project, it will compile and build that project first, and then it will apply that to the current project, right? So no need to publish that project in order to make inner dependency work, right?


(Peter Niederwieser) #4

Right.


(Alan Lee) #5

Thanks.

Since my source is not java, I can use the “publish” task to build my project with custom artifact which packages as a zip file.

And then I have a custom configuration which will extract the zip file from the resolved dependencies.

Now I want to have a inner module dependency and make it like the java to compile the project and then apply. But I am unable to combine those two procedures.

Thanks a lot