29

I'm switching my project over to using Gradle and an internal SonaType Nexus for hosting my dependencies. My core project depends on library project A and library project A has a dependency on library project B.

My issue is that as soon as I add LibA to my main project I get this error: "Module version com.example:LibA:1.1 depends on libraries but is not a library itself"

I have no issues adding library projects with jar dependencies with the same build script. I have seen people doing this successfully with LOCAL (in the project) android libraries but no one doing it with maven repos.

Is this a bug in gradle or did I misconfigure the library builds?

Core Project Build

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    maven {
        url "http://localhost:8081/nexus/content/repositories/releases/"
    }

    maven {
        url "http://localhost:8081/nexus/content/repositories/central/"
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile('com.example:LibA:1.+')
}

LibA Build

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17

        versionCode = "3"
        versionName = "1.2"
    }

    android {
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aild.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        compile ('com.example:LibB:1.+')
    } ...

LibB Build

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}

apply plugin: 'android-library'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 17

        versionCode = "1"
        versionName = "1.0"
    }

    android {
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aild.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
    } ...

Edit: Adding -info output for the error.

* What went wrong:
A problem occurred configuring project ':GradleTest'.
> Failed to notify project evaluation listener.
   > Module version com.example:LibA:1.+ depends on libraries but is not a library itself

Edit 2: Adding my local maven upload script for LibA

apply plugin: 'maven'
apply plugin: 'signing'

group = "com.example"
version = defaultConfig.versionName

configurations {
    archives {
        extendsFrom configurations.default
    }
}

signing {
    required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}


uploadArchives {
    configuration = configurations.archives
    repositories.mavenDeployer {
        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
        repository(url: sonatypeRepo) {
            authentication(userName: sonatypeUsername,
                    password: sonatypePassword)
        }

        pom.project {
            name 'com-example'
            packaging 'aar'
            description 'none'
            url 'https://internal github link'

            scm {
                url 'scm:git@https://internal github link'
                connection 'git@https://internal github link'
                developerConnection 'git@https://internal github link'
            }

            licenses {
                license {
                    name 'example'
                    url 'example'
                    distribution 'example'
                }
            }

            developers {
                developer {
                    id 'example'
                    name 'example'
                    email 'example'
                }
            }

            groupId "com.example"
            artifactId rootProject.name //LibA
            version defaultConfig.versionName
        }
    }
}
3

8 Answers 8

2

Your line in the dependencies to include LibA is wrong. To include a library project, use this:

compile project(':LibA')

If the library's directory isn't at the root of your project directory, you'll need to specify a colon-delimited path. For example, if your directory structure is:

projectFolder
  |
  +--coreProject
  |
  +--libraries
      |
      +--LibA
      |
      +--LibB

your dependency will be:

compile project(':libraries:LibA')

This is the same as the notation you use in your settings.gradle file.

8
  • As far as I know this is the method you would use for LOCAL dependencies, ie dependencies where the code is actually in the project structure. In my example I'm using remote dependencies pulled from mavencentral and a custom maven repo. My goal is to avoid local code in my project so that I don't need submodules to update them.
    – sgarman
    Commented Nov 21, 2013 at 19:47
  • Oh, okay. Can you run the build from the command line and add the --info command-line option? That may shed more light on what's going wrong. It could be that your local Maven repo isn't set up right and Gradle can't find LibA. How have you set up that local Maven repo? Commented Nov 21, 2013 at 19:56
  • Yes the local maven repo works fine for all regular android libraries and jars. I only get the error message above when adding a library project that has another android library project as a dependency. Added -info error to original post.
    – sgarman
    Commented Nov 21, 2013 at 19:58
  • How are you deploying LibA into the local Maven repo? If you're just trying to drop the library project into there, it won't work -- you have to configure your Gradle build script to deploy the AAR into the repo. There's some relevant info in gradle.org/docs/current/userguide/maven_plugin.html Commented Nov 21, 2013 at 21:20
  • I will post the code in the above post, let me know if you see errors.
    – sgarman
    Commented Nov 21, 2013 at 21:35
2

Maybe problem is that you use mavenCentral as your repository for library projects

repositories {
    mavenCentral()
}

and not yours nexus repository where actual dependencies exists

repositories {
    maven {
        url "http://localhost:8081/nexus/content/repositories/releases/"
}

    maven {
        url "http://localhost:8081/nexus/content/repositories/central/"
    }
}
0
2

If you uploaded library artifact for both jar and aar, try this.

compile 'com.example:LibA:1.1.1@aar'
1

In my work, I have used compile project(':google-play-services_lib') instead of compile ('google-play-services_lib') when I declare dependent projects in my build.gradle file. I think that is the right way to do this with Gradle: http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:project_dependencies

5
  • These are maven hosted gradle projects not local source gradle projects, if you keep reading the section you linked you will see dependency declarations like that as well.
    – sgarman
    Commented Nov 21, 2013 at 19:50
  • I see that. One more thing to try is list dependencies (gradle.org/docs/current/userguide/…) for each library project and then for core project and see the differences and debug. Commented Nov 21, 2013 at 19:59
  • I ran the command on the core project and it actually errors out with the same error when I try to build so I am not able to gather any additional information.
    – sgarman
    Commented Nov 21, 2013 at 20:55
  • I saw Scott's post above aar files and it triggered my memory. Take a look at this post:flexlabs.org/2013/06/…, it may help. Commented Nov 22, 2013 at 4:32
  • thanks for the link but I don't suffer this issue as my aars are actually already "remote" or served by maven (that's the custom nexus). The issue is what happens when I add libraries that have library dependencies. This just adds a single library dependency which is easy and working fine.
    – sgarman
    Commented Nov 22, 2013 at 21:28
1

if you don't want to have it as sub-module in the first build.gradle file you can add your local maven repository

mavenLocal()

//repositories
repositories {
    mavenCentral()
    mavenLocal()
}

but you need to run install on libA first.

1
  • Luis, I'm pretty sure that using my custom maven repo is the exact same process as local maven - which would still produce the error I have above.
    – sgarman
    Commented Nov 21, 2013 at 23:35
1

I had a similar error message after introducing by mistake a cyclic dependency between libraries:

build.gradle in commons-utils

dependencies {
    ...
    instrumentTestCompile project(':test-utils')
}

build.gradle in test-utils

dependencies {
    ...
    compile project(':commons-utils')
}

Fixing this solved the problem. The error message is not very explicit.

0
1

Don't know for sure, just a couple of thoughts:

  1. Have you tried running gradle assemble instead gradle build? This should skip tests, as I see error is related to test task.
  2. Maybe stupid, but try to remove dependcy on 2nd lib from the first and put it to your main build file listing before the first. I have a memory of something related. This way the second lib may be added to classpath allowing the first to compile.
  3. Try to create .aar files by hand and upload it to repo also by hand.
  4. It's a hack, but maybe it'll work: have you considered to exclude this :GradleTest module? See section 50.4.7
1
  • Got the same error with assemble, I believe one of the projects is actually called GradleTest. 2) I have not tried yet... but that defeats the whole purpose of dependency management - my project should not know about dependencies of the other projects.
    – sgarman
    Commented Dec 5, 2013 at 1:54
0

This issue has gone away with the later versions of Gradle and the Android Gradle Plugin. Seems to have just been an early release bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.