Is it possible to declare git repository as dependency in android gradle?

后端 未结 5 447
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 19:27

I want to use master version of my lib from mavencentral.

Is it possible to declare git repository as dependency in android gradle?

5条回答
  •  抹茶落季
    2020-11-30 19:48

    There is now a new feature in gradle that lets you add source dependencies from git.

    You first need to define the repo in the settings.gradle file and map it to a module identifier:

    sourceControl {
        gitRepository("https://github.com/gradle/native-samples-cpp-library.git") {
            producesModule("org.gradle.cpp-samples:utilities")
        }
    }
    

    And now in your build.gradle you can point to a specific tag (e.g.: 'v1.0'):

    dependencies {
        ...
    
        implementation 'org.gradle.cpp-samples:utilities:v1.0'
    }
    

    Or to a specific branch:

    dependencies {
        ...
    
        implementation('org.gradle.cpp-samples:utilities') {
            version {
                branch = 'release'
            }
        }
    }
    

    Caveats:

    • Gradle 4.10 or higher required
    • Does not support authentication yet

    References:

    • SourceControl docs
    • Gradle Blog - Introducing source dependencies
    • Gradle Forum - Limitations of Gradle source dependencies

提交回复
热议问题