Orest
Orest

Reputation: 6748

How to prioritize mavenLocal over artifactory repo in gradle?

I have multi-modules project and I'm using artifactory for resolving custom libraries: build.gradle of parent project:

...
subporjects {
   ...
    apply plugin: "com.jfrog.artifactory"

    artifactory {
        resolve {
            contextUrl = ext.getProperty('ARTIFACTORY_URL')
            repoKey = ext.getProperty('ARTIFACTORY_REPO_NAME')
            username = ext.getProperty('ARTIFACTORY_USERNAME')
            password = ext.getProperty('ARTIFACTORY_PASSWORD')
        }
    }
}

It works as expected my library is published to artifactory with gradle artifactoryPublish and then it's fetched from there. But in some cases I want to fetch my custom library from mavenLocal() repo. I have next subproject build.gradle

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile 'my-custom-library'
}

But as I can see it is still resolves from artifactory. Can I somehow prioritize mavenLocal() over it ?

Upvotes: 1

Views: 994

Answers (2)

adarshr
adarshr

Reputation: 62603

If all you want to do is to depend on one subproject from within another, you should declare dependencies using the project notation:

dependencies {
    compile project(':shared')
}

https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:project_jar_dependencies

Upvotes: 0

lance-java
lance-java

Reputation: 28006

The repository priority will be the order in which they were added to the RepositoryHandler

I'm guessing that the artifactory repository is added when the plugin is applied so you could delay this by

afterEvaluate {
    subprojects {
        apply plugin: "com.jfrog.artifactory"
        // etc
    }
}    

Or maybe

evaluationDependsOnChildren()
subprojects {
    apply plugin: "com.jfrog.artifactory"
    // etc
}

Upvotes: 1

Related Questions