使用 aar 和源 jar 将 Android 库发布到 Maven
问题描述:
有人可以给我一个关于如何使用 maven-publish
gradle 插件发布带有 aar 和源 jar 的 com.android.library
项目/模块的提示吗?我可以使用旧的 maven 插件来做到这一点 - 但我想使用新的 maven-publish
插件.
Can somebody give me a hint on how to use the maven-publish
gradle plugin to publish a com.android.library
project/module with aar and source jar? I am able to do this with the old maven plugin - but I would like to use the new maven-publish
plugin.
答
这是使用新的 maven-publish
插件的示例.
Here's a sample using the new maven-publish
plugin.
apply plugin: 'maven-publish'
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
publishing {
publications {
bar(MavenPublication) {
groupId 'com.foo'
artifactId 'bar'
version '0.1'
artifact(sourceJar)
artifact("$buildDir/outputs/aar/bar-release.aar")
}
}
repositories {
maven {
url "$buildDir/repo"
}
}
}
使用 发布./gradlew clean build 发布