Fix dependencies of release task #19

Merged
CommanderTvis merged 1 commits from commandertvis/fix-release into dev 2021-07-21 12:31:22 +03:00

View File

@ -5,6 +5,7 @@ import kotlinx.validation.ApiValidationExtension
import kotlinx.validation.BinaryCompatibilityValidatorPlugin import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.changelog.ChangelogPluginExtension
@ -13,6 +14,8 @@ import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import ru.mipt.npm.gradle.internal.* import ru.mipt.npm.gradle.internal.*
private fun Project.allTasks(): Set<Task> = allprojects.flatMapTo(HashSet()) { it.tasks }
@Suppress("unused") @Suppress("unused")
class KSciencePublishingExtension(val project: Project) { class KSciencePublishingExtension(val project: Project) {
private var initializedFlag = false private var initializedFlag = false
@ -33,13 +36,17 @@ class KSciencePublishingExtension(val project: Project) {
if (!initializedFlag) { if (!initializedFlag) {
vcs("https://github.com/$githubOrg/$githubProject") vcs("https://github.com/$githubOrg/$githubProject")
} }
project.addGithubPublishing(githubOrg, githubProject) project.addGithubPublishing(githubOrg, githubProject)
if (publish) { if (publish)
project.tasks.findByName("publish${project.publicationTarget}ToGithubRepository")?.let {publicationTask-> project.afterEvaluate {
releaseTask?.dependsOn(publicationTask) allTasks()
.find { it.name == "publish${publicationTarget}ToGithubRepository" }
?.let { publicationTask ->
releaseTask?.dependsOn(publicationTask)
}
} }
}
} }
private val releaseTask by lazy { 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) { 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" } require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" }
project.addSpacePublishing(spaceRepo) project.addSpacePublishing(spaceRepo)
if (publish) {
project.tasks.findByName("publish${project.publicationTarget}ToSpaceRepository")?.let { publicationTask -> if (publish)
releaseTask?.dependsOn(publicationTask) project.afterEvaluate {
allTasks()
.find { it.name == "publish${publicationTarget}ToSpaceRepository" }
?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) }
} }
}
} }
// // Bintray publishing // // Bintray publishing
@ -71,16 +80,16 @@ class KSciencePublishingExtension(val project: Project) {
fun sonatype(publish: Boolean = true) { fun sonatype(publish: Boolean = true) {
require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" }
project.addSonatypePublishing() project.addSonatypePublishing()
if (publish) {
project.tasks.findByName("publish${project.publicationTarget}ToSonatypeRepository") if (publish)
?.let { publicationTask -> project.afterEvaluate {
releaseTask?.dependsOn(publicationTask) allTasks()
} .find { it.name == "publish${publicationTarget}ToSonatypeRepository" }
} ?.let { publicationTask -> releaseTask?.dependsOn(publicationTask) }
}
} }
} }
/** /**
* Apply extension and repositories * Apply extension and repositories
*/ */
@ -98,7 +107,7 @@ open class KScienceProjectPlugin : Plugin<Project> {
} }
} else { } else {
configure<ChangelogPluginExtension> { configure<ChangelogPluginExtension> {
setVersion(project.version.toString()) version.set(project.version.toString())
} }
} }
} }