dokka实现

1、app项目下的build.gradle 的dependencies下添加

classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.8.10'

2、settings.gradle 的repositories添加

mavenLocal()
mavenCentral()

3、将库下面的build.gradle改成build.gradle.kts

4、将build.gradle.kts的plugins添加

id("org.jetbrains.dokka")

5、修改build.gradle.k

plugins {
    id("com.android.library")
    id("kotlin-android")
    id("kotlin-kapt")
    id("org.jetbrains.dokka")
}
android {
    compileSdk = 32

    defaultConfig {
        minSdk = 28
        targetSdk = 32
		
		manifestPlaceholders["DATA_SERVICE_PACKAGE_NAME"] = "com.example.test"

    }

    buildTypes {
        debug {
            isMinifyEnabled = false
        }

        release {
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

    buildFeatures {
        viewBinding = true
    }
}

dependencies {
    implementation ("androidx.core:core-ktx:1.8.0")
    implementation ("androidx.activity:activity-ktx:1.5.1")
    implementation ("androidx.fragment:fragment-ktx:1.5.1")
}

tasks.dokkaHtml.configure {
    // 导出的文档目录路径library是库名称
    outputDirectory.set(File(rootDir, "library/doc/dokkaHtml"))
    dokkaSourceSets {
        named("main") {
            noAndroidSdkLink.set(true)
            noStdlibLink.set(true)
            noJdkLink.set(true)
        }

        configureEach {
            // 排除不包含在api文档中的目录
            val list = listOf(
                """com.example.*""",
                """com.example.aa.*""",
            )
            list.forEach { pkg ->
                perPackageOption {
                    matchingRegex.set(pkg)
                    suppress.set(true)
                }
            }
        }
    }

}

tasks.register("dokkaHtmlJar") {
    dependsOn(tasks.dokkaHtml)
    from(tasks.dokkaHtml.flatMap { it.outputDirectory })
    archiveClassifier.set("docs-1.0.0")
    archiveBaseName.set("test-library")

    copy {
        from(outputs)
        into("doc")
    }
}.configure {
    group = "documentation"
}

6、详细可以看文档

Kotlin 多平台 · Kotlin 官方文档 中文版

你可能感兴趣的:(java,android,开发语言)