6
votes

I am trying to resolve dependency in configuration phase with artifactory gradle plugin.

apply plugin: 'java'
apply plugin: 'com.jfrog.artifactory'

artifactory {
  contextUrl = "${artifactory_contextUrl}"
  ...
  resolve {
    repository {
      repoKey = 'repo'
      username = "${artifactory_user}"
      password = "${artifactory_password}"
      maven = true
    }
  }
}

dependencies {
  compile 'commons-lang:commons-lang:+'
}

task testCustomResolve {
  logger.quiet configurations.getByName('compile').singleFile.absolutePath
}

And it gives me

Could not resolve all dependencies for configuration ':compile'. Cannot resolve external dependency commons-lang:commons-lang:+ because no repositories are defined.

It works as a charm in execution phase

task testCustomResolve << {
  logger.quiet configurations.getByName('compile').singleFile.absolutePath
}

or when I use mavenCentral()

repositories {
  mavenCentral()
}
1
Try placing your task definition inside an afterEvaluate {...} block.Mark Vieira
Did you ever figure this out? I'm getting the same error. In my case, it seems to work fine when I run the actual build, but I get the error when trying to list all tasks...Hakanai
Also getting the same error. Quite frustrating...zedix
Might help someone in future - A repository definition needs to be added outside of buildscript block ex. repositories { mavenCentral() }Sunil

1 Answers

1
votes

In case you don't need to publish to Artifactory, I noticed that it works better if you don't use the artifactory {} syntax. Instead, try using:

plugins {
    id "com.jfrog.artifactory" version "4.4.10"
}

repositories {
    mavenLocal()
    maven {
        url "${artifactory_contextUrl}/${artifactory_repo}"
        credentials {
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
    }
    mavenCentral()
}