英文:
How is the classpath setup in a multimodule gradle project during runtime?
问题
我对于Gradle和尤其是多模块Gradle项目还不太熟悉,所以我有一个小的示例项目,其项目结构如下:
主项目
*src
*tests
*build.gradle
*settings.gradle
*子项目1
+src
+tests
+build.gradle
因此,当我尝试从主(根)项目中的一个类加载子项目1中的类时,它无法找到这个类。我本以为根项目的类路径也包含子项目的类。
我在这里做错了什么,或者是否有任何资料可以让我理解这个问题?
当前的settings.gradle文件如下,
rootProject.name = 'main'
include 'Subproject1'
英文:
I'm quite new to gradle and especially multimodule gradle projects, so I have a small example project created with the following project structure
Main
*src
*tests
*build.gradle
*settings.gradle
*Subproject1
+src
+tests
+build.gradle
So when I tried to load the classes in Subproject1 from a class in the main (root) project, it can not find the class, I would have thought the root project classpath contains the subprojects classes as well.
What am I doing wrong here or any material I should go through to understand this?
current settings.gradle file,
rootProject.name = 'main'
include 'Subproject1'
答案1
得分: 2
你应该花些时间阅读此处的文档,该文档解释了多项目构建的概念,并提供了一些示例,介绍了如何在子项目之间创建依赖关系。
根项目不会从子项目继承类路径,你需要显式地声明这些依赖关系,如下所示:
build.gradle(根项目)
dependencies {
implementation project(':Subproject1')
}
英文:
You should take some time to read documentation HERE which explains the concept of multiproject builds and provides some examples on how to create dependencies between sub-projects.
The root project will not inherit classpath from the subprojects, you will have to declare explicitelly these dependencies as follows
build.gradle (root project)
dependencies {
implementation project(':Subproject1')
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论