我有big-project/
中的gradle項目和big-project/lib/
中的子項目。Gradle構建,然後忽略子項目
在big-project/
的big.project.Main
class I import big.project.lib.Utils
,它在big-project/lib/
子項目中定義。
當我嘗試運行gradle build
,這是發生了什麼:
:lib:
compileJava UP-TO-DATE
:lib:processResources UP-TO-DATE
:lib:classes UP-TO-DATE
:lib:jar
:compileJava
big-project/src/main/java/big/project/Main.java:3: error: package big.project.lib not exist
import big.project.lib.Utils;
^
1 error
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 6.243 secs
出於某種原因,gradle這個編譯子項目的代碼,然後決定忽略它。 我該如何解決這個問題?
這些都是我的gradle這個文件:
big-project/settings.gradle
:
include 'lib'
big-project/build.gradle
:
evaluationDependsOnChildren()
allprojects {
apply plugin: 'java'
sourceCompatibility = '1.8'
version = '1.0'
group = 'big.project'
}
apply plugin: 'war'
dependencies {
compile project(':lib')
}
big-project/lib/build.gradle
是空
我的確學習了Gradle手冊: Chapter 56. Multi-project Builds,但沒有任何用處。
通常在多項目構建中,根項目不包含源代碼,僅用於協調構建。嘗試爲您的根源代碼添加另一個子項目。從技術上講,你的解決方案應該基於什麼「解耦項目」說明,但由於解耦最終將是強制性的,所以現在最好這樣做(這種轉換可能是你的問題的原因) –
我試圖將該代碼移動到「大項目/ product',但我仍然得到相同的錯誤。我重訪了部分[56.9。解耦項目](https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:decoupled_projects)和[56.7。項目庫依賴關係](https://docs.gradle.org/current/userguide/multi_project_builds.html#javadependencies_2),但這並沒有幫助;無論我把'compile project(':lib')'放到'big-project/product/build.grade'還是放在'big-project/build.gradle'中。 (PS:我確實將'product'項目添加到'big-project/settings。gradle') – derabbink
不幸的是,在沒有看到構建腳本的情況下,我所能做的就是指出一個示例[project](https://github.com/ben-manes/caffeine),瞭解多項目構建的外觀。 –