I've run into an issue while using the maven-publish
plugin for this Android library I'm developing. I've looked at similar posts on SO and other forums as well, and my issue is still persisting.
scenario:
I have
Library A
which includes the core of the library,Library B
which is a wrapper aroundLibrary A
. SoB
depends onA
.B
also has several other dependencies on its own.
issue:
I need to be able to include only
Library B
and have all the required (api/compile) transient dependencies be downloaded along with it.
what i've tried:
(1) I read up here on how Gradle populates the generated
pom.xml
file with the dependencies required by looking at the dependencies you've declared in thedependencies {}
block. api means the dependency should be transient and implementation hides it (prevents leakage). So I went ahead and applied the changes needed toLibrary B
's gradle.build and marked all the dependencies I wanted with api. This did not work and the generatedpom.xml
still did not contain the transient deps.
(2) I've followed the steps here and thought it's now generating the
pom.xml
with all the dependencies, after publishing it to mavenLocal and attempting to consume it in a fresh Demo app the project is building but it crashes as soon as it attempts to run (due to the missing dependencies).
code:
pom.withXml {
// for dependencies and exclusions
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.api.allDependencies.each { dp ->
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dp.group)
dependencyNode.appendNode('artifactId', dp.name)
dependencyNode.appendNode('version', dp.version)
// for exclusions
if (dp.excludeRules.size() > 0) {
def exclusions = dependencyNode.appendNode('exclusions')
dp.excludeRules.each { ExcludeRule ex ->
def exclusion = exclusions.appendNode('exclusion')
exclusion.appendNode('groupId', ex.group)
exclusion.appendNode('artifactId', ex.module)
}
}
}
}
The only way I've gotten it to work so far was by also adding all the other deps on top of Library B
(needless to say this is not ideal...)
QUESTION: How can I achieve what I need while only adding this one library?