build.gradle is not part of the build defined by settings file

I was running into the exact same issue:

org.gradle.api.InvalidUserDataException: Project directory 'Users/Shared/myProject/theDirectory/src/test is not part of the build defined by settings file 'Users/Shared/myProject/theDirectory/settings.gradle.

The issue was I was running gradle from a terminal window that was based too far down in the directory structure.

The FIX: simply Change Directories in the terminal window cd ..

So for me I simply backed up to directory levels to: "myProject" folder and boom...simple gradle works.


I also encountered the same problem recently which actually brought me to this question.

In my case, I was trying to build the jar from the wrong path '../project/someFolder' and I corrected my path to '../project'.


In my case my project did not have a settings.gradle file, so I went ahead & created an empty one as per this documentation:

Always add a settings.gradle to the root directory of your build to avoid the initial performance impact. This recommendation applies to single project builds as well as multi-project builds. The file can either be empty or define the desired name of the project.


I had same issue. I see there is no answer, though I'm late, this might be helpful for others.

Copy the settings.gradle file from the available location and paste it and needed location.

In my case Error was -

* What went wrong:
Project directory '/Users/pradeepbehera/Downloads/ud867-master/1.04-Demo-GroovyClosuresAndObjects' is not part of the build defined by settings file '/Users/pradeepbehera/settings.gradle'. If this is an unrelated build, it must have its own settings file.

I copied settings.gradle file from /Users/pradeepbehera/settings.gradle and pasted at /Users/pradeepbehera/Downloads/ud867-master/1.04-Demo-GroovyClosuresAndObjects.

Then it worked just fine.

Tags:

Gradle