如何在Javadoc警告上失败gradle构建 [英] How to fail gradle build on Javadoc warnings

查看:159
本文介绍了如何在Javadoc警告上失败gradle构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Java 7(尽管使用1.6编译)来编译类和javadoc。我已经消除了所有出现的javadoc警告,但是如果存在任何javadoc警告,则构建失败。

使用Java 8,这是缺省值行为。但是,当涉及到警告时,它也更加严格(如果方法没有列出所有的@params或@returns,我们不需要警告)。另外,我没有看到公司很快就会搬迁到8家,所以这是一个有争议的问题。



我希望有一些简单的标志可以让石化失败如果有警告(只有failonError)。我在想的是抓取javadoc进程的控制台输出。如果输出包含WARNINGS,那么我知道有警告,并且构建应该失败。



这是我的build.gradle中的javadoc块:

 任务gendocs(类型:Javadoc){
options.stylesheetFile = new File(./ assets / doc_style.css)
options.windowTitle =OurTitle
options.memberLevel = JavadocMemberLevel.PROTECTED
options.author = true
options.linksOffline('http://d.android.com/reference', System.getenv(ANDROID_HOME)+'/ docs / reference')
String v =$ {SEMVER}
version = v.replace(_,'。')
destinationDir = new File($ {BUNDLE_FOLDER} / docs / api)
source = sourceSets.main.allJava
classpath + = configurations.compile
}

因此,如果没有更简单的方法来做到这一点,我该如何检查javadoc的控制台输出来抓取它? / p>

解决方案

注意:我完全取代了原来的答案,因为我找到了一个赌注第一个 - 这不是那么难看:

  import org.gradle.logging.internal.OutputEvent 
导入组织。 gradle.logging.internal.OutputEventListener

任务(javadocCheck,类型:Javadoc){
//常规javadoc任务配置

def outputEvents = []
def listener = new OutputEventListener(){
void onOutput(OutputEvent event){
outputEvents<<事件
}
};
doFirst {
getLogging()。addOutputEventListener(listener)
}
doLast {
getLogging()。removeOutputEventListener(listener)
outputEvents.each {e - >
if(e.toString()=〜warning:){
抛出新的GradleException(你有一些javadoc警告,请修复它们!
}
}
}
}


I'm using Java 7 (though compiliing using 1.6) to compile classes, and the javadocs. I've eliminated all javadoc warnings which come up, but the idea is to have the build fail if there are any javadoc warnings.

Using Java 8, this is the default behaviour. BUT, it's also a lot more strict when it comes to warnings (we don't want warnings if a method doesn't list all @params, or @returns). Plus, I don't see the company moving to 8 anytime soon, so it's a moot point.

I was hoping there was some easy flag to set to have gradle fail if there are warnings (there's only failonError). What I was thinking, was to scrape the console output of the javadoc process. If that output contains WARNINGS, then I know there are warnings, and the build should fail.

Here's my javadoc block in my build.gradle:

task gendocs(type: Javadoc) {
options.stylesheetFile = new File("./assets/doc_style.css")
options.windowTitle = "OurTitle"
options.memberLevel = JavadocMemberLevel.PROTECTED
options.author = true
options.linksOffline('http://d.android.com/reference', System.getenv("ANDROID_HOME") + '/docs/reference')
String v = "${SEMVER}"
version = v.replace("_", '.')
destinationDir = new File("${BUNDLE_FOLDER}/docs/api")
source = sourceSets.main.allJava
classpath += configurations.compile
}

So, if there isn't an easier way to do this, how do I check the console output of javadoc to scrape it?

解决方案

note: i've totally replaced my original answer, because i've found a better one - which is not that ugly:

import org.gradle.logging.internal.OutputEvent
import org.gradle.logging.internal.OutputEventListener

        task("javadocCheck",type:Javadoc){
            // regular javadoc task configuration

            def outputEvents = []
            def listener=new OutputEventListener(){
                    void onOutput(OutputEvent event){
                        outputEvents << event
                    }
                };
            doFirst {
                getLogging().addOutputEventListener(listener)
            }
            doLast {
                getLogging().removeOutputEventListener(listener)
                outputEvents.each { e ->
                    if(e.toString() =~ " warning: "){
                        throw new GradleException("You have some javadoc warnings, please fix them!");
                    }
                }
            }
        }

这篇关于如何在Javadoc警告上失败gradle构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆