在使用 Gradle (v 1.7) 作为构建工具的 Android 库上工作时,我使用了 maven 插件并配置了任务 uploadArchives 以将 lib 的发布和调试版本发布到本地 maven 存储库。
下面的代码工作正常:
// [...]
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)
但是,当尝试重构 pom 配置时:
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扩展为输出文件名,groupId扩展为根目录名;从而在 maven repo 中给出了不好的路径。
我想知道为什么会这样,也许是否有更清洁的方法来实现我所需要的。