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

I'm trying to build a Gradle file and getting the error Build file '.../build.gradle' is not part of the build defined by settings file '.../settings.gradle'. If this is an unrelated build, it must have it's own settings file.

Here is my build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-securing-web'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-web")
    // tag::security[]
    compile("org.springframework.boot:spring-boot-starter-security")
    // end::security[]
    testCompile("junit:junit")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.springframework.security:spring-security-test")
}

Here is my settings.gradle:

/*
 * This settings file was generated by the Gradle 'init' task.
 *
 * The settings file is used to specify which projects to include in your build.
 * In a single project build this file can be empty or even removed.
 *
 * Detailed information about configuring a multi-project build in Gradle can be found
 * in the user guide at https://docs.gradle.org/4.0/userguide/multi_project_builds.html
 */

/*
// To declare projects as part of a multi-project build use the 'include' method
include 'shared'
include 'api'
include 'services:webservice'
*/

rootProject.name = 'gs-securing-web'

How do I get this to build?



Solution 1:[1]

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.

Solution 2:[2]

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'.

Solution 3:[3]

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.

Solution 4:[4]

Most of the time this happens when you are using Deprecated Gradle features were used in your build.gradle, making it incompatible with the latest Gradle version your IDE refers.

Found the right fix for a similar issue after I lost almost half a day to figure out a fix for this issue in IntelliJ in Ubuntu OS.

Finally found myself the solution by chance:

Just by setting Gradle version pointed to locally installed version, and Gradle JVM chose the installed version of JDK in your local machine, this solved my problem enter image description here

Solution 5:[5]

Run your gradle / gradlew command on the project where you can see settings.gradle

example: gradlew dependencies

Solution 6:[6]

In my case I had to delete that file from the root path. The file wasn't inside my project and that was strange.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matthew_automater
Solution 2 Dharman
Solution 3 cjones26
Solution 4
Solution 5
Solution 6 Damian Lattenero