2

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 = 'com.android.support.test:runner:0.5'
    appcompat = 'com.android.support:appcompat-v7:24.1.0'
    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 = 'com.android.support:design:24.1.0'
    cardview = 'com.android.support:cardview-v7:24.1.1'
    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.design
    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 ('com.github.xxx:module2:1.0.0@aar') {
    transitive=true
}

and

compile 'com.github.xxx:module2:1.0.0'

and

compile ('com.github.xxx:module2:1.0.0') {
    transitive=true
}

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

Vignesh Sundaramoorthy
  • 1,827
  • 1
  • 25
  • 38

1 Answers1

2

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('com.android.application') ||
          project.getPlugins().hasPlugin('com.android.library')) {
    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('groupId', it.group)
            dependencyNode.appendNode('artifactId', it.name)
            dependencyNode.appendNode('version', it.version)
          }
        }
      }
    }
Community
  • 1
  • 1
Vignesh Sundaramoorthy
  • 1,827
  • 1
  • 25
  • 38