[英]Gradle: include directory as dependency
I have multiple Gradle Java projects in which I am attempting to add the source code of a local project, whose root directory is /library
, as a dependency that is a directory, just as I can add dependencies that are JARs.我有多个 Gradle Java 项目,我试图在其中添加一个本地项目的源代码,其根目录是
/library
,作为一个目录的依赖项,就像我可以添加依赖项是 Z5C1F83365C85B539E8B75C85B039E8B77 一样。 I tried using compile files('/library/src/main/java')
: the packages were imported recursively, but the *.java files were left alone.我尝试使用
compile files('/library/src/main/java')
:包是递归导入的,但 *.java 文件被单独留下。 Can I add /library/src/main/java
as a dependency to the project?我可以添加
/library/src/main/java
作为项目的依赖项吗? My goal is not having to recompile whenever I make changes to the library.我的目标是在对库进行更改时不必重新编译。
Gradle allows this throughcomposite builds . Gradle 允许通过复合构建实现这一点。 To include the build
/library
, add includeBuild("/library")
to the settings.gradle
file of the dependent build.要包含构建
/library
,请将includeBuild("/library")
添加到依赖构建的settings.gradle
文件中。 Then declare it as a dependency in build.gradle
with correct group and name;然后在
build.gradle
中使用正确的组和名称将其声明为依赖项; an explicit version is not unnecessary.明确的版本不是必需的。 As it is now, Gradle will be unable to resolve this dependency, so finally substitute this dependency with the included build by changing
includeBuild("/library")
to就像现在一样,Gradle 将无法解决此依赖关系,因此最后通过将
includeBuild("/library")
更改为
includeBuild("/library") {
dependencySubstitution {
substitute(module: "<group>:<name>").with(project(":"))
}
}
, which will cause the dependency declared earlier to be replaced by /library
. ,这将导致之前声明的依赖被
/library
替换。
After reloading the Gradle project with your IDE, the classes from /library
should be available and any changes made to /library
should be immediately visible to the dependent build.使用 IDE 重新加载 Gradle 项目后,
/library
中的类应该可用,并且对/library
所做的任何更改都应该立即对依赖构建可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.