简体   繁体   中英

Can't find the Transitive Dependency using maven publication

I have checked multiple questions and have checked the answers as well but those are not working for me.

LibraryA -> LibraryB -> App

I want to access the classes of LibraryA from my App and I have added LibraryA in LibraryB and LibraryB is implemented in my App .

api("com.xyz.abc:LibraryA:1.0.0")

I am using the api keyword to add the dependency in LibraryB and both the libraries are published on maven and then I have implemented the LibraryB in my app using implementation keyword and keeping the transitive as true .

implementation("com.xyz.abc:LibraryB:1.0.0"){
    transitive = true
}

After doing all this, when I try to access a class from LibraryA, it gives an error Unresolved Reference . But If I try to do the same thing by adding the LibraryB as a module then all works fine.

Please let me know, what else should I change to make it work for me. Thanks in Advance!!

I was able to resolve the transitive dependency issue by a small modification. After reading at multiple Stackoverflow questions, I found same thing mentioned everywhere that the dependency should be present in the pom.xml file. But for me it was not getting added, even after using api to include the dependency the App was not able to access it. I as adding the dependency in pom file using below code:

withXml {
    asNode().appendNode("dependencies").let {
        for (dependency in configurations["implementation"].dependencies) {
            it.appendNode("dependency").apply {
                appendNode("groupId", dependency.group)
                appendNode("artifactId", dependency.name)
                appendNode("version", dependency.version)
            }
        }
    }
}

This was adding only the dependencies that are included using the implementation keyword but after adding the below code as well I was able to access the transitive dependency.

withXml {
    asNode().appendNode("dependencies").let {
        for (dependency in configurations["api"].dependencies) {
            it.appendNode("dependency").apply {
                appendNode("groupId", dependency.group)
                appendNode("artifactId", dependency.name)
                appendNode("version", dependency.version)
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM