使用Gradle(v 1.7)作为构建工具处理Android库时,我使用了maven插件并配置了任务uploadArchives以发布发行版和调试版lib到本地的maven仓库。
下面的代码工作正常:Gradle和Android:包含多个Maven构件的pom配置出版物
// [...]
apply plugin: 'android-library'
// [...] nothing unusual
/*
* Define name of the apk output file (build/apk/)
*/
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回购提供了不好的途径。
我想知道这是为什么,也许如果有一个更清晰的方式来实现我所需要的。
2013-08-23
mklj
+0
在我的项目中,我需要重命名输出'.aar'。因此,我在用于'artifactId'的'build.gradle'中设置了'archivesBaseName'。也许这有帮助。 –
+0
你有想过吗? –
+0
@YuchenZhong不幸的是,这项工作是短期实习的一部分。我不知道谁负责这个项目,因此从那以后如何处理。 –