Giter Site home page Giter Site logo

bat-cha / gradle-plugin-git-dependencies Goto Github PK

View Code? Open in Web Editor NEW
152.0 13.0 24.0 814 KB

A Gradle Plugin to manage git repository dependencies

Home Page: http://bat-cha.github.io/gradle-plugin-git-dependencies/

Groovy 72.60% Shell 27.26% Java 0.14%

gradle-plugin-git-dependencies's Introduction

Git Dependencies Plugin for Gradle

The Git dependencies plugin helps resolving Gradle project dependencies via git using seamless gradle syntax. It relies on Gradle multi-project build capabilities. The purpose of this plugin is to setup a multi-project Gradle environment ONLY when a dependency cannot be resolved via the classical maven or ivy Gradle Dependency Resolution.

What's this ?

If you sometime need to convert some external module dependency to project dependency then this plugin is for you ! Just specify your git repo where the plugin can find your dependency.

The git-dependencies plugin adds 3 tasks to your project:

  • initGitDependencies
  • resolveGitDependencies
  • refreshGitDependencies

initGitDependencies task

This task will look for dependency that cannot be resolved but have a git extra property. It will clone them into project.gitDependenciesDir, default to "${projectDir.parent}/${project.name}-git-dependencies" and prepare your environment for a multi-project build by adding '''settings.gradle''' in "${projectDir.parent}

resolveGitDependencies task

This task will always be called after your project evaluation, it is simply replacing any unresolved git dependencies by a project dependency using the cloned repositories.

refreshGitDependencies task

This task simply refresh all cloned repository

Usage

To use the git-dependencies plugin, include in your build script:

apply plugin: 'git-dependencies'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.batcha.gradle.plugins:git-dependencies:0.2'
    }
}

If you do not need the gradle --offline (cf http://issues.gradle.org/browse/GRADLE-1768), You can also do

apply from: 'https://raw.github.com/bat-cha/gradle-plugin-git-dependencies/0.2/git-dependencies.gradle'

To declare a Dependency,

dependencies {

  compile('org.batcha:dummy-project-a:4.2').ext.git = 'https://github.com/bat-cha/dummy-java-project-a.git'
    
}

or if you want to use a different version from the unresolved dependency

dependencies {

  compile('org.anic:myproject:42.0') {
    ext.git = '[email protected]:fabzo/gradle-plugin-git-dependencies.git'
    ext.gitVersion = 'some/otherBranch/h2g2'
  }
    
}

To setup the multi-project build for all the non resolved dependencies having a git property,

./gradlew initGitDependencies

To refresh git repositories for the non resolved dependencies having a git property,

./gradlew refreshGitDependencies

API Doc

gradle-plugin-git-dependencies's People

Contributors

bat-cha avatar darshakthakore avatar fabzo avatar mheffner avatar scottdeboy avatar walterra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gradle-plugin-git-dependencies's Issues

mavenLocal refresh too slow

Sometime, the resolution of the dependecny can fails even if the dependency is correctly installed on mavenLocal

Add support for ssh keys with a passphrase

If you have an ssh private key with a passphrase, the fetch will fail. In order to get it to work, Jsch needs to be told how to use the appropriate agent (pageant, ssh-agent, etc).

Example using ssh-agent:
http://morecanaries.blogspot.com/2013/04/dont-dare-prompt-me.html

Agent examples from JSch folks:
https://github.com/ymnk/jsch-agent-proxy/tree/master/examples/src/main/java/com/jcraft/jsch/agentproxy/examples

Here is a part of a commit that added similar support in gradle-git:
ajoberstar/gradle-git@9f27727

Maven dependency support

I know, my stomach churns when I see maven too. But not everyone can be on the gradle train yet :-).

Anyway, I'd like to add an option that marks a github dependency as 'maven', and the install step will be 'mvn install' rather than 'gradlew(.bat)' install. The function should fail fast if 'mvn' is not in the path.

Undefined variables in build.gradle

sonatypeUserName and sonatypePassword are not defined in build.gradle because they are presumably in your personal gradle.properties file or an environment variable. I've found myself having to add the following to get gradle to sync when developing on this plugin

uploadArchives {
  repositories {
    mavenDeployer {
      def sonatypeUserName = ""
      def sonatypePassword = ""

Perhaps you could add something like the following depending on where you are getting your username/password from.

uploadArchives {
  repositories {
    mavenDeployer {
      def sonatypeUserName = System.getenv("SONATYPE_USERNAME") ?: ""
      def sonatypePassword = System.getenv("SONATYPE_PASSWORD") ?: ""

This would make it easier for others that don't need to publish to work on this plugin.

Thanks

Build process assumes current directory is in your $PATH

If you do not have 'the current directory (.) in your $PATH environment variable, building dependencies fails with:

Cannot run program "gradlew" (in directory "/Users/epierce/src/MessageServiceWorker/MessageServiceWorkerJobs/build/git-dependencies/GoogleAppsClient"): error=2, No such file or directory

The obvious workaround is just to run export PATH=$PATH:., but if you change the call to gradlew to ./gradlew in ResolveGitDependenciesTask.groovy, it will work regardless of what is in the user's $PATH

password protected git repository

Do you support password protected repositories (or authorization via key auth) somehow?

When trying to define a password protected git repository as a dependency, I get the following error:

Execution failed for task ':resolveGitDependencies'.
> <http://path-to-repository/>: not authorized

I tried to add the user/password like

http://username:password@path/repository.git

Also tried via SSH + key auth like

ssh://git@path/repository.git

However, even when specifing the SSH version, the error message still contains the http-link.

Resolve buildscript/other plugin dependencies directly from Git - possible?

Hi,
I'd really like to make the resolution of a 3rd-party Gradle plugin, 'gradle-trang', part of my main project's own Gradle build-script (the external plugin, 'gradle-trang', is _not_ under dependency management and is hosted at Github).

As this is not a project dependency and is instead a plugin required by the script itself (in order to process some XML files, before another tasks is executed), is it possible to use your plugin to retrieve a Gradle PLUGIN project from Git (it will probably be declared within the buildscript => dependencies closure section). For example:

-Attempt at resolving the 'gradle-trang' plugin from a GitHub (for Gradle buildscript itself, NOT code project)

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'org.batcha.gradle.plugins:git-dependencies:0.2'

        //The 'Trang' dependency should be brought in and built from the Git repository (i.e. is *not* hosted for Maven)
        compile('org.hsudbrock:gradle-trang:0.1-SNAPSHOT').ext.git = 'https://github.com/hsudbrock/gradle-trang.git'
    }

apply plugin: 'trang'   //To be resolved/built directly from Git by using your 'gradle-plugin-git-dependencies'

Of course, once that plugin has been cloned from Git[Hub], it would need to be installed locally by Gradle and its task should be available from the main build script (along with your own).

If this isn't feasible, it's no biggy, I can install manually, I just wanted to make this as automated as possible.

Rich

Error in readme

Hi,

I'm trying out your project to set up my gradle build script with git-dependencies, but I think there is a small flaw in the readme.

To apply the plugin to the build script is says to use:

classpath 'org.batcha.gradle.plugins:gradle-plugin-git-dependencies:0.1'

This results in the following error when running the Gradle build file:

FAILURE: Build failed with an exception.

What went wrong:
Could not resolve all dependencies for configuration ':classpath'.
Could not find group:org.batcha.gradle.plugins, module:gradle-plugin-git-dependencies, version:0.1.

I think the readme should instead have said:

classpath 'org.batcha.gradle.plugins:git-dependencies:0.1'

Once I had changed the build script to use that, the plugin is downloaded. This also seems to be more in line with what you've got in your settings.gradle file.

Cheers,

Wijnand

PS: Gradle installation details below.

Gradle 1.2

Gradle build time: Wednesday, 12 September 2012 10:46:02 o'clock UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_39 (Sun Microsystems Inc. 20.14-b01)
OS: Windows 7 6.1 x86

What does this mean?

"To be resolved just as other dependencies, this plugin add the mavenLocal repository to your project"

Does this mean this plugin ADDS the mavenLocal repro or I need to add the mavenLocal repro to the project.

Typo? It's on the project's README.md.

Pretty awesome that this performs a checkout of a git repro. In the final step when it tries to run ./gradlew on the dependency I get this error:

C:\TestProject>gradle eclipse

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':resolveGitDependencies'.

    java.io.IOException: Cannot run program "gradlew.bat" (in directory "C:\TestProject\build\git-dependencies\dummy-project-a"): CreateProcess error=2, The system cannot find the file specified

Plugin does not check out a branch correctly

Currently when i specify a git repository in the compile dependency, for example

compile( 'groupId:artifactId:${branchName}' ).ext.git = 'RepoURL'

It creates a new branch with 'branchName' but that branch always points to the origin/master. Ideally one would expect that 'branchName' to point to an existing branch in origin. With tags this works ok since tags are in detached head mode.

Seems like the branch creation logic is missing a call to the setStartPoint method.

How to pass credentials

For my https://github.com/XXXXXXXXX/TestAndroidGradle.git how to pass credentials

git org.eclipse.jgit.api.errors.TransportException: https://github.com/XXXXXXXXXXXX/TestAndroidGradle.git: not authorized

compile('com.xxxxxxxxx:library:1.0.0_Build-3@aar').ext.git = ('https://github.com/XXXXXXXXXXXX/TestAndroidGradle.git')
In my ubuntu home directory ~/.gradle/gradle.properties I already specified the below two properties
github.credentials.username=XXXXX
github.credentials.password=XXXXX

Thanks
Samba Damerla

Incompatible with Android plugin?

Hey,

When I try to use a dependency with the android plugin applied, the build fails. It only fails when the dependency doesn't exist in the local Maven repo.

build.gradle snippet:

android {
    ...

    dependencies {
        compile('org.batcha:dummy-project-a:4.2').ext.git = 'https://github.com/bat-cha/dummy-java-project-a.git'
    }
}

gradle output:

FAILURE: Build failed with an exception.

What went wrong:
Could not resolve all dependencies for configuration ':compile'.
Could not find group:org.batcha, module:dummy-project-a, version:4.2.
...

I ran the build script with the --info and --stackTrace flags, but they didn't seem to provide any more information on where exactly things went wrong. I can post the output later if you want.

Cheers,

Wijnand

PS: My build script dependency is to the locally built git-dependencies-0.1.jar that has #3 fixed.

android studio error

Error:Unable to find method 'com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V'.
Possible causes for this unexpected error include:

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Required Gradle version

Hello,

I was wondering what the required Gradle version is to use this plugin? I'm using 1.2 as it is the required version for the Android Gradle plugin.
From your build.gradle file I take that the required version is 1.3?

task wrapper(type: Wrapper) { gradleVersion = '1.3' }

Is there any possibility for you to support 1.2 as well?

Thanks again,

Wijnand

Do not call gradlew on dependency when it does not exist

I'm trying to get the plugin to download a dependency that is not a Gradle project itself. It works fine, but then it tries to run ./gradlew and it fails. Can the plugin check if gradlew actually exists in the project before calling it?

Required Git Project Structure

I'm having an issue with most git repositories I want to use.
They don't adher to the structure that seems to be required by this plugin, that is the root/build.gradle file has to be within the root folder of the repository, like it's done in the org.batcha:dummy-project-a:4.2 example project, instead the structure is like this: root/libname/build.gradle as in https://github.com/adjust/android_sdk.
The error I'm getting is: "Gradle wrapper not found in ..\MyProject\build\git-dependencies\Adjust ! The dependency won't be installed to your local repository"
All required files are in ..\MyProject\build\git-dependencies\Adjust\Adjust.

Is there a way to specify which folder of the repository the relevant files are in that I've overlooked (maybe through gradle itself? admitedly I'm not very experienced with that) or was this not considered? If this is missing, would it be possible to add a way to specificy local path within the repository?

I'm using version 0.1 of the plugin from maven central because I get the following error with 0.2: Error:Cause: com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V this seems to be caused by a missing guava (17.0+), but trying to include that, even before this plugin, doesn't help me.

The relevant parts of my main build.gradle file looks like this:

apply plugin: 'git-dependencies'
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'

        //classpath 'com.google.guava:guava:17.0'
        //classpath 'org.batcha.gradle.plugins:git-dependencies:0.2' // produces an error
        classpath 'org.batcha.gradle.plugins:git-dependencies:0.1'
    }
}

repositories {
    mavenCentral()
}


dependencies {
    compile('com.adjust:Adjust:v3.3.2').ext.git = 'https://github.com/adjust/android_sdk.git'
}

Perhaps there's a possibility to define a path similar to my not yet managed dependencies:
build.gradle:

dependencies {
    compile project(':Adjust')
}

settings.gradle:

include ':Adjust'
project(':Adjust').projectDir = new File(settingsDir, '../MyProject/build/git-dependencies/Adjust/Adjust')

Unable to resolve dependencies after running initGitDependencies task

This project seems to be exactly what I need, but I'm not sure I am using it correctly.

I am able to clone the repository correctly via $ gradlew initGetDependencies, and it checks out the correct repository into the proj-git-dependencies directory, but when I attempt to build using the java plugin I get the following error:

* What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not find com.vendor:git_proj:1.0.
  Searched in the following locations:
      https://repo1.maven.org/maven2/com/vendor/git_proj/1.0/git_proj-1.0.pom
      https://repo1.maven.org/maven2/com/vendor/git_proj/1.0/git_proj-1.0.jar
  Required by:
      :proj:unspecified

Simply calling the resolveDependencies action gives me the following output:

$ gradlew resolveGitDependencies
Failed to Replace an ExternalDependency by a Project Dependency...
Failed to Replace an ExternalDependency by a Project Dependency...
Failed to Replace an ExternalDependency by a Project Dependency...
Failed to Replace an ExternalDependency by a Project Dependency...
Failed to Replace an ExternalDependency by a Project Dependency...
:resolveGitDependencies

BUILD SUCCESSFUL

Total time: 2.645 secs

I am attempting to build from the same project that contains the git dependencies, but I noticed that the initGitDependencies task places a settings.gradle file in the parent of the project. Is this plugin intended to allow me to create a separate parent project that is responsible for building projects with git dependencies, or is there a separate issue that I am experiencing?

Here is the build.gradle project of what I am trying to build to clarify what I am trying to achieve:

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'git-dependencies'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.batcha.gradle.plugins:git-dependencies:0.2'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

mainClassName = "main.Proj"

sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
}


repositories {
    mavenCentral()
}

dependencies {
    compile("com.vender:git_proj:1.0"){
        ext.git = "[email protected]:java-libraries/git-proj.git"
        ext.gitVersion = "gradle-test"
    }
}

Let me know if I'm not being clear.

Thanks alot!

gradlew install

Hi.

I'm trying to use this plugin to have git dependencies in my android project.
i realised that after cloning the git repository, it is calling the install task on the cloned dependency, which in android is actually trying to install that dependency on the phone. If i do not have a phone connected to my pc, the task fails with


* What went wrong:
Execution failed for task ':installDebugAndroidTest'.
> com.android.builder.testing.api.DeviceException: No connected devices!

my thing is, why is it even calling 'install' ?
build would be ok, but i dont want to install those dependencies on any phone.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.