diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index a56fcbc..c163c3d 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -5,6 +5,7 @@ import kotlinx.validation.ApiValidationExtension import kotlinx.validation.BinaryCompatibilityValidatorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.Task import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPluginExtension @@ -13,6 +14,8 @@ import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaTask import ru.mipt.npm.gradle.internal.* +private fun Project.allTasks(): Set = allprojects.flatMapTo(HashSet()) { it.tasks } + @Suppress("unused") class KSciencePublishingExtension(val project: Project) { private var initializedFlag = false @@ -33,13 +36,17 @@ class KSciencePublishingExtension(val project: Project) { if (!initializedFlag) { vcs("https://github.com/$githubOrg/$githubProject") } + project.addGithubPublishing(githubOrg, githubProject) - if (publish) { - project.tasks.findByName("publish${project.publicationTarget}ToGithubRepository")?.let {publicationTask-> - releaseTask?.dependsOn(publicationTask) + if (publish) + project.afterEvaluate { + allTasks() + .find { it.name == "publish${publicationTarget}ToGithubRepository" } + ?.let { publicationTask -> + releaseTask?.dependsOn(publicationTask) + } } - } } private val releaseTask by lazy { @@ -52,11 +59,13 @@ class KSciencePublishingExtension(val project: Project) { fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", publish: Boolean = false) { require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } project.addSpacePublishing(spaceRepo) - if (publish) { - project.tasks.findByName("publish${project.publicationTarget}ToSpaceRepository")?.let { publicationTask -> - releaseTask?.dependsOn(publicationTask) + + if (publish) + project.afterEvaluate { + allTasks() + .find { it.name == "publish${publicationTarget}ToSpaceRepository" } + ?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) } } - } } // // Bintray publishing @@ -71,16 +80,16 @@ class KSciencePublishingExtension(val project: Project) { fun sonatype(publish: Boolean = true) { require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } project.addSonatypePublishing() - if (publish) { - project.tasks.findByName("publish${project.publicationTarget}ToSonatypeRepository") - ?.let { publicationTask -> - releaseTask?.dependsOn(publicationTask) - } - } + + if (publish) + project.afterEvaluate { + allTasks() + .find { it.name == "publish${publicationTarget}ToSonatypeRepository" } + ?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) } + } } } - /** * Apply extension and repositories */ @@ -98,7 +107,7 @@ open class KScienceProjectPlugin : Plugin { } } else { configure { - setVersion(project.version.toString()) + version.set(project.version.toString()) } } } @@ -225,4 +234,4 @@ open class KScienceProjectPlugin : Plugin { companion object { const val RELEASE_GROUP = "release" } -} \ No newline at end of file +}