Javadoc fail on warning


(Levon Saldamli) #1

There doesn’t seem to be any option for the javadoc task to fail on warnings. Would it be possible to add a flag for this?

There was a workaround using import org.gradle.logging.internal.OutputEventListener that checked for warnings in the output but that broke after an upgrade to Gradle 2.14 (I’m aware of the internal part of the package name).


(Levon Saldamli) #2

I’ve found that the class has moved to org.gradle.internal.logging.events and updated the imports, which works but it is still bad to depend on internal stuff. Will there be a publicly available way to do this kind of thing? I.e. doing this without depending on internal classes:

import org.gradle.internal.logging.events.OutputEvent
import org.gradle.internal.logging.events.OutputEventListener
import org.gradle.internal.logging.LoggingOutputInternal
tasks.withType(Javadoc) {
    def exceptions = []
    doFirst {
        gradle.services.get(LoggingOutputInternal).addOutputEventListener(new OutputEventListener() {
            void onOutput(OutputEvent event) {
                if (event.toString() =~ " warning: ") {
                    exceptions << new GradleException("Javadoc warning: ${event.toString()}")
                }
            }
        })
    }
    doLast {
        exceptions.each {
            throw it
        }
    }
}

(Oliver Lockwood) #3

Seconded, I think this would be a great feature to have.


(Florian Schmaus) #4

Taken from my stackoverflow answer:

There is a non-standard hidden javadoc option -Xwerror available on all supported Java releases. Thus you could simply do something like this:

if (JavaVersion.current().isJava8Compatible()) {
	tasks.withType(Javadoc) {
		// The '-quiet' as second argument is actually a hack,
		// since the one paramater addStringOption doesn't seem to
		// work, we extra add '-quiet', which is added anyway by
		// gradle. See https://github.com/gradle/gradle/issues/2354
        // See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363)
        // for information about the -Xwerror option.
		options.addStringOption('Xwerror', '-quiet')
	}
}

A feature request for an official ‘-Werror’ for javadoc is tracked as JDK-8200363.