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 {
    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


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"

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

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.