From 5a812642b0da23a41ebde813b1c9b5de61c960a6 Mon Sep 17 00:00:00 2001 From: Philipp Schirmer Date: Wed, 28 Feb 2024 10:22:23 +0100 Subject: [PATCH] Listen for Java and Dokka plugin setup --- .../com/bakdata/gradle/SonatypePlugin.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sonatype/src/main/kotlin/com/bakdata/gradle/SonatypePlugin.kt b/sonatype/src/main/kotlin/com/bakdata/gradle/SonatypePlugin.kt index 0d28e2c..a2f8fcb 100644 --- a/sonatype/src/main/kotlin/com/bakdata/gradle/SonatypePlugin.kt +++ b/sonatype/src/main/kotlin/com/bakdata/gradle/SonatypePlugin.kt @@ -31,6 +31,7 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.attributes.DocsType.JAVADOC import org.gradle.api.logging.Logging +import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -220,18 +221,16 @@ class SonatypePlugin : Plugin { apply(plugin = "signing") apply(plugin = "org.gradle.maven-publish") - // Java and Dokka plugins might not have been applied yet - project.afterEvaluate { - tasks.findByName("dokka")?.apply { - val javadocTask: Task = this - val main: SourceSet = - the().sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) - tasks.create(main.javadocJarTaskName) { - archiveClassifier.set(JAVADOC) - from(javadocTask) - } + project.tasks.matching { it.name == "dokka" }.all { + val javadocTask: Task = this + val main: SourceSet = the().sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME) + tasks.create(main.javadocJarTaskName) { + archiveClassifier.set(JAVADOC) + from(javadocTask) } + } + project.plugins.matching { it is JavaPlugin }.all { configure { withSourcesJar() withJavadocJar()