Jar present in cache but not resolved in project

I have a groovy project in which I am trying to use the http-builder module. My build.gradle file looks as below

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0'
        classpath ('org.codehaus.groovy.modules.http-builder:http-builder:0.7.2') {
            exclude(module: 'groovy')
        }
    }
}

group 'example.gradle.plugins'
version '1.0.7'

apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: "com.jfrog.artifactory"

sourceCompatibility = 1.7

dependencies {
    compile gradleApi()
    compile localGroovy()
    compile('org.codehaus.groovy.modules.http-builder:http-builder:0.7.2') {
        exclude(module: 'groovy')
    }
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

I cannot use HTTPBuilder though as it is not found in the external libraries. I checked my ~/.gradle/cache folder and it does have the following entries

./modules-2/files-2.1/org.codehaus.groovy.modules.http-builder/http-builder/0.7.2/2f8b0b834864b56848900d6202d0bc4d5b666672/http-builder-0.7.2.pom
./modules-2/files-2.1/org.codehaus.groovy.modules.http-builder/http-builder/0.7.2/323092cd786480311c1cf693770f9e6fc20a8bef/http-builder-0.7.2.jar
./modules-2/files-2.1/org.codehaus.groovy.modules.http-builder/http-builder/0.7.2/f1860181de06236f28f3f247aed57fa4631016d8/http-builder-0.7.2-sources.jar

What am I doing wrong here?

You need to specify a root level repositories { } block. Just because the module is cached (likely by another build) does not mean the cached version will be used for this build if you haven’t defined a repository to get things from. Basically, if I tell my build to only use dependencies downloaded from repository A, it will not use one downloaded from repository B, as there is no guarantee they are the same. We refer to this as the cache being “repository-aware”. Logically, if I specify no repositories at all, no external dependencies can be resolved.

Thanks!! Turns out adding another repo

maven {
            url 'http://gradle.artifactoryonline.com/gradle/libs/'
        }

in a root repositories block solved the issue. However when I run the maven publish task it generates the follow pom

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example.gradle.plugins</groupId>
  <artifactId>upload</artifactId>
  <version>1.0.8</version>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy.modules.http-builder</groupId>
      <artifactId>http-builder</artifactId>
      <version>0.7.2</version>
      <scope>runtime</scope>
      <exclusions>
        <exclusion>
          <artifactId>groovy</artifactId>
          <groupId>*</groupId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

but when the plugin is applied I get an error saying

Error:Could not find org.codehaus.groovy.modules.http-builder:http-builder:0.7.2.
Searched in the following locations:
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/org/codehaus/groovy/modules/http-builder/http-builder/0.7.2/http-builder-0.7.2.pom
    file:/Applications/Android Studio.app/Contents/gradle/m2repository/org/codehaus/groovy/modules/http-builder/http-builder/0.7.2/http-builder-0.7.2.jar
    https://maven.fabric.io/public/org/codehaus/groovy/modules/http-builder/http-builder/0.7.2/http-builder-0.7.2.pom
    https://maven.fabric.io/public/org/codehaus/groovy/modules/http-builder/http-builder/0.7.2/http-builder-0.7.2.jar

How can I include the repository in the generated pom?

You don’t. The pom.xml simply defines the dependencies, not where to get them. It’s up to the consuming project to specify this.

Is there a way I can package the dependency with the plugin so that the project using this plugin need not add the repo?

You could certainly use something like the shadow plugin to bundle dependencies in your plugin’s JAR.

Hy Mr. Mark, please I am new to android studio and I just created my first project but whenever I try to sync with gradle it takes alot of time and then later show error message "can’t download builder-4.0.0.jar. so I downloaded the jar file using browser but I don’t know the path to put the file. I searched for builder -4.0.0.pom and. I saw it located in folder that has a weird name and that makes it more confusing to me. Please do have any idea on what to do? Thank you