如何使用Gradle将多个Javadoc合并为一个

huangapple go评论70阅读模式
英文:

How to combine multiple Javadoc into one using Gradle

问题

这个问题之前已经有答案,但所选择的答案对我来说并没有详细解释如何在Gradle上实现这一点。

还有一个问题是,我无法评论解决方案以请求更多信息,所以我不得不提出这个问题。

我有一个Gradle项目,其中有几个可用的模块,现在我想设置Javadoc任务,将所有模块的Javadoc注释合并到一个单独的位置,以便浏览它。如何使用Gradle实现这一点?如果版本很重要,我使用Gradle 5.5,并且在build.gradle文件中设置了以下内容:

allprojects {
    ext {
        // 用于配置Javadoc的便捷方法
        configureJavadoc = { Object jDocConfig ->
            jDocConfig.options {
                it.author()
                it.encoding = 'UTF-8'
                it.memberLevel = JavadocMemberLevel.PROTECTED

                if (it instanceof StandardJavadocDocletOptions) {
                    def opt = it as StandardJavadocDocletOptions

                    opt.links(
                            "https://docs.example.com/java/"
                    )

                    if (JavaVersion.current().isJava9Compatible()) {
                        opt.addBooleanOption("html5", true)
                        opt.addStringOption("-release", "8")
                    }

                    if (JavaVersion.current().isJava11Compatible()) {
                        opt.addBooleanOption("-no-module-directories", true)
                    }
                }
            }
        }
    }
}

subprojects {
    javadoc {
        destinationDir = file("$rootDir/docs/")
        
        configureJavadoc(it)
    }
}

希望这可以帮助你设置Gradle项目的Javadoc任务以合并模块的Javadoc注释到一个单独的位置。

英文:

This question was answered before but the chosen answer doesn't explain a lot for me on how this is doable on Gradle.

That and the fact that I can't comment on the solution to ask for more info forced me to make this question.

I have a Gradle project that has several modules available and I now want to set up the Javadoc task to combine the Javadoc comments of all the modules into a single location where I could browse it.
How would I now be able to do this using Gradle? I run Gradle 5.5 if the version is of any importance and I have the following things set in the build.gradle file:

allprojects {
    ext {
        // Convenience method to configure Javadoc
        configureJavadoc = { Object jDocConfig ->
            jDocConfig.options {
                it.author()
                it.encoding = 'UTF-8'
                it.memberLevel = JavadocMemberLevel.PROTECTED

                if (it instanceof StandardJavadocDocletOptions) {
                    def opt = it as StandardJavadocDocletOptions

                    opt.links(
                            "https://docs.example.com/java/"
                    )

                    if (JavaVersion.current().isJava9Compatible()) {
                        opt.addBooleanOption("html5", true)
                        opt.addStringOption("-release", "8")
                    }

                    if (JavaVersion.current().isJava11Compatible()) {
                        opt.addBooleanOption("-no-module-directories", true)
                    }
                }
            }
        }
    }
}

subprojects {
    javadoc {
        destinationDir = file("$rootDir/docs/")
        
        configureJavadoc(it)
    }
}

答案1

得分: 2

I was able to do it with:

def exportedProjects = [
    ":",
    ":module-a",
    ":module-b",
    ":module-c"
]

task allJavadoc(type: Javadoc) {
    source exportedProjects.collect { project(it).sourceSets.main.allJava }
    classpath = files(exportedProjects.collect { project(it).sourceSets.main.compileClasspath })
    destinationDir = file("${buildDir}/docs/javadoc-all")
}
英文:

I was able to do it with:

def exportedProjects = [
		":",
		":module-a",
		":module-b",
		":module-c"
]

task allJavadoc(type: Javadoc) {
	source exportedProjects.collect { project(it).sourceSets.main.allJava }
	classpath = files(exportedProjects.collect { project(it).sourceSets.main.compileClasspath })
	destinationDir = file("${buildDir}/docs/javadoc-all")
}

huangapple
  • 本文由 发表于 2020年8月6日 23:48:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63287292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定