为什么 gradle 7.3 无法找到使用相对路径定义的子模块?

Why gradle 7.3 is incapable of finding a submodule defined using relative path?

我有一个包含 1 个子模块的 gradle 项目,定义在以下文件结构中(+- 指目录):

+- <root>
  build.gradle.kts
  +- graph-commons
    +- core
      build.gradle.kts

唯一的子模块是使用以下 kotlin 脚本包含的:

val graphCommons = project(File("./graph-commons/core"))

includeBuild(graphCommons)

当我执行 ./gradlew clean assembly 时,出现以下错误:

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/peng/git/shapesafe/settings.gradle.kts' line: 2

* What went wrong:
Project with path './graph-commons/core' could not be found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 492ms

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/peng/git/shapesafe/settings.gradle.kts' line: 2

* What went wrong:
Project with path './graph-commons/core' could not be found.

出了什么问题?为什么有效路径“./graph-commons/core”不能被gradle识别?

项目已上传并测试 github:

https://github.com/tribbloid/shapesafe/runs/4280805005?check_suite_focus=true

Gradle 这样不行。项目路径是指 gradle 项目路径,而不是文件路径。参见 https://docs.gradle.org/current/userguide/multi_project_builds.html#multi_project_builds

编辑:如评论中所述,project(File) method that is available in the settings.gradle.kts is a special method allowing to receive a ProjectDescriptor whose directory points to the given file. The project must be present already e.g. by including it via include(String...) 首先。

我首先想到你试图以某种方式使用 DependencyHandler#project(Map) 方法,这是引用项目依赖项的常用方法。 Gradle 分隔依赖项和多项目设置。在 settings.gradle.kts 中,您通常在每个 build.gradle.kts 中声明依赖项时设置项目结构。使用 includeBuild 时,您仅依赖于另一个完全独立的项目的构建。然后,当您想要从包含的构建中声明对项目的依赖性时,您通常使用项目的工件坐标来执行此操作。这样,在删除 includeBuild 声明时构建仍然有效。

如果您想使用复合构建,请参阅此处了解基本用法:https://docs.gradle.org/current/samples/sample_composite_builds_basics.html 您将必须协调工件发布和相应的依赖关系,以使其像普通的多项目一样工作。像这样:

graph-commons
|build.gradle.kts -> group = "org.scala-lang"; version = "1.0";
|settings.gradle.kts -> include(":graph-commons-core")
|graph-commons-core
||build.gradle.kts

shapesafe
|settings.gradle.kts -> includeBuild("../graph-commons")
|core
||build.gradle.kts -> dependencies { implementation("org.scala-lang:graph-commons-core:1.0") }