我有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),了解多项目构建的外观。 –