Home > OS >  How to set the repository my library depends into the artifact?
How to set the repository my library depends into the artifact?

Time:07-26

I've a Android library that generates an artifact. This library have some dependencies in itself that are resolved from jitpack, but currently, if the user of the library don't add jitpack to their dependency repoisitories my library will fail to resolve.

How can I add to my artifact the repositories it depends so the user that uses my library don't have to add jitpack to their dependencies?

This is the current code I use for publishing:

afterEvaluate {
    publishing {
        repositories {
            maven {
                Properties properties = new Properties()
                if (project.rootProject.file('local.properties').canRead()) {
                    properties.load(project.rootProject.file("local.properties").newDataInputStream())
                }
                name = "GitHub"
                description = "PROJECT NAME"
                url = uri("PROJECT PRIVATE REPO URL")
                credentials {
                    username = properties.getProperty("REPO_PACKAGES_USERNAME") ?: System.getenv("REPO_PACKAGES_USERNAME")
                    password = properties.getProperty("REPO_PACKAGES_TOKEN") ?: System.getenv("REPO_PACKAGES_TOKEN")
                }
            }
        }
        components.all((component) -> {
            def componentName = component.getName()
            println("componentName: ${componentName}")
            def isDebug = componentName == "debug"
            publishing.publications.create("publication-$componentName", MavenPublication) {
                from component
                groupId = "com.foo.bar"
                version = "${android.defaultConfig.versionName}${isDebug ? '-DEBUG' : ''}"
            }
        })
    }
}

CodePudding user response:

You can't control the repositories of your consumers, as this would be a security vulnerability.

The best thing to do would be to publish your library to maven central, as this repository is almost universally used for Java dependencies.

  • Related