• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

stabib/gradle-git-repo-plugin: Use a private git repo as a repository

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

stabib/gradle-git-repo-plugin

开源软件地址(OpenSource Url):

https://github.com/stabib/gradle-git-repo-plugin

开源编程语言(OpenSource Language):


开源软件介绍(OpenSource Introduction):

The Gradle Git Repo Plugin

This plugin allows you to add a git repository as a maven repo, even if the git repository is private, similar to how CocoaPods works.

Using a github repo as a maven repo is a quick and easy way to host maven jars. Private maven repos however, aren't easily accessible via the standard maven http interface, or at least I haven't figured out how to get the authentication right. This plugin simply clones the repo behind the scenes and uses it as a local repo, so if you have permissions to clone the repo you can access it.

This plugin lets you tie access to your repository to github accounts, seamlessly. This is most useful if you've already set up to manage distribution this way. Deliver CocoaPods and Maven artifacts with the same system, then sit back and relax.

Building

Run gradle build to build, and gradle -Porg=layerhq -Prepo=gradle-releases publishToGithub to publish. The plugin uses itself to publish itself :).

Usage

This plugin needs to be added via the standard plugin mechanism with this buildscript in your top level project

buildscript {
    repositories {
        maven { url "https://github.com/layerhq/releases-gradle/raw/master/releases" }
    }
    dependencies {
        classpath group: 'com.layer', name: 'git-repo-plugin', version: '1.0.0'
    }
}

and then apply the plugin

apply plugin: 'git-repo'

Depending on github repos

This plug adds a github method to your repositories block

repositories {
    github("layerhq", "maven-private", "master", "releases")
}

Add this alongside other repositories and you're good to go

Publishing to github repos

Publishing is a bit less seamless, mostly because there isn't one single way to handle publishing in gradle (also the maven-publish plugin is infuratingly tamper-proof). You're expected to have a task called publish by default, that publishes to the locally cloned github repo. That task gets wrapped into a publishToGithub task that handles committing and pushing the change. Then you can run

gradle -Porg=layerhq -Prepo=gradle-releases publishToGithub

You can also run

gradle -Porg=layerhq -Prepo=gradle-releases publish

to stage a release in the local github repo and commit it manually.

The maven-publish plugin defines a publish task for you, so you just need to supply the right url in the publishing block

publishing {
    publications {
        //...
    }
    repositories {
        maven {
            url "file://${System.env.HOME}/.gitRepos/${property("org")}/${property("repo")}/releases"
        }
    }
}

A version of this with the maven plugin might look like

String url() {
    String org =  hasProperty("org") ? property("org") : "layerhq"
    String repo = hasProperty("repo") ? property("repo") : "maven-private"
    String repoHome = hasProperty("gitRepoHome") ? property("gitRepoHome") : "${System.env.HOME}/.gitRepos"
    return "file://$repoHome/$org/$repo/releases"
}

task publishJar(type: Upload, description: "Upload android Jar library") {
    configuration = configurations.sdkJar
    repositories {
        mavenDeployer {
            repository(url: url())
        }
    }
}

Flags

The following flags are supported

  • gitRepoHome (optional for dependencies and publishing, default is ~/.gitRepos) The location for cloned gitrepos
  • org (required for publishing) The github org to publish to
  • repo (required for publishing) The github repo to publish to
  • publishTask (option for publishing, default is publish) The publish task to use

Futures

It would be nice to make publishing seamless, without the flags, and completely hide the locally cloned repo. That might require reimplementing maven publishing though. The maven-publish plugin isn't amenable to having its settings messed with after it's been applied unfortunately.

Credits

Douglas Rapp

License

The gradle git repo plugin is available under the Apache 2 License. See the LICENSE file for more info.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap