0

I've created a library to use on most of our projects. So far, we've been using Github with Jitpack but our Jitpack subscription is expired and we've found an alternative way to upload the project elsewhere. We're using myMavenRepo for it. From this answer I was able to upload the project. However, there is a problem (which doesn't have an answer to include dependencies of the project itself.)

The project contains dependencies, and when we add this project into another project, the dependencies are not added. I'd like to figure out how to do that.

Here is my code:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "sources"
}

publishing {
    publications {
        Repo(MavenPublication) {
            groupId 'com.example.repo'
            artifactId 'Repo'
            version '1.3.7'
            artifact(sourceJar)
            artifact("$buildDir/outputs/aar/repo-release.aar")
        }
    }
    repositories {
        maven {
            url "https://mymavenrepo.com/repo/repo_url/"
        }
    }
}

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 137
        versionName "1.3.7"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation ("com.kochava.base:tracker:3.5.0") {
        exclude group: "com.android.support"
    }
    implementation ("com.google.firebase:firebase-core:16.0.6") {
        exclude group: "com.android.support"
    }
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    // Required: Install Referrer (If publishing to Google Play)
    implementation 'com.android.installreferrer:installreferrer:1.0'

    // Optional: Instant App Status Collection
    implementation 'com.google.android.instantapps:instantapps:1.1.0'

    // Required for Flurry Analytics integration
    implementation 'com.flurry.android:analytics:11.4.0@aar'

    // Crashlytics implementation.
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
        transitive = true
    }
}

The publishing process is made with ./gradlew clean build publish (I'm using ubuntu) and the publish is successful. From the read side of the repo, we're implementing it like this (after putting the maven URL to allprojects section):

implementation 'com.example.repo:Repo:1.3.7'

While the project itself is added, the inner dependencies such as Crashlytics, Flurry, Firebase Core etc. are not added. What should I do to make this library implement its own dependencies too? Any help is appreciated, thanks.

Furkan Yurdakul
  • 2,801
  • 1
  • 15
  • 37
  • Possible duplicate of [Publish an Android library to Maven with aar and source jar](https://stackoverflow.com/questions/26874498/publish-an-android-library-to-maven-with-aar-and-source-jar) Check especially the answers dealing with adding dependencies. – Henry Feb 12 '19 at 06:17
  • Checking it out, right now. Edit: Yes I've followed that answer to upload the project, however the issue still exists. Edited the question accordingly. – Furkan Yurdakul Feb 12 '19 at 06:17
  • 1
    What about this answer: https://stackoverflow.com/a/42160584/1796579 – Henry Feb 12 '19 at 06:26
  • This answer helped a lot: https://stackoverflow.com/a/45514339/6276596 Now, I'm able to publish. Thanks for redirecting me to correct way. – Furkan Yurdakul Feb 12 '19 at 06:40

1 Answers1

0

All your dependencies are declared in the implementation configuration. This means they are not exposed as part of the API of your library. They are not compile time dependencies.

This is going to be reflected in the published Maven POM where they will appear in the Maven runtime scope. And so for consumers, they will only be added to the runtime classpath, not the compile one.

If you want the dependencies of your library to be directly visible on the compile classpath of your consumers, you need to add them to the api configuration instead. As this will cause them to be exposed to the Maven compile scope and visible to the compile classpath of consumers.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43