build.gradle 不是设置文件定义的构建的一部分

jim*_*web 11 gradle

我正在尝试构建 Gradle 文件并收到错误 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.

这是我的 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")
}
Run Code Online (Sandbox Code Playgroud)

这是我的 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'
Run Code Online (Sandbox Code Playgroud)

我如何得到这个建立?

小智 21

我遇到了完全相同的问题:

org.gradle.api.InvalidUserDataException:项目目录“Users/Shared/myProject/theDirectory/src/test不是由设置文件“Users/Shared/myProject/theDirectory/ settings.gradle ”定义的构建的一部分。

问题是我从终端窗口运行 gradle,该窗口位于目录结构的下方。

FIX: 只需在终端窗口中更改目录cd ..

所以对我来说,我只是简单地备份到目录级别:“myProject”文件夹和繁荣......简单的gradle作品。

  • 这个答案似乎是在正确的路径上,但我如何告诉 Android Studio 应该从哪里运行命令?因为如果我从 /android/ 子文件夹打开项目,它会很好地检测 gradle,但随后它无法访问 /.env 文件...而且我也无法处理位于根文件夹中的跨平台代码因为该项目仅在 /android/ 范围内打开 (2认同)
  • 这应该是公认的答案 (2认同)

小智 9

我有同样的问题。我看到没有答案,虽然我迟到了,但这可能对其他人有帮助。

从可用位置复制 settings.gradle 文件并将其粘贴到所需位置。

在我的情况下,错误是 -

* 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.
Run Code Online (Sandbox Code Playgroud)

我复制settings.gradle的文件/Users/pradeepbehera/settings.gradle和粘贴/Users/pradeepbehera/Downloads/ud867-master/1.04-Demo-GroovyClosuresAndObjects。

然后它工作得很好。