ARTIFACTORY: Why is the Artifactory Jenkins plugin only resolving from one repository and how to resolve from the build.gradle settings instead

AuthorFullName__c
Derek Pang
articleNumber
000006093
FirstPublishedDate
2024-05-15T07:46:09Z
lastModifiedDate
2025-05-21

ARTIFACTORY: Why is the Artifactory Jenkins plugin only resolving from one repository and how to resolve from the build.gradle settings instead

You may have run into an issue where your Gradle builds were not resolving from the expected repositories. Upon further investigation, you may find that there were only requests to one repository. This is the result of this change in the Jenkins Artifactory Plugin version 4.0.1. It causes the settings sent by the plugin (i.e. configured in the Jenkinsfile) to take precedence over the project settings. This means that repository configurations in the build.gradle will not be utilized.

In this article, we will show you how to work around this and resolve artifacts based on the build.gradle again.

Problem Example
2024-05-01T21:04:30.591+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Could not find com.google.guava:guava:32.1.2-jre.
2024-05-01T21:04:30.591+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Searched in the following locations:
2024-05-01T21:04:30.591+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]        - https://artifactory.art1.site/artifactory/gradle-libs-none/com/google/guava/guava/32.1.2-jre/guava-32.1.2-jre.pom


You may notice that you are not expecting to find this particular artifact in this repository, “gradle-libs-none” but instead in another repository.
This site is coming from the Jenkins file:
I.e.

…
                rtGradleResolver (
                    id: "GRADLE_RESOLVER",
                    serverId: "artifactory-art1-site-server",
                    repo: gradle-libs-none
                )

…
                rtGradleRun (
                    usesPlugin: true, // Artifactory plugin already defined in build script
                    useWrapper: true,
                    tool: GRADLE_TOOL, // Tool name from Jenkins configuration
                    rootDir: "gradle-examples/gradle-example-publish/",
                    tasks: 'clean artifactoryPublish',
                    deployerId: "GRADLE_DEPLOYER",
                    resolverId: "GRADLE_RESOLVER"
                )


While in the build.gradle you have configured the following repositories:

  repositories {
    maven {
            url "http://arti.test:8081/artifactory/gradle-libs-none"
            setAllowInsecureProtocol(true);
        }    
        maven {
            url "http://arti.test:8081/artifactory/gradle-libs-release"
            setAllowInsecureProtocol(true);
        credentials {
            username "user"
            password "password"
        }
        authentication {
            basic(BasicAuthentication)
        }
    }


The particular artifact is expected to be found at gradle-libs-release but because the plugin has a configured rtGradleResolver and utilizes it in the Gradle run (resolverId: "GRADLE_RESOLVER") that configuration takes precedence over the configurations in the build.gradle.
 

Resolution 

To resolve this issue you will have to take out the resolver in the Gradle run (i.e. comment out resolverId: "GRADLE_RESOLVER") or you can set this Gradle property in the settings.gradle:

dependencyResolutionManagement {
 repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
}


The change in 4.0.1 and above of the Jenkins Artifactory plugin sets the RepositoriesMode.PREFER_SETTINGS Gradle property when utilized. So setting it to PREFER_PROJECT will cause the build to instead use the build.gradle configurations again.