0

I've created an Android library called Library and I want to publish it to a private maven repository and then consume it in an app called App.

I am encountering an issue however which is making the usage of the library untenable for App. The issue is that one of the dependencies of Library is hosted in a "non standard" maven repository, and is forcing the consuming App to add this repository to it's repositories block.

To explain this further; Library has lots of dependencies, most of which are pulled from google and mavenCentral repositories (both of which the consuming App has in the repositories block because all Android apps will include these repositories). However, one of the dependencies, Quikkly, is hosted in a "non standard" maven repository (i.e. one with a non standard URL), which also requires a github personal access token to access. So in my Library repositories block, I have to add this maven repo in order to pull this specific dependency:

maven {
    url 'https://maven.pkg.github.com/quikkly/quikkly-android-sdk'
    credentials {
        username = <github_username>
        password = <github_access_token>
    }
}

All well and good; I can build Library just fine, and the Quikkly dependency is pulled successfully from this repository.

The issue arises when I use Library in App. I published Library to mavenLocal (or my own private maven repository depending on when I'm ready to actually push a release). When I pull Library into App and then build, the build fails because Quikkly could not be resolved.

The errors show that the locations searched were just the repositories defined in App and not those defined in Library. I can make the build succeed if I add the Quikkly custom maven repo (and github access token) to App but I don't want to force App developers to need to add custom repos just to use my library - surely my library should be responsible for properly packaging it's own dependencies such that consumers just need to use my library via a one line gradle import.

I've done some research on this, and I think the solution involves adding the custom maven repository URL to a <server> element in my libraries .pom file, however the repository also requires a github username and personal access token in order to pull the library from it... my research shows that I need to add these details to "somewhere" (but not in the .pom file as this would be insecure and/or wouldn't even work).

I'm now getting pressured to release something working, but I'm pretty stuck with this. Can anyone help?

Thomas Cook
  • 4,371
  • 2
  • 25
  • 42
  • 1
    publishing to Github Packages sucks badly ... do it old way: download aar and jar then add them from lib folder of your project – Selvin Feb 10 '23 at 11:00
  • Grim, I was hoping I wouldn't have to resort to that, feels yucky – Thomas Cook Feb 10 '23 at 11:05
  • 1
    Add Your private dependency with `api` instead of `implementation` via gradle in `dependencies` section. With that thing, You add whole library in another with sources. When You add `implementation`, You have to provide implenetation of Your library by Yourself. – KurdTt- Feb 10 '23 at 11:17
  • Yea I think that could work KurdTt but then I'd be exposing this library to the consuming app which isn't ideal either is it... I don't want the consuming app to use this dependency, so `api` isn't really appropriate. – Thomas Cook Feb 10 '23 at 11:21
  • 1
    So, is what you're looking to do is have it declared as `implementation`, and to "fatten" the jar only a little, by only adding a SINGLE dependency into the final artifact? If so, would something like this solve it for you? https://stackoverflow.com/questions/32146204/how-do-i-include-a-single-dependency-in-my-jar-with-gradle I believe these are your own two options.. Provide the repo, or provide the dependency inside. – User51 Feb 10 '23 at 14:12

0 Answers0