Maven任务的Gradle项目构建顺序 [英] Gradle Project Build Order For Maven Tasks

查看:152
本文介绍了Maven任务的Gradle项目构建顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

build.gradle

 子项目{
apply plugin:'java'
apply plugin:'maven'
group =myorg
version =1.0 .0-SNAPSHOT


项目(':client'){
依赖关系{
编译'myorg:shared:1.0.0-SNAPSHOT'


$ / code>

使用以下文件:

 ├──build.gradle 
├──客户
│└──src
│└──main
│└──java
│└──myorg
│└──客户端
│└──MyOrgClient.java
├──settings.gradle
└──共享
└──src
└──main
└──java
└──myorg
└──共享
└──MyOrgObj.java

在上述文件中,MyOrgClient.java包含 myorg .shared.MyOrgObj 和settings.gradle有单行 include'client','shared'



问题

Maven相关任务(如本地安装和部署到远程存储库)的项目/任务构建顺序不考虑说明隐含的项目依赖性。由于gradle不知道'myorg:shared:1.0.0-SNAPSHOT'是由 project(':shared'),构建顺序为:client - > :共享并导致类似下面的错误:

  $ gradle install 
:client :compileJava

失败:生成失败并出现异常。

*出错:
无法解析配置':client:compile'的所有依赖关系。
>无法找到myorg:shared:1.0.0-SNAPSHOT。
要求:
myorg:客户端:1.0.0 -snapshot.ht

问题:
是否有解决此问题的标准方法?我试过这些解决方案没有成功:


  • 使用 mustRunAfter 但遇到问题还没有任务。我也不认为这可以很好地满足大量项目的要求。

  • archives project(':shared')添加到客户端的依赖关系

  • 在客户端的依赖关系中添加 compile project(':shared')然后将其从生成的POM。不幸的是,这不会将依赖项添加到安装任务或artifactoryPublish 编辑:这实际上是解决方案。项目依赖项将在生成的pom.xml中提供正确的版本/名称/组,因此不需要显式的group:name:version dependency




>例如:

 项目(':app'){
apply plugin:'ear'
dependencies {
compile project(':webgui')
编译项目(':service')
}
}

但您需要定义包含如下模块的settings.gradle:

  include'app'
include'domain'
include'service'
include'service-client'
include'webgui'


Consider the following multi-project build script:

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'
  }
}

With the following files:

├── build.gradle
├── client
│   └── src
│       └── main
│           └── java
│               └── myorg
│                   └── client
│                       └── MyOrgClient.java
├── settings.gradle
└── shared
    └── src
        └── main
            └── java
                └── myorg
                    └── shared
                        └── MyOrgObj.java

In the above files MyOrgClient.java includes myorg.shared.MyOrgObj and settings.gradle has the single line include 'client', 'shared'

Problem

The project/task build order for maven related tasks like installing locally and deploying to remote repositories does not take into account the implied project dependency. Because gradle does not know that 'myorg:shared:1.0.0-SNAPSHOT' is created by project(':shared'), the build order is :client -> :shared and causes errors like the one below:

$ 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

Question: Is there a standard way to deal with this problem? I have tried these solutions without success:

  • Using mustRunAfter but ran into problems with tasks not existing yet. I also don't think this would scale well with a large number of projects
  • Adding archives project(':shared') to the client's dependencies
  • Adding compile project(':shared') to the client's dependencies and then removing it from the generated pom. Unfortunately this doesn't add the dependency to the install task or artifactoryPublish Edit: This actually was the solution. A project dependency will provide the correct version/name/group in the generated pom.xml so the explicit group:name:version dependency is not needed

解决方案

You have to define the dependencies between the projects more or less the same way as in Maven:

For example like this:

project(':app') {
  apply plugin: 'ear'
  dependencies {
    compile project (':webgui')
    compile project (':service')
  }
}

But you need to define the settings.gradle which contains the modules like this:

include 'app'
include 'domain'
include 'service'
include 'service-client'
include 'webgui'

这篇关于Maven任务的Gradle项目构建顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆