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

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

问题描述

我正在寻找将一个Maven构建移植到Gradle中。 maven的一个功能是 pom继承,据此我可以在pom中声明各种常见行为,将其发布到存储库,然后通过具体项目中的< parent> 元素使用该行为。

我的问题只是在gradle中是否存在等价的行为?

我之前在ant + ivy中通过导入一个公共的build.xml来完成这项工作,它依赖于已经从源代码检出公共build.xml的位置控制或使用像svn:externals。我可以在没有任何实际困难的情况下重复这种方法,但是这似乎是maven做得非常好的一件事,所以在gradle中看到类似的东西会很好。

解决方案

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

  buildscript {
repositories {
//企业仓库在这里
}
依赖项{
classpath'com.foo.bar:common-build:0.1.0-SNAPSHOT'
}
依赖关系{
ant.unjar src:configurations.classpath.singleFile,dest:'build / gradle'
}
}

适用于:'build / gradle /common.gradle'

这似乎是我想要的。


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.

My Q is simply whether there is an equivalent behaviour in 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.

解决方案

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'

This seems to do what I want.

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

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