[英]How can I add docstrings to android maven-publish .aar files in build.gradle.kts?
I have a project with the standard java library and this creates several .jar
files, one being a docset and another the source set.我有一个带有标准 java 库的项目,这会创建几个
.jar
文件,一个是文档集,另一个是源集。 Now I have successfully created an android-library using themaven-publish plugin, but when I add the .aar
files to another project, they don't contain neither source nor comments as the .jar
version did, so I don't get help inside the IDE or look into the implementation of methods.现在我已经使用maven-publish插件成功创建了一个 android-library,但是当我将
.aar
文件添加到另一个项目时,它们既不包含源代码也不包含注释,因为.jar
版本没有,所以我不明白IDE 里面的帮助或查看方法的实现。
What do I need to add to my build.gradle.kts
to include docstrings and sources in the debug version of the .aar
I'm publishing locally as a file?我需要添加什么到我的
build.gradle.kts
以在我作为文件在本地发布的.aar
的调试版本中包含文档字符串和源? The linked gradle documentation from that Android developer page does not mention anything about docstrings or sources at all.来自 Android 开发人员页面的链接 gradle 文档根本没有提及有关文档字符串或源的任何内容。
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("com.google.android.material:material:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact("androidJavadocsJar") // Doesn't seem to work
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
While I've read about other devs being able to cram the javadocs into the .aar
file, this is not explicitly necessary at all to gain documentation and source code inspection from inside IDEs like Android Studio.虽然我读过其他开发人员能够将 javadocs 塞进
.aar
文件中,但这对于从像 Android Studio 这样的 IDE 内部获取文档和源代码检查来说完全没有必要。 In fact, looking at the way a typical java library works, it creates files like:事实上,看看典型的 java 库的工作方式,它会创建如下文件:
foo-ver.jar
foo-ver-sources.jar
foo-ver-javadoc.jar
The only difference with an Android library would be having these files:与 Android 库的唯一区别是拥有这些文件:
foo-ver.aar
foo-ver-sources.jar
foo-ver-javadoc.jar
Which means that the sources and javadoc jars can still be copied along the .aar
and the IDE will load them.这意味着源代码和 javadoc jars 仍然可以沿
.aar
复制,并且 IDE 将加载它们。 Having said that, the publish example code only creates the .aar
file, looking at other questions like this one I was able to modify the script to create the .aar
plus the two other .jar
packages:话虽如此,发布示例代码仅创建
.aar
文件,查看像这样的其他问题,我能够修改脚本以创建.aar
以及其他两个.jar
包:
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
id("org.jetbrains.dokka") version "0.9.17"
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
//implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("com.google.android.material:material:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
moduleName = rootProject.name
}
val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokka)
dependsOn(tasks.dokka)
}
val sourcesJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles sources JAR"
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}
artifacts {
archives(sourcesJar)
archives(dokkaJar)
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact(sourcesJar)
artifact(dokkaJar)
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
With these modifications the ./gradlew publish
task will generate all files, and despite one of them having .aar
they work the same as .jar
when copied together into another project.通过这些修改,.
./gradlew publish
任务将生成所有文件,尽管其中一个文件具有.aar
,但当它们一起复制到另一个项目中时,它们的工作方式与.jar
相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.