Working on an Android library with Gradle (v 1.7) as the building tool, I've used the maven plugin and configured the task uploadArchives to publish both release and debug version of the lib to the local maven repository.
The code below works ok :
// [...]
apply plugin: 'android-library'
// [...] nothing unusual
/*
* Define name of the apk output file (build/apk/<outputFile>)
*/
android.libraryVariants.all
{
variant ->
def outputName = "MyModule-${android.defaultConfig.versionName}-${variant.baseName}.aar"
variant.outputFile = new File("$buildDir/libs", outputName)
}
/*
* Publish to maven local repo (older style maven plugin)
* Used while android plugin is not fixed regarding maven-publish plugin
*
* type command "gradle uploadArchives" to publish the module into the
* local .m2 repository
*/
apply plugin: 'maven'
android.libraryVariants.all
{
variant ->
// add final apk to the 'archives' configuration
project.artifacts
{
archives variant.outputFile
}
}
def localRepoPath = "file://" + new File(
System.getProperty("user.home"), ".m2/repository").absolutePath
uploadArchives
{
repositories.mavenDeployer
{
repository(url: localRepoPath)
addFilter('debug') { artifact, file ->
artifact.name.contains("debug")
}
addFilter('release') { artifact, file ->
artifact.name.contains("release")
}
pom('debug').groupId = 'com.company'
pom('release').groupId = 'com.company'
pom('debug').artifactId = 'id'
pom('release').artifactId = 'id'
pom('debug').version = android.defaultConfig.versionName + "d"
pom('release').version = android.defaultConfig.versionName
pom.packaging = 'aar'
}
}
uploadArchives.dependsOn(assemble)
However, when trying to refactor the pom configuration :
uploadArchives
{
repositories.mavenDeployer
{
repository(url: localRepoPath)
addFilter('debug') { artifact, file ->
artifact.name.contains("debug")
}
addFilter('release') { artifact, file ->
artifact.name.contains("release")
}
pom.groupId = 'com.company'
pom.artifactId = 'id'
pom('debug').version = android.defaultConfig.versionName + "d"
pom('release').version = android.defaultConfig.versionName
pom.packaging = 'aar'
}
}
artifactId is expanded as the name of the output file, and groupId as the name of the root directory ; thus giving bad paths in the maven repo.
I'd like to know why is that, and maybe if there is a cleaner way to achieve what I need.
.aar
. Therefore, I set thearchivesBaseName
inbuild.gradle
which is used for theartifactId
. Maybe this helps. – JJD