This question has already been answered:

There is the following structure

MainProject settings.gradle build.gradle Proj1 build.gradle Proj2 build.gradle 

In the MainProject/settings.gradle I prescribe projects

 include 'Proj1', 'Proj2' 

Proj2 requires classes from Proj1 , so in Proj2/build.gradle I am writing

 dependencies { compile project(':Proj1') //other dependencies } 

When I do gradle :Proj2:compileJava I have written that the package (from Proj1 ) was not found, so the compilation ended with an error.

What am I doing wrong?

Reported as a duplicate by members of aleksandr barakin , fori1ton , user207618, Kirill Stoianov , Streletz Sep. 28 '16 at 17:38 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    Found a solution.

    You must write the MainProject/build.gradle in MainProject/build.gradle

     project(':Proj2') { dependencies { compile project(':Proj1'); } } 

    and the Proj2 Proj2/build.gradle must be deleted.

    Accordingly, the question arose - why it does not work as I wrote in the question, but this is another question .

    • As we found out in a related question, this is not really a solution. - Roman