Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does Gradle support defining a different repo for one single compile time dependency?

Below is the snippet of my gradle file and what I’m trying to achieve is that, for the dependency artifact – com.google.code.gson:2.8.2 alone, should be fetched from a different repo instead of one mentioned under repositories section ? Is it possible ?

Say, com.google.code.gson:2.8.2 should be fetched only from https://internal-repo-url/artifactory/second-repo instead of https://internal-repo-url/artifactory/first-repo.

buildscript {
    repositories {
        mavenLocal()
        maven {
            url 'https://internal-repo-url/artifactory/first-repo'
        }
    }

apply plugin: 'com.choko-build'

dependencies {

    compile group: 'org.influxdb', name: 'influxdb-java', version: '2.20'
    compile ('org.repo.strung:javacontainer:1.8.16') {
        exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
        exclude group: 'com.google.code.gson', module: 'gson'
    }
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, this is possible via Gradle’s repository filtering mechanism: Declaring content exclusively found in one repository.

For example (untested):

repositories {
    // This repository will _not_ be searched for artifact "com.google.code.gson:gson:2.8.2"
    // despite being declared first
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                url 'https://internal-repo-url/artifactory/first-repo'
            }
        }
        filter {
            // this repository *only* contains artifacts with group "com.google.code.gson:gson:2.8.2"
            includeVersion "com.google.code.gson", "gson", "2.8.2"
        }
    }
}

Have a look at Repository content filtering for other available options.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading