Skip to content

Commit

Permalink
fix issue with javadocJar tasks (#788)
Browse files Browse the repository at this point in the history
* fix issue with javadocJar tasks

* ktlint
  • Loading branch information
gabrielittner authored May 26, 2024
1 parent d81a4e8 commit 42d5235
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.provider.Property
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.external.javadoc.StandardJavadocDocletOptions
Expand Down Expand Up @@ -153,11 +152,6 @@ abstract class MavenPublishBaseExtension(
project.gradleSigning.sign(publication)
}

// TODO: https://youtrack.jetbrains.com/issue/KT-46466 https://github.com/gradle/gradle/issues/26091
project.tasks.withType(AbstractPublishToMaven::class.java).configureEach { publishTask ->
publishTask.dependsOn(project.tasks.withType(Sign::class.java))
}

// TODO: https://youtrack.jetbrains.com/issue/KT-61313/ https://github.com/gradle/gradle/issues/26132
project.plugins.withId("org.jetbrains.kotlin.multiplatform") {
project.tasks.withType(Sign::class.java).configureEach {
Expand Down
17 changes: 6 additions & 11 deletions plugin/src/main/kotlin/com/vanniktech/maven/publish/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.gradle.api.plugins.internal.JavaPluginHelper
import org.gradle.api.plugins.internal.JvmPluginsHelper
import org.gradle.api.provider.Provider
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.component.external.model.ProjectDerivedCapability
import org.gradle.jvm.component.internal.DefaultJvmSoftwareComponent
import org.gradle.jvm.tasks.Jar
Expand Down Expand Up @@ -66,7 +65,7 @@ data class JavaLibrary @JvmOverloads constructor(
project.gradlePublishing.publications.create(PUBLICATION_NAME, MavenPublication::class.java) {
it.from(project.components.getByName("java"))
it.withJavaSourcesJar(sourcesJar, project)
it.withJavadocJar { project.javadocJarTask(javadocJar) }
it.withJavadocJar(javadocJar, project)
}

setupTestFixtures(project, sourcesJar)
Expand Down Expand Up @@ -95,11 +94,9 @@ data class GradlePlugin @JvmOverloads constructor(
"Calling configure(GradlePlugin(...)) requires the java-gradle-plugin to be applied"
}

val javadocJarTask = project.javadocJarTask(javadocJar)

project.mavenPublicationsWithoutPluginMarker {
it.withJavaSourcesJar(sourcesJar, project)
it.withJavadocJar { javadocJarTask }
it.withJavadocJar(javadocJar, project)
}
}
}
Expand Down Expand Up @@ -287,10 +284,8 @@ data class KotlinMultiplatform internal constructor(
"Calling configure(KotlinMultiplatform(...)) requires the org.jetbrains.kotlin.multiplatform plugin to be applied"
}

val javadocJarTask = project.javadocJarTask(javadocJar)

project.mavenPublications {
it.withJavadocJar { javadocJarTask }
it.withJavadocJar(javadocJar, project)
}

project.extensions.configure(KotlinMultiplatformExtension::class.java) {
Expand Down Expand Up @@ -339,7 +334,7 @@ data class KotlinJvm @JvmOverloads constructor(
project.gradlePublishing.publications.create(PUBLICATION_NAME, MavenPublication::class.java) {
it.from(project.components.getByName("java"))
it.withJavaSourcesJar(sourcesJar, project)
it.withJavadocJar { project.javadocJarTask(javadocJar) }
it.withJavadocJar(javadocJar, project)
}

setupTestFixtures(project, sourcesJar)
Expand Down Expand Up @@ -480,8 +475,8 @@ private fun MavenPublication.withJavaSourcesJar(enabled: Boolean, project: Proje
}
}

private fun MavenPublication.withJavadocJar(factory: () -> TaskProvider<*>?) {
val task = factory()
private fun MavenPublication.withJavadocJar(javadocJar: JavadocJar, project: Project) {
val task = project.javadocJarTask(name, javadocJar)
if (task != null) {
artifact(task)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@ open class JavadocJar : Jar() {
}

internal companion object {
internal fun Project.javadocJarTask(javadocJar: JavadocJarOption): TaskProvider<*>? {
internal fun Project.javadocJarTask(prefix: String, javadocJar: JavadocJarOption): TaskProvider<*>? {
return when (javadocJar) {
is JavadocJarOption.None -> null
is JavadocJarOption.Empty -> emptyJavadocJar()
is JavadocJarOption.Javadoc -> plainJavadocJar()
is JavadocJarOption.Dokka -> dokkaJavadocJar(javadocJar.taskName)
is JavadocJarOption.Empty -> emptyJavadocJar(prefix)
is JavadocJarOption.Javadoc -> plainJavadocJar(prefix)
is JavadocJarOption.Dokka -> dokkaJavadocJar(prefix, javadocJar.taskName)
}
}

private fun Project.emptyJavadocJar(): TaskProvider<*> = tasks.register("emptyJavadocJar", JavadocJar::class.java)
private fun Project.emptyJavadocJar(prefix: String): TaskProvider<*> = tasks.register(
"${prefix}EmptyJavadocJar",
JavadocJar::class.java,
) {
it.archiveBaseName.set("$prefix-javadoc")
}

private fun Project.plainJavadocJar(): TaskProvider<*> {
return tasks.register("plainJavadocJar", JavadocJar::class.java) {
private fun Project.plainJavadocJar(prefix: String): TaskProvider<*> {
return tasks.register("${prefix}PlainJavadocJar", JavadocJar::class.java) {
val task = tasks.named("javadoc")
it.dependsOn(task)
it.from(task)
it.archiveBaseName.set("$prefix-javadoc")
}
}

private fun Project.dokkaJavadocJar(taskName: DokkaTaskName): TaskProvider<*> {
return tasks.register("dokkaJavadocJar", JavadocJar::class.java) {
private fun Project.dokkaJavadocJar(prefix: String, taskName: DokkaTaskName): TaskProvider<*> {
return tasks.register("${prefix}DokkaJavadocJar", JavadocJar::class.java) {
val task = when (taskName) {
is ProviderDokkaTaskName -> taskName.value.flatMap { name -> tasks.named(name) }
is StringDokkaTaskName -> tasks.named(taskName.value)
}
it.dependsOn(task)
it.from(task)
it.archiveBaseName.set("$prefix-javadoc")
}
}
}
Expand Down

0 comments on commit 42d5235

Please sign in to comment.