我为Android应用创建了一个库(SDK),我将在jCenter中发布它。目前,我使用以下gradle
脚本:
apply plugin: 'maven'
def groupId = project.PUBLISH_GROUP_ID
def artifactId = project.PUBLISH_ARTIFACT_ID
def version = project.PUBLISH_VERSION
def localReleaseDest = "${buildDir}/release/${version}"
task androidJavadocs(type: Javadoc) {
failOnError = false
source = android.sourceSets.main.java.srcDirs
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
uploadArchives {
repositories.mavenDeployer {
pom.groupId = groupId
pom.artifactId = artifactId
pom.version = version
// Add other pom properties here if you want (developer details / licenses)
repository(url: "file://${localReleaseDest}")
}
}
task zipRelease(type: Zip) {
from localReleaseDest
destinationDir buildDir
archiveName "release-${version}.zip"
}
task generateRelease {
doLast {
println "Release ${version} can be found at ${localReleaseDest}/"
println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip"
}
}
generateRelease.dependsOn(uploadArchives)
generateRelease.dependsOn(zipRelease)
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
它汇编了一个ZIP
文件,我上传到jCenter并展开此存档。此ZIP
包含mySDK.aar
,mySDK-javadoc.jar
,mySDK-sources.jar
以及其他一些文件,例如.pom
。然后我使用gradle将我的库包含到另一个项目中:
compile 'com.my.company:my-sdk:1.0'
同步后,gradle会下载所有必要的文件,包括包含javadoc评论的sources
文件和SOURCES
!
问题是我不想发布SDK源代码,但仍希望包含javadoc注释。 mySDK.aar
被混淆和编译,AFAIK不能包含任何内容,只能包含代码。我对此问题的看法是创建sources.jar
文件,其中仅包含我的public
函数及其javadoc的定义。也许,我需要编写生成这种JAR的gradle任务,但我不知道如何。虽然,可能有更好的解决方案。
所以,我的问题是如何将javadoc注释(将在鼠标悬停的Android工作室中显示)包含在jCenter
存储库中发布的模糊SDK库中?