Vignesh Sundar Vignesh Sundar - 2 years ago 91
Android Question

How to specify dependencies in library(sdk) which has multiple modules

I have a Library project which has multiple modules, so that i centralised its dependencies in project level build.gradle like below

ext {
compileSdkVersion = 23
minSdkVersion = 9
targetSdkVersion = 24
buildToolsVersion = '23.0.3'
junit = 'junit:junit:4.12'
mockito = 'org.mockito:mockito-core:1.10.19'
testRunner = ''
appcompat = ''
retrofit2 = 'com.squareup.retrofit2:retrofit:2.1.0'
gsonConverter = 'com.squareup.retrofit2:converter-gson:2.1.0'
httpLogInterceptor = 'com.squareup.okhttp3:logging-interceptor:3.4.1'
design = ''
cardview = ''
universalImageLoader = 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

and i used it in modules as

dependencies {
compile project(':module1')
compile rootProject.appcompat
compile rootProject.retrofit2
compile rootProject.gsonConverter
compile rootProject.httpLogInterceptor
compile rootProject.cardview
compile rootProject.universalImageLoader
testCompile rootProject.junit
testCompile rootProject.mockito
androidTestCompile rootProject.junit
androidTestCompile rootProject.testRunner

in my sample app (another module in same project), i included the library module as
compile project(':module2')
& it works fine but now i published the sdk in jcenter & if i use it in a new app, the dependencies i mentioned in the library are not resolving.

i tried including the dependency like

compile ('') {


compile ''


compile ('') {

i have tried

How to specify dependencies in aar library?

Can an AAR include transitive dependencies?

if i missed any info please comment

Thanks in advance

Answer Source

Answering my own question, so that might be useful for any one. Thank @Gabriele Mariotti, I checked the pom generated, in that there is no dependencies tag available, so searched & found a snippet to add it.

but there they added it in publications, in my case one module depends on another module which is not published yet, that dependency is mention in build.gradle of module2 as complie project(':module1') and its generating the new pom which did not contains the name, description, etc., tags in publications folder.

So i added it to the previous pom fields creation area & it works for me

Here is the updated part of gradle-mvn-push.gradle

if (project.getPlugins().hasPlugin('') ||
          project.getPlugins().hasPlugin('')) {
    task install(type: Upload, dependsOn: assemble) {
      repositories.mavenInstaller {
        configuration = configurations.archives

        pom.groupId = GROUP
        pom.artifactId = POM_ARTIFACT_ID
        pom.version = VERSION_NAME

        pom.project {
          name POM_NAME
          packaging POM_PACKAGING
          description POM_DESCRIPTION
          url POM_URL

          scm {
            url POM_SCM_URL
            connection POM_SCM_CONNECTION
            developerConnection POM_SCM_DEV_CONNECTION

          licenses {
            license {
              name POM_LICENCE_NAME
              url POM_LICENCE_URL
              distribution POM_LICENCE_DIST

          developers {
            developer {
              id pom_developer_id
              name pom_developer_name


        //Updated part which adds dependencies in pom
        pom.withXml {
          def dependenciesNode = asNode().appendNode('dependencies')

          //Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
          configurations.compile.allDependencies.each {
            def dependencyNode = dependenciesNode.appendNode('dependency')
            dependencyNode.appendNode('version', it.version)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download