Maven任务的Gradle项目构建顺序

时间:2014-01-07 17:27:25

标签: maven gradle

考虑以下多项目构建脚本:

的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')添加到客户端的依赖项,然后将其从生成的pom中删除。不幸的是,这不会将依赖项添加到安装任务或artifactoryPublish 编辑:这实际上是解决方案。项目依赖项将在生成的pom.xml中提供正确的版本/名称/组,因此不需要显式组:name:version依赖项

1 个答案:

答案 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'