diff options
Diffstat (limited to 'buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt')
-rw-r--r-- | buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt index 921ec025..af35a847 100644 --- a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt +++ b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt @@ -3,6 +3,7 @@ package org.jetbrains import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Project +import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -11,22 +12,21 @@ import org.gradle.kotlin.dsl.findByType open class ValidatePublications : DefaultTask() { - class UnpublishedProjectDependencyException( - project: Project, dependencyProject: Project - ) : GradleException( - "Published project ${project.path} cannot depend on unpublished project ${dependencyProject.path}" - ) - + init { + group = "verification" + project.tasks.named("check") { + dependsOn(this@ValidatePublications) + } + } @TaskAction fun validatePublicationConfiguration() { - @Suppress("LocalVariableName") project.subprojects.forEach { subProject -> val publishing = subProject.extensions.findByType<PublishingExtension>() ?: return@forEach publishing.publications .filterIsInstance<MavenPublication>() .filter { it.version == project.dokkaVersion } - .forEach { publication -> + .forEach { _ -> checkProjectDependenciesArePublished(subProject) subProject.assertPublicationVersion() } @@ -34,8 +34,12 @@ open class ValidatePublications : DefaultTask() { } private fun checkProjectDependenciesArePublished(project: Project) { - (project.configurations.findByName("implementation")?.allDependencies.orEmpty() + - project.configurations.findByName("api")?.allDependencies.orEmpty()) + val implementationDependencies = project.findDependenciesByName("implementation") + val apiDependencies = project.findDependenciesByName("api") + + val allDependencies = implementationDependencies + apiDependencies + + allDependencies .filterIsInstance<ProjectDependency>() .forEach { projectDependency -> val publishing = projectDependency.dependencyProject.extensions.findByType<PublishingExtension>() @@ -52,23 +56,24 @@ open class ValidatePublications : DefaultTask() { } } - private fun Project.assertPublicationVersion() { - if (System.getenv("SKIP_VERSION_CHECK")?.contains("true", ignoreCase = true) == true) - return + private fun Project.findDependenciesByName(name: String): Set<Dependency> { + return configurations.findByName(name)?.allDependencies.orEmpty() + } - if (!publicationChannels.all { publicationChannel -> - publicationChannel.acceptedDokkaVersionTypes.any { acceptedVersionType -> - acceptedVersionType == dokkaVersionType - } - }) { + private fun Project.assertPublicationVersion() { + val versionTypeMatchesPublicationChannels = publicationChannels.all { publicationChannel -> + publicationChannel.acceptedDokkaVersionTypes.any { acceptedVersionType -> + acceptedVersionType == dokkaVersionType + } + } + if (!versionTypeMatchesPublicationChannels) { throw AssertionError("Wrong version $dokkaVersion for configured publication channels $publicationChannels") } } - init { - group = "verification" - project.tasks.named("check") { - dependsOn(this@ValidatePublications) - } - } + private class UnpublishedProjectDependencyException( + project: Project, dependencyProject: Project + ): GradleException( + "Published project ${project.path} cannot depend on unpublished project ${dependencyProject.path}" + ) } |