gradle父类pom之类的功能 [英] gradle parent pom like feature

查看:1165
本文介绍了gradle父类pom之类的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中,我们使用Maven。我会第一次尝试Gradle。我们为所有项目设置常用的maven插件和少量的comon依赖项,使用一个共同的父项目。 Gradle中有类似的选项吗?

At my work we use Maven. I am going to try gradle for the first time. We use a common parent pom for all project which has setting for commonly used maven plugins and few comon dependencies. Is there a similar option available in gradle?

我的第二个问题是关于版本管理。我们使用Maven发布插件,这对我们来说非常有用。 Gradle中有类似的东西吗?

My second question is regarding release management. We use maven release plugin, which works pretty good for us. Is there something similar available in Gradle?

推荐答案

要在同一个构建的多个项目中共享内容,请使用 allprojects {...} 子项目{...} 等等。在父项目中声明的foo = ... )在子项目中可见。一个常见的习惯用法是使用 ext.libs = [junit:junit:junit:4.11,spring:org.springframework:spring-core:3.1.0.RELEASE),... ] 在顶级构建脚本中。然后,子项目可以通过短名选择性地包含依赖关系。您应该可以在 Gradle论坛上找到更多相关信息。

To share stuff within multiple projects of the same build, use allprojects { ... }, subprojects { ... }, etc. Also, extra properties (ext.foo = ...) declared in a parent project are visible in subprojects. A common idiom is to have something like ext.libs = [junit: "junit:junit:4.11", spring: "org.springframework:spring-core:3.1.0.RELEASE", ...] in the top-level build script. Subprojects can then selectively include dependencies by their short name. You should be able to find more information on this in the Gradle Forums.

要在整个构建中共享逻辑,您可以编写脚本插件( foo.gradle ),将其放在Web服务器上,并将其包含在构建中应用于:http:// ...,或者编写一个二进制插件(一个实现 org.gradle.api.Plugin ),将其作为Jar发布到存储库,并使用 apply plugin:... buildscript {} 部分。有关详细信息,请参阅 Gradle用户指南以及Gradle发行版中的许多示例。

To share logic across builds, you can either write a script plugin (foo.gradle), put it up on a web server, and include it in builds with apply from: "http://...", or write a binary plugin (a class implementing org.gradle.api.Plugin), publish it as a Jar to a repository, and include it in builds with apply plugin: ... and a buildscript {} section. For details, see the Gradle User Guide and the many samples in the full Gradle distribution.

脚本(但不是二进制)插件的当前局限性是它们没有被缓存。因此,构建只有在能够连接到为插件提供服务的Web服务器时才会成功。

A current limitation of script (but not binary) plugins is that they aren't cached. Therefore, a build will only succeed if it can connect to the web server that's serving the plugin.

至于第二个问题(应该是单独的问题),有几个第三方发布插件可用,例如 https://github.com/townsfolk/gradle - 发布

As to your second question (which should have been a separate question), there are a couple of third-party release plugins available, for example https://github.com/townsfolk/gradle-release.

这篇关于gradle父类pom之类的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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