Why does Second project which depends on project first needs all the dependencies of first?

Why does Second project which depends on project first needs all the dependencies of first. Here is a demo to prove it: https://github.com/confile/Gradle-MultiProject-Test

Because of the transitive nature of dependencies. If A depends on B and B depends on C, then A will have a transitive dependency to C.

How do I solve the problem?

If you indeed don’t want to bring along transitive dependencies you can disable that behavior.

dependencies {

compile(project(’:first’)) {

transitive = false

}

}

I tried your solution, but in this case eclipse could not resolve dependencies from first in second.

When I use classes from first in second they are not found.

I’m afraid I’m not able to reproduce your problem. Can you perhaps post your exact error, or a screenshot of what you are seeing in Eclipse?

Eclipse cannot find the class from project first in project second.

When I Use a class from first in second and try to do Ctrl + O in Eclipse it does not show the import of the class.

You may want to try running ‘gradle eclipse’ again and reimport the projects. I was able to get everything to compile fine.

Do I have to reimport the project everytime I change something in project first?

No does not work. When I do gradle build on second I get:

:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.7 /Users/mg/Documents/Grails/GGTS3.6.3-SR1/Second/src/main/java/test2/Some.java:4: error: package org.test does not exist import org.test.Person;

^ /Users/mg/Documents/Grails/GGTS3.6.3-SR1/Second/src/main/java/test2/Some.java:9: error: cannot find symbol

Person person;

^

symbol:

class Person

location: class Some 2 errors 1 warning

Can you post your build file, or perhaps update the github repo you linked with your latest changes?

The git repo has the latest version.

I am able to get that project to build by making the transitive dependency change I mentioned above and adding an import for ‘org.test.Person’ to the source file in project ‘Second’.

Is Gradle building project ‘First’ when you run ‘gradle build’? Is project ‘First’ listed as a dependency if you run ‘gradle dependencies’?

I did the following in the build.gradle in second project:

dependencies {

compile(project(’:buddyis-core’)) {

transitive = false

} }

First project can be build without problems. gradle dependencies on the second project gave the following result:

[sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks:

[sts]

dependencies [sts] ----------------------------------------------------- :dependencies

------------------------------------------------------------ Root project ------------------------------------------------------------

archives - Configuration for archive artifacts. No dependencies

compile - Compile classpath for source set ‘main’. No dependencies

default - Configuration for default artifacts. No dependencies

runtime - Runtime classpath for source set ‘main’. No dependencies

testCompile - Compile classpath for source set ‘test’. No dependencies

testRuntime - Runtime classpath for source set ‘test’. No dependencies

BUILD SUCCESSFUL

Total time: 0.162 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 0 min, 0 sec [sts] -----------------------------------------------------

I did this

dependencies {

compile(project(’:First’)) {

transitive = false

} }

in the build.gradle of the second project. Yes First can be build without errors.Here are the dependencies of Second:

[sts] ----------------------------------------------------- [sts] Starting Gradle build for the following tasks:

[sts]

dependencies [sts] ----------------------------------------------------- :dependencies

------------------------------------------------------------ Root project ------------------------------------------------------------

archives - Configuration for archive artifacts. No dependencies

compile - Compile classpath for source set ‘main’. — project :First

default - Configuration for default artifacts. — project :First

runtime - Runtime classpath for source set ‘main’. — project :First

testCompile - Compile classpath for source set ‘test’. — project :First

testRuntime - Runtime classpath for source set ‘test’. — project :First

BUILD SUCCESSFUL

Total time: 0.188 secs [sts] ----------------------------------------------------- [sts] Build finished succesfully! [sts] Time taken: 0 min, 0 sec [sts] -----------------------------------------------------

What version of Gradle are you using?

I think now I got it working. You where right it is just transitive = false to solve it. Thank you very much. If you post an answer here: http://stackoverflow.com/questions/28384700/how-can-i-make-sure-that-an-included-subproject-runs-before-the-main-project-in

Then I can accept your answer.

Gradle 2.2.1