@@ -13,8 +13,6 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException
1313import org.eclipse.jgit.lib.Constants
1414import org.eclipse.jgit.lib.RepositoryBuilder
1515import java.io.Serializable
16- import java.net.HttpURLConnection
17- import java.net.URI
1816import java.nio.channels.FileChannel
1917import java.nio.file.Files
2018import java.nio.file.StandardOpenOption
@@ -45,7 +43,7 @@ plugins {
4543}
4644
4745group = " com.ms.gradle"
48- version = " 2.0.2 "
46+ version = " 2.0.3 "
4947
5048val pluginId = " com.ms.gradle.application"
5149val pluginClass = " com.ms.gradle.application.ApplicationPlugin"
@@ -65,7 +63,7 @@ val productUrl = "https://github.com/morganstanley/gradle-plugin-application"
6563val supportedJavaVersions = sortedSetOf(
6664 JavaVersion .VERSION_1_8 , JavaVersion .VERSION_11 , JavaVersion .VERSION_17 , JavaVersion .VERSION_21 )
6765val sourceJavaVersion = supportedJavaVersions.minOf { it }
68- val toolsJavaVersion = JavaVersion . VERSION_11
66+ val toolsJavaVersion = supportedJavaVersions.maxOf { it }
6967
7068fun 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