简体   繁体   English

如何使用 JavaDocs 将 AAR 发布到 Maven Local

[英]How do I publish an AAR to Maven Local With JavaDocs

I need to publish my android library (aar) using Gradle to Maven local repo.我需要使用 Gradle 将我的 android 库 (aar) 发布到 Maven 本地仓库。 But the publication script needs to also generate the Javadocs, while ONLY including Public and Protected methods and classes.但是发布脚本还需要生成 Javadocs,而只包括公共和受保护的方法和类。

Can't seem to find any information online, especially about the Javadocs part... Help, I never published a library before.似乎无法在网上找到任何信息,尤其是关于 Javadocs 部分的信息...帮助,我以前从未发布过库。

Ok, after much research I found a solution, so I'm going to share it here if anyone will need this.好的,经过大量研究,我找到了解决方案,所以如果有人需要,我将在这里分享。
(I don't want you to be frustrated like I was). (我不希望你像我一样感到沮丧)。

1) Create an android library as a new module inside your project. 1) 在项目中创建一个 android 库作为新模块。

2) Inside the build gradle of your library place this code: 2) 在您的库的构建 gradle 中放置以下代码:

plugins {
    id 'com.android.library'
    id 'maven-publish'
}

android {
   nothing special here...
}

This is the code for creating the Javadocs(still inside build.gradle):这是创建 Javadocs 的代码(仍在 build.gradle 中):

task androidJavadocs(type: Javadoc){
    source = android.sourceSets.main.java.srcDirs

    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    android.libraryVariants.all{ variant->
        if (variant.name == 'release'){
            owner.classpath += variant.javaCompileProvider.get().classpath
        }
    }
    // excluding a specific class from being documented
    exclude '**/NameOfClassToExclude.java'

    title = null

    options{
        doclet = "com.google.doclava.Doclava"
        docletpath = [file("libs/doclava-1.0.6.jar")]
        noTimestamp = false

        // show only Protected & Public
        memberLevel = JavadocMemberLevel.PROTECTED
    }

}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs){
    archiveClassifier.set('javadoc')
    from androidJavadocs.destinationDir
}


task androidSourcesJar(type: Jar){
    archiveClassifier.set('sources')
    from android.sourceSets.main.java.srcDirs
}

This is to publish the library to MavenLocal(still inside build.gradle):这是将库发布到 MavenLocal(仍在 build.gradle 中):

   afterEvaluate {
        publishing{
            publications{
                release(MavenPublication){
                    groupId = "com.example.mylibrary"
                    artifactId = "mycoollibrary"
                    version = "1.0"
                    // Applies the component for the release build variant
                    from components.release
                    // Adds javadocs and sources as separate jars.
                    artifact androidSourcesJar
                    artifact androidJavadocsJar
                }
            }
        }
    }

Your default dependencies block:您的默认依赖项块:

dependencies {
       your dependencies...
    }

3) Now you can download the doclava doclet : 3) 现在您可以下载doclava doclet
Extract the zip, copy the doclava-1.0.6.jar and paste it into your LibraryName/libs folder (can be found using the project view).提取 zip,复制 doclava-1.0.6.jar 并将其粘贴到 LibraryName/libs 文件夹中(可以使用项目视图找到)。 You only need doclava if you want to be able to use @hide.如果你想能够使用@hide,你只需要 doclava。 With this annotation, you can exclude specific methods from your Javadocs.使用此注释,您可以从 Javadocs 中排除特定方法。

4) Build and publish your library: Find the gradle tab at the top right side of android studio, or find it from the toolbar View->Tool Windows->Gradle. 4) 构建和发布你的库:在 android studio 右上角找到 gradle 选项卡,或从工具栏 View->Tool Windows->Gradle 中找到它。
Now find your library -> tasks -> publishing -> publishReleasePublicationToMavenLocal.现在找到你的库 -> 任务 -> 发布 -> publishReleasePublicationToMavenLocal。

5) To consume the library from another project: Go to the settings.gradle file (of the consuming project) and add MavenLocal() as the first repository in the the dependencyResolutionManagement block. 5)从另一个项目使用库: Go 到 settings.gradle 文件(消费项目)并添加 MavenLocal() 作为dependencyResolutionManagement块中的第一个存储库。
And inside the module build gradle add your library as a dependency:在模块内部构建 gradle 将您的库添加为依赖项:

dependencies{
    implementation 'com.example.mylibrary:mycoollibrary:1.0'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM