如何将javadoc jar收集到一个zip文件中

时间:2017-02-14 07:43:22

标签: gradle

对于多项目Gradle项目,foo,bar和baz。我正在尝试创建一个任务,创建一个包含库和javadoc的zip文件,即foo.jar,AND foo-javadoc.jar ..

./build.gradle
./settings.gradle
./foo/build.gradle
./bar/build.gradle
./baz/build.gradle

settings.gradle

include ":foo"
include ":bar"
include ":baz"

顶级构建

allprojects {
    apply plugin: 'java'

    task generateJavadoc (type : Javadoc) {
        source = sourceSets.main.allJava  
        classpath = sourceSets.main.compileClasspath
        failOnError = false             
    }
    task javadocJar(type: Jar, dependsOn: generateJavadoc) {
        classifier = 'javadoc'
        from generateJavadoc.destinationDir                     
    }   
    artifacts {
        archives javadocJar     
    }

}

task buildZip(type: Zip, dependsOn: build) {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from (project(':foo').configurations.runtime) {
        into 'jars'
    }
    from (project (':foo').configurations.archives.all) {
        into 'jars'
    }
}

当我使用gradle clean buildZip调用此文件时,会创建一个zip文件,但是没有任何我想要的-javadoc JAR ... JavaDoc jar生成到项目构建目录中,例如: foo / build / lib / foo-javadoc.jar我尝试了project (':foo').artifacts等的多种组合。

1 个答案:

答案 0 :(得分:0)

使用以下方法可以实现。注意javadocJarallprojects

中定义的任务的名称
from (rootProject.allprojects.javadocJar.outputs) {
    into 'javadoc'
}