Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gradle with external javadoc
plugins {
id 'java'
}
repositories {
jcenter()
}
dependencies {
compile 'com.google.guava:guava:23.0'
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'ch.qos.logback:logback-classic:1.2.3'
testCompile 'junit:junit:4.12'
}
javadoc {
options.charSet = 'UTF-8'
options.encoding = 'UTF-8'
options.docEncoding = 'UTF-8'
options.use = true
options.links += [jvmToJavadoc(project.targetCompatibility)] + javadocFromDependencies(project.configurations.compile)
}
// Go through all the artifacts and find javadoc for it...
def List<String> javadocFromDependencies(Configuration config) {
List<String> javadocs = []
config.dependencies.each { dep ->
javadocs.add(artifactToJavadoc(dep.group, dep.name, dep.version))
}
javadocs
}
def String jvmToJavadoc(JavaVersion jvmVersion) {
if (jvmVersion.java8) {
'https://docs.oracle.com/javase/8/docs/api/'
} else if (jvmVersion.java9) {
'https://docs.oracle.com/javase/9/docs/api/'
}else if (jvmVersion.java10) {
'https://docs.oracle.com/javase/10/docs/api/'
}else if (jvmVersion.java11) {
'https://docs.oracle.com/en/java/javase/11/docs/api/'
}
}
def String artifactToJavadoc(String organization, String name, String apiVersion) {
String slashedOrg = organization.replace('.', '/')
"https://oss.sonatype.org/service/local/repositories/releases/archive/$slashedOrg/$name/$apiVersion/$name-$apiVersion-javadoc.jar/!/"
}
task externalJavadocLinks {
doLast {
javadocFromDependencies(project.configurations.compile).each { dep ->
println dep
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment