aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src/main/kotlin/org
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src/main/kotlin/org')
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt4
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt3
-rw-r--r--buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt79
3 files changed, 85 insertions, 1 deletions
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
index c3d21d88..4180c445 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/BintrayPublishing.kt
@@ -10,7 +10,8 @@ fun Project.configureBintrayPublication(vararg publications: String) {
extensions.configure<BintrayExtension>("bintray") {
user = System.getenv("BINTRAY_USER")
key = System.getenv("BINTRAY_KEY")
-
+ dryRun = System.getenv("BINTRAY_DRY_RUN") == "true" ||
+ project.properties["bintray_dry_run"] == "true"
pkg = PackageConfig().apply {
repo = dokka_publication_channel
name = "dokka"
@@ -25,3 +26,4 @@ fun Project.configureBintrayPublication(vararg publications: String) {
setPublications(*publications)
}
}
+
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
index d5fd3e78..2a5c21a7 100644
--- a/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
+++ b/buildSrc/src/main/kotlin/org/jetbrains/DokkaVersion.kt
@@ -21,3 +21,6 @@ private fun dokkaVersionFromBase(baseVersion: String): String {
}
return "$baseVersion-$buildNumber"
}
+
+val Project.dokkaVersion: String
+ get() = configureDokkaVersion()
diff --git a/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt
new file mode 100644
index 00000000..84c48b96
--- /dev/null
+++ b/buildSrc/src/main/kotlin/org/jetbrains/ValidatePublications.kt
@@ -0,0 +1,79 @@
+package org.jetbrains
+
+import com.jfrog.bintray.gradle.BintrayExtension
+import org.gradle.api.DefaultTask
+import org.gradle.api.GradleException
+import org.gradle.api.Project
+import org.gradle.api.artifacts.ProjectDependency
+import org.gradle.api.publish.PublishingExtension
+import org.gradle.api.publish.maven.MavenPublication
+import org.gradle.api.tasks.TaskAction
+import org.gradle.kotlin.dsl.findByType
+import org.gradle.kotlin.dsl.provideDelegate
+
+open class ValidatePublications : DefaultTask() {
+ class MissingBintrayPublicationException(project: Project, publication: MavenPublication) : GradleException(
+ "Project ${project.path} has publication ${publication.name} that is not configured for bintray publication"
+ )
+
+ class UnpublishedProjectDependencyException(
+ project: Project, dependencyProject: Project
+ ) : GradleException(
+ "Published project ${project.path} cannot depend on unpublished projed ${dependencyProject.path}"
+ )
+
+
+ @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 ->
+ checkPublicationIsConfiguredForBintray(subProject, publication)
+ checkProjectDependenciesArePublished(subProject)
+ }
+ }
+ }
+
+ private fun checkPublicationIsConfiguredForBintray(project: Project, publication: MavenPublication) {
+ val bintrayExtension = project.extensions.findByType<BintrayExtension>()
+ ?: throw MissingBintrayPublicationException(project, publication)
+
+ val isPublicationConfiguredForBintray = bintrayExtension.publications.orEmpty()
+ .any { publicationName -> publicationName == publication.name }
+
+ if (!isPublicationConfiguredForBintray) {
+ throw MissingBintrayPublicationException(project, publication)
+ }
+ }
+
+ private fun checkProjectDependenciesArePublished(project: Project) {
+ (project.configurations.findByName("implementation")?.allDependencies.orEmpty() +
+ project.configurations.findByName("api")?.allDependencies.orEmpty())
+ .filterIsInstance<ProjectDependency>()
+ .forEach { projectDependency ->
+ val publishing = projectDependency.dependencyProject.extensions.findByType<PublishingExtension>()
+ ?: throw UnpublishedProjectDependencyException(
+ project = project, dependencyProject = projectDependency.dependencyProject
+ )
+
+ val isPublished = publishing.publications.filterIsInstance<MavenPublication>()
+ .filter { it.version == project.dokkaVersion }
+ .any()
+
+ if (!isPublished) {
+ throw UnpublishedProjectDependencyException(project, projectDependency.dependencyProject)
+ }
+ }
+ }
+
+ init {
+ group = "verification"
+ project.tasks.named("check") {
+ dependsOn(this@ValidatePublications)
+ }
+ }
+}