Gradle Maven之类的多模块项目 [英] Gradle Maven like multi module project

查看:270
本文介绍了Gradle Maven之类的多模块项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Maven中定义多模块项目时,您将有一个根项目及其模块.当您构建根项目时,Maven将以正确的顺序过渡性地构建其所有模块.到目前为止,与Gradle非常相似.

When you define multi module project in Maven, you have one root project and its modules. When you build the root project, Maven transitivelly builds all its modules in correct order. So far pretty similar to Gradle.

但是使用Maven,您可以从存储库中仅克隆一个子模块并在本地构建它,而无需下载整个项目结构.这是因为您定义了对同一项目中其他模块的依赖,就像定义了其他任何外部依赖一样,它是从本地存储库(Nexus)下载和缓存的.

But with Maven, you can clone only one submodule from repository and build it locally without need to download the whole project structure. This is because you define dependencies on other modules within the same project just as any other external dependency and it is downloaded and cached from your local repository (Nexus).

使用Gradle,您将跨模块依赖项定义为compile project(':other').因此,您需要从存储库克隆整个项目结构,以便正确解析和构建.有什么方法可以使用Gradle多模块项目支持,而不必在本地克隆整个项目结构?

With Gradle, you define cross module dependencies as compile project(':other'). So you need to clone whole project structure from repository in order to resolve and build correctly. Is there any way to use Gradle multi module project support, without having to locally clone whole project structure?

推荐答案

我认为Maven的多模块支持是一种事后思考.与Gradle不同,项目依赖不是一流的概念.相反,当GAV(组/工件/版本)匹配时,行家反应器"将本地工件替换为依赖项.

I would argue that Maven's multi-module support is a slapped on after-thought. Unlike Gradle, a project dependency is not a first class concept. Instead the maven "reactor" substitutes local artifacts for dependencies when the GAV (group/artifact/version) matches.

如果您想在Gradle中使用相同的方法,则可以使用GAV表示法指定依赖项,然后使用新的

If you'd like to use the same approach in Gradle then you can specify your dependencies using the GAV notation and then use the new composite build feature to join two or more separate gradle builds together and substitute repository dependencies for local source dependencies. Note that that you can define the projects included in the composite using groovy so you could easily script this based on custom logic (eg if a subfolder exists in some root folder etc)

请注意,复合构建支持是Gradle 3.1中添加的新功能.在Gradle 3.1之前,您可以使用 Prezi Pride 来实现相同的目的

Note that composite build support is a new feature added in Gradle 3.1. Prior to Gradle 3.1 you can use Prezi Pride to achieve the same

这篇关于Gradle Maven之类的多模块项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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