Gradle evaluates using empty build file

I am getting below error when trying to run grdle tasks command

Evaluating project ‘:Project1’ using empty build file.
Evaluating project ‘:Project2’ using empty build file.
I have multiproject build


and below is my settings.gradle

File modulesDir = new File("${rootProject.projectDir}/…/Root").canonicalFile
modulesDir.eachFile {
rootProject.children.each {
it.projectDir = new File(modulesDir,
it.buildFileName = ‘./sub-project.gradle’
this line is not working

it.buildFileName = './sub-project.gradle’
the sub-project.gradle is not getting assigned to sub project.

whats the problem? How can one assign actual build file to project?

buildFileName is evaluated relatively to its project directory, using its project’s method file.

So, your code

it.buildFileName = './sub-project.gradle'

should be

it.buildFileName = '../sub-project.gradle'

The complete sample is available at my repo.

or define at build.gradle

subprojects {
    apply from: 'sub-project.gradle'

I have made the changes as per your suggestion, but the problem is still there.

Did you see my sample? It seems any one doesn’t click the link.

The sample works well.

This works well! now I have another problem Project2 has dependency on Project1 so when I execute gradle build it fails. How to add this dependency?

Add project dependency declaration in your sub-project.gradle.

for example…

ext {
  // if this project is Project2 then this value becomes true. If Project1, it's false.
  dependence = != 'Project1'
dependencies {
  // some your dependencies

  // If this project is Project2 then depend on Project1
  if(dependence) {
    compile project.rootProject.project(':Project1')

The sample project, which I mentioned before, is currently adjust your requirement. And it works well.

1 Like

Thank you very much!