Reputation: 75
I'm trying to publish an aar locally to /.m2
directory using the maven-publish
Gradle plugin. With the below code, I can publish the release
version (with PTML), but not the debug
one.
I would like to publish either a release
or a debug
one with custom tasks or through command line. Any help is greatly appreciated.
publishing {
publications {
aar(MavenPublication) {
groupId 'com.sample.project'
artifactId 'SampleProject'
version '1.1.0'
artifact bundleReleaseAar
}
}
}
Upvotes: 1
Views: 3643
Reputation: 3434
You have to create a new publication for each of your buildTypes
.
Currently you have only one publication named library
which uses as the output from the bundleReleaseAar
task as artifact.
When you want to publish the debug
version you have to use the output from the bundleDebugAar
task.
Therefore you need something like this:
project.afterEvaluate {
publishing {
publications {
libraryRelease(MavenPublication) {
artifact bundleReleaseAar
artifact sourceJar
groupId 'com.sample.project'
artifactId 'DummyProject'
version '1.0'
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def dependencies = new ArrayList<Dependency>()
dependencies.addAll(configurations.api.allDependencies)
dependencies.addAll(configurations.implementation.allDependencies)
dependencies.each {
if (it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
libraryDebug(MavenPublication) {
artifact bundleDebugAar
artifact sourceJar
groupId 'com.sample.project'
artifactId 'DummyProject'
version '1.0'
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def dependencies = new ArrayList<Dependency>()
dependencies.addAll(configurations.api.allDependencies)
dependencies.addAll(configurations.implementation.allDependencies)
dependencies.each {
if (it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
}
This will create two tasks publishLibraryReleaseToLocalMaven
and publishLibraryDebugToLocalMaven
. You can one run them depending on which type you want to publish.
Upvotes: 6