Jar present in cache but not resolved in project


(Kushal Kadaba) #1

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?


(Mark Vieira) #2

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.


(Kushal Kadaba) #4

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?


(Mark Vieira) #5

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.


(Kushal Kadaba) #6

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


(Mark Vieira) #7

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