Artifactory virtual repository cannot resolve the Gradle-Artifactory plugin
Asked Answered
F

2

5

So, I am at my wits end with trying to get the build-info-extractor-gradle plugin to work...sorry for venting. ;-)

I'm using the gradle wrapper, specifying gradle 1.6, artifactory 3.0.0, and trying to specify a dependency on the build-info-extractor-gradle plugin 2.1.x-SNAPSHOT, as this is the specified version for gradle 1.5 and above.

I was attempting to follow this tutorial video, but it must be out-dated because it is still referencing gradle 1.0 and specifying jfrog repo paths, which don't contain 2.x versions of the plugin.


Artifactory Setup


Gradle Setup

settings.gradle (generated from artifactory)

buildscript {
    repositories {
        maven {
            url 'http://artifactory.build.somewhere.com:8081/artifactory/gradle'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }

    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT'
    }
}

allprojects {
    apply plugin: 'artifactory'
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            ivy {
                ivyLayout = '[organization]/[module]/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
                mavenCompatible = false
            }
        }
    }
    resolve {
        repository {
            repoKey = 'gradle'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}

My repository configuration does work, if I upload the jar, locally, e.g. this is how I got the build-info-extractor-gradle jar to be downloaded. However, all of the dependencies fail, as you can see:

    $ gradlew tasks

    FAILURE: Build failed with an exception.

    * What went wrong:
    Could not resolve all dependencies for configuration 'classpath'.
    > Could not find commons-io:commons-io:2.0.1.
      Required by:
          unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT
    > Could not find org.apache.ivy:ivy:2.2.0.
      Required by:
          unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-
...
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

Any ideas of what's wrong with either my gradle configuration or my artifactory repo configuration? Why can't it resolve external dependencies from remote repositories? Should I just add mavenCentral?


Update

I added mavenCentral() to the repositories, just to see what would happen and got:

$ gradlew tasks
Download http://repo1.maven.org/maven2/commons-io/commons-io/2.0.1/commons-io-2.0.1.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/15/commons-parent-15.pom
Download http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.pom
Download http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/5/commons-parent-5.pom
Download http://repo1.maven.org/maven2/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.pom

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration 'classpath'.
> Could not find org.jfrog.buildinfo:build-info-extractor:2.1.x-SNAPSHOT.
  Required by:
      unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Update #2

Started fresh. Removed mavenCentral() and the locally uploaded jar and pom, then ran with --info and --refresh-dependencies:

$ gradlew --refresh-dependencies -i tasks
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'D:\repos\some_build\build.gradle'.
Included projects: [root project 'some_build']
Evaluating root project 'some_build' using build file 'D:\repos\some_build\build.gradle'.
Compiling build file 'D:\repos\some_build\build.gradle' using BuildScriptClasspathScriptTransformer.
Resource missing. [HTTP GET: http://artifactory.build.somewhere.com:8081/artifactory/gradle/org/jfrog/buildinfo/build-info-extractor-gradle/2.1.0/build-info-extractor-gradle-2.1.0.pom]
Resource missing. [HTTP HEAD: http://artifactory.build.somewhere.com:8081/artifactory/gradle/org/jfrog/buildinfo/build-info-extractor-gradle/2.1.0/build-info-extractor-gradle-2.1.0.jar]

FAILURE: Build failed with an exception.

So, clearly, my virtual "gradle" repo is not finding the artifact. How can I tell if it is searching the remote "gradle-plugins" repo?

Fellner answered 8/7, 2013 at 2:10 Comment(0)
F
6

Doh! It turns out that there are two very important configuration options, which disable remote repository resolution, which are selected by default (I can't recall checking/unchecking these?).

Anyways, here is what I did, in order to finally get the gradle-artifactory plugin working, via resolution with my virtual repo:

  • Disable global offline mode
    1. Go to: Admin -> Configuration -> General
    2. Ensure that the Global Offline Mode is deselected. You'll see this option in General Settings
    3. Save
  • Enable remote artifact resolution for your virtual repo
    1. Go to: Admin -> Configuration -> Repositories -> {Edit the virtual repo} -> Advanced Settings
    2. Ensure that the virtual repository has Artifactory Requests Can Retrieve Remote Artifacts selected
    3. Save
  • Add the gradle-plugins remote repo to your virtual repo
    1. Choose New in remote repositories
    2. Give your remote repo a name, such as jfrog-gradle-plugins
    3. Set URL to http://repo.jfrog.org/artifactory/gradle-plugins
    4. Save
    5. Add the jfrog-gradle-plugins remote repo to your virtual repo's Selected Repositories, using the Edit option
    6. Save

Add following to build.gradle:

buildscript {
    repositories {
        maven {
            url "${repositoryUrl}/libs-release"
        }
    }
    dependencies {
        classpath( group: 'org.jfrog.buildinfo',
                   name: 'build-info-extractor-gradle',
                   version: '2.2.2')
    }
}

Add following to gradle.properties:

repositoryUrl = http://my.artifactory.server:8081/artifactory
repositoryUser = me
repositoryPassword = thisIsAPasswordStoredInMyUserDirectory

Hope that helps anyone struggling with getting started with integrating Artifactory and Gradle.

Helpful hint for debugging artifact resolution in Artifactory

Use the trace REST API option. For example:

http://repo.jfrog.org/artifactory/gradle-plugins/org/jfrog/buildinfo/build-info-extractor-gradle/2.2.2/build-info-extractor-gradle-2.2.2?trace

Fellner answered 30/1, 2014 at 2:31 Comment(1)
Note that I'm using very different settings now, compared to my original post. It really was my own configuration issues, within Artifactory that were blocking me.Fellner
P
1

Looks like the documentation is misleading :( Sorry about that. I am adding a clarification note now.

The page you are looking at is the documentation of a whole new (different and better) artifactory-publish plugin, but in the code you are using the classic artifactory plugin (which is also fine).

Please look at this page for the documentation of artifactory plugin.

P.S. you're more than welcome to try the artifactory-publish plugin, it's awesome.

Perspex answered 8/7, 2013 at 9:41 Comment(3)
Sorry, I believe that the "artifactory" mistake is a copy and paste error from generating the build script. I did notice that there was a newer version of the plugin (or perhaps an entirely different one?), and I was going to use "artifactory-publish". Thanks for clarifying that and noting it in the documentation.Fellner
Regarding the virtual gradle repo - just add gradle-plugins to it in the settings.Perspex
Regarding the generated script with artifactory - jfrog.com/jira/browse/RTFACT-5800Perspex

© 2022 - 2024 — McMap. All rights reserved.