如何通过存储库共享公共 build.gradle? [英] How to share a common build.gradle via a repository?

查看:24
本文介绍了如何通过存储库共享公共 build.gradle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将 Maven 构建移植到 gradle.maven 的一个特性是 pom 继承可以在 pom 中声明各种常见行为,将其发布到存储库,然后通过 元素在具体项目中使用它.

I'm looking at porting a maven build to gradle. One feature of maven is pom inheritance whereby I can declare a variety of common behaviour in a pom, publish that to a repository and then use that via the <parent> element in a concrete project.

我的问题只是在 gradle 中是否有等效的行为?

My Q is simply whether there is an equivalent behaviour in gradle?

我以前在 ant+ivy 中通过导入通用 build.xml 来完成此操作,这依赖于已经从源代码管理中检出通用 build.xml 的位置或使用类似 svn:externals 的东西.我可以毫无困难地重复这种方法,但这似乎是 maven 做得很好的一件事,所以很高兴在 gradle 中看到类似的东西.

I've previously done this in ant+ivy by importing a common build.xml which relied on either having already checked out the location of the common build.xml from source control or using something like svn:externals. I can repeat this approach without any real difficulty but this seems to be one thing maven does quite nicely so it would be nice to see something similar in gradle.

推荐答案

我目前的解决方案是选项 3;将常用脚本打包成jar作为资源,然后像这样在buildscript部分解压

My current solution is option 3; package the common scripts into a jar as resources and then unjar during the buildscript section like so

buildscript {
    repositories {
        // enterprise repo here
    }
    dependencies { 
        classpath 'com.foo.bar:common-build:0.1.0-SNAPSHOT'
    }
    dependencies {
        ant.unjar src: configurations.classpath.singleFile, dest: 'build/gradle'
    }
}

apply from: 'build/gradle/common.gradle'

这似乎是我想要的.

这篇关于如何通过存储库共享公共 build.gradle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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