考虑以下多项目构建脚本:
的build.gradle
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
group = "myorg"
version = "1.0.0-SNAPSHOT"
}
project(':client') {
dependencies {
compile 'myorg:shared:1.0.0-SNAPSHOT'
}
}
使用以下文件:
├── build.gradle
├── client
│ └── src
│ └── main
│ └── java
│ └── myorg
│ └── client
│ └── MyOrgClient.java
├── settings.gradle
└── shared
└── src
└── main
└── java
└── myorg
└── shared
└── MyOrgObj.java
在上面的文件中,MyOrgClient.java包含myorg.shared.MyOrgObj
,而settings.gradle包含单行include 'client', 'shared'
问题
maven相关任务的项目/任务构建顺序(如本地安装和部署到远程存储库)不考虑隐含的项目依赖性。由于gradle不知道'myorg:shared:1.0.0-SNAPSHOT'
创建了project(':shared')
,因此构建顺序为:client -> :shared
并导致如下错误:
$ gradle install
:client:compileJava
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':client:compile'.
> Could not find myorg:shared:1.0.0-SNAPSHOT.
Required by:
myorg:client:1.0.0-SNAPSHOT
问题: 有没有一种标准的方法来处理这个问题?我尝试过这些解决方案但没有成功:
mustRunAfter
但遇到了尚未存在的任务问题。我也认为这不会很好地适应大量项目archives project(':shared')
添加到客户端的依赖项compile project(':shared')
添加到客户端的依赖项答案 0 :(得分:0)
您必须以与Maven中相同的方式定义项目之间的依赖关系:
例如:
project(':app') {
apply plugin: 'ear'
dependencies {
compile project (':webgui')
compile project (':service')
}
}
但您需要定义settings.gradle,其中包含以下模块:
include 'app'
include 'domain'
include 'service'
include 'service-client'
include 'webgui'