我有一個帶有 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.
什么地方出了錯?為什么gradle無法識別有效路徑“./graph-commons/core”?
專案在github上上傳并測驗:
https://github.com/tribbloid/shapesafe/runs/4280805005?check_suite_focus=true
uj5u.com熱心網友回復:
Gradle 不會以這種方式作業。專案路徑是指 gradle 專案路徑,而不是檔案路徑。請參閱https://docs.gradle.org/current/userguide/multi_project_builds.html#multi_project_builds
編輯:如評論中所述project(File), 中可用的方法settings.gradle.kts是一種特殊方法,允許接收ProjectDescriptor其目錄指向給定檔案的 。該專案必須已經存在,例如通過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") }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/367235.html
標籤:等级 gradle-kotlin-dsl gradle 子模块
上一篇:當我運行“npxreact-nativerun-ad”時,FreshReactNativeApp不會安裝在模擬器上
