Skip to content

Commit cb2f39f

Browse files
committed
Use latest Java toolchain and simplify Javadoc generation now that the javadoc tool can properly link to older docs
* https://bugs.openjdk.org/browse/JDK-8216497 * https://bugs.openjdk.org/browse/JDK-8297437
1 parent 2773f83 commit cb2f39f

File tree

2 files changed

+9
-69
lines changed

2 files changed

+9
-69
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The plugin adds an extension named `applications` to the project, which is a con
4848
// build.gradle
4949
5050
plugins {
51-
id "com.ms.gradle.application" version "2.0.2"
51+
id "com.ms.gradle.application" version "2.0.3"
5252
}
5353
5454
applications.main {
@@ -64,7 +64,7 @@ For more complex examples, see the [build file of the plugin's functional test](
6464
// build.gradle.kts
6565

6666
plugins {
67-
id("com.ms.gradle.application").version("2.0.2")
67+
id("com.ms.gradle.application").version("2.0.3")
6868
}
6969

7070
applications.main {

build.gradle.kts

Lines changed: 7 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException
1313
import org.eclipse.jgit.lib.Constants
1414
import org.eclipse.jgit.lib.RepositoryBuilder
1515
import java.io.Serializable
16-
import java.net.HttpURLConnection
17-
import java.net.URI
1816
import java.nio.channels.FileChannel
1917
import java.nio.file.Files
2018
import java.nio.file.StandardOpenOption
@@ -45,7 +43,7 @@ plugins {
4543
}
4644

4745
group = "com.ms.gradle"
48-
version = "2.0.2"
46+
version = "2.0.3"
4947

5048
val pluginId = "com.ms.gradle.application"
5149
val pluginClass = "com.ms.gradle.application.ApplicationPlugin"
@@ -65,7 +63,7 @@ val productUrl = "https://github.com/morganstanley/gradle-plugin-application"
6563
val supportedJavaVersions = sortedSetOf(
6664
JavaVersion.VERSION_1_8, JavaVersion.VERSION_11, JavaVersion.VERSION_17, JavaVersion.VERSION_21)
6765
val sourceJavaVersion = supportedJavaVersions.minOf { it }
68-
val toolsJavaVersion = JavaVersion.VERSION_11
66+
val toolsJavaVersion = supportedJavaVersions.maxOf { it }
6967

7068
fun toolchainSpec(javaVersion: JavaVersion) = { toolchain: JavaToolchainSpec ->
7169
toolchain.vendor.set(JvmVendorSpec.AZUL)
@@ -148,71 +146,13 @@ tasks.javadoc {
148146
memberLevel = JavadocMemberLevel.PUBLIC
149147
// See: https://github.com/gradle/gradle/issues/18274
150148
addStringOption("-release", sourceJavaVersion.majorVersion)
149+
links("https://docs.gradle.org/${GradleVersion.current().baseVersion.version}/javadoc/")
151150
}
152-
153-
// Javadoc in Java 9+ requires this `linkoffline` workaround to be able to link to Java 8 docs
154-
// In case of a package overlap (e.g. `javax.annotation`), the last offline link takes precedence
155-
// To have control over the situation, we have to use offline links for every dependency
156151
doFirst {
157-
val linksDir = temporaryDir.resolve("links")
158-
delete(linksDir.toPath())
159-
Files.createDirectories(linksDir.toPath())
160-
161-
data class OfflineLink(val dir: File, val uri: URI)
162-
val descriptorFileNames = listOf("element-list", "package-list")
163-
164-
// For built-in dependencies, download Javadoc descriptors manually from the URI
165-
val linksForBuiltIns = listOf(
166-
OfflineLink(linksDir.resolve("java"),
167-
uri("https://docs.oracle.com/javase/${sourceJavaVersion.majorVersion}/docs/api/")),
168-
OfflineLink(linksDir.resolve("gradle"),
169-
uri("https://docs.gradle.org/${GradleVersion.current().baseVersion.version}/javadoc/")),
170-
).onEach { offlineLink ->
171-
val javadocDescriptor = descriptorFileNames.mapNotNull { fileName ->
172-
with(offlineLink.uri.resolve(fileName).toURL().openConnection() as HttpURLConnection) {
173-
instanceFollowRedirects = false
174-
inputStream.use { content ->
175-
responseCode.takeIf { it == 200 }?.let {
176-
Files.createDirectories(offlineLink.dir.toPath())
177-
offlineLink.dir.resolve(fileName).apply {
178-
Files.copy(content, toPath())
179-
}
180-
}
181-
}
182-
}
183-
}.firstOrNull()
184-
checkNotNull(javadocDescriptor) { "Could not download Javadoc descriptor from ${offlineLink.uri}" }
185-
}
186-
187-
// For external modules, extract Javadoc descriptors from the module's Javadoc JAR
188-
val linksForModules = run {
189-
val compileComponents = configurations.compileClasspath.get().incoming.resolutionResult.allComponents
190-
val compileJavadocs = dependencies.createArtifactResolutionQuery()
191-
.forComponents(compileComponents.map { it.id })
192-
.withArtifacts(JvmLibrary::class, JavadocArtifact::class)
193-
.execute()
194-
compileJavadocs.resolvedComponents.mapNotNull { component ->
195-
val javadocArtifact =
196-
component.getArtifacts(JavadocArtifact::class).singleOrNull() as ResolvedArtifactResult?
197-
val javadocDescriptor = javadocArtifact?.let { artifact ->
198-
val javadocJarTree = zipTree(artifact.file)
199-
descriptorFileNames.firstNotNullOfOrNull { fileName ->
200-
javadocJarTree.matching { include(fileName) }.singleOrNull()
201-
}
202-
}
203-
javadocDescriptor?.let { file ->
204-
val id = component.id as ModuleComponentIdentifier
205-
OfflineLink(file.parentFile, uri("https://javadoc.io/doc/${id.group}/${id.module}/${id.version}/"))
206-
}
207-
}
208-
}
209-
210-
// Add offline links
211-
linksForBuiltIns.plus(linksForModules).forEach { offlineLink ->
212-
fullOptions.linksOffline(offlineLink.uri.toString(), offlineLink.dir.path)
213-
}
214-
// Generate correct deep links to Java 8 and Gradle methods (HTML5: `#toString()`, HTML4: `#toString--`)
215-
fullOptions.addBooleanOption("html4", true)
152+
// `compileClasspath` is already an input via `Javadoc.classpath` (see `JvmPluginsHelper.configureJavaDocTask`)
153+
configurations.compileClasspath.get().incoming.resolutionResult.allComponents
154+
.mapNotNull { it.id as? ModuleComponentIdentifier }
155+
.forEach { fullOptions.links("https://javadoc.io/doc/${it.group}/${it.module}/${it.version}/") }
216156
}
217157
}
218158

0 commit comments

Comments
 (0)