aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-07-08 17:09:41 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-07-09 09:24:52 +0200
commit1b8030d4b8d4b83e35c91632694fb32fcb58a02d (patch)
treeb266352658c943159065f5bde252a7a63b99a9aa
parent4ba7ec9facb26c5ae0b0dd434e07c4af728f277a (diff)
downloaddokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.tar.gz
dokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.tar.bz2
dokka-1b8030d4b8d4b83e35c91632694fb32fcb58a02d.zip
Implement PublicationValidation
-rw-r--r--build.gradle.kts6
-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
-rw-r--r--plugins/gfm/build.gradle.kts4
-rw-r--r--plugins/javadoc/build.gradle.kts1
-rw-r--r--plugins/jekyll/build.gradle.kts6
-rw-r--r--plugins/mathjax/build.gradle.kts6
-rw-r--r--runners/gradle-plugin/build.gradle.kts2
9 files changed, 104 insertions, 7 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index ee17ba75..7cc0394f 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,3 +1,4 @@
+import org.jetbrains.ValidatePublications
import org.jetbrains.configureDokkaVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -45,8 +46,6 @@ subprojects {
}
}
-println("Publication version: $dokka_version")
-
// Workaround for https://github.com/bintray/gradle-bintray-plugin/issues/267
// Manually disable bintray tasks added to the root project
tasks.whenTaskAdded {
@@ -54,3 +53,6 @@ tasks.whenTaskAdded {
enabled = false
}
}
+
+println("Publication version: $dokka_version")
+tasks.register<ValidatePublications>("validatePublications")
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)
+ }
+ }
+}
diff --git a/plugins/gfm/build.gradle.kts b/plugins/gfm/build.gradle.kts
index 2addd9c9..16b318fb 100644
--- a/plugins/gfm/build.gradle.kts
+++ b/plugins/gfm/build.gradle.kts
@@ -1,3 +1,5 @@
+import org.jetbrains.configureBintrayPublication
+
publishing {
publications {
register<MavenPublication>("gfmPlugin") {
@@ -7,6 +9,8 @@ publishing {
}
}
+configureBintrayPublication("gfmPlugin")
+
dependencies {
compileOnly(project(":plugins:base"))
testImplementation(project(":plugins:base"))
diff --git a/plugins/javadoc/build.gradle.kts b/plugins/javadoc/build.gradle.kts
index 4c5c22b0..ebf79f8f 100644
--- a/plugins/javadoc/build.gradle.kts
+++ b/plugins/javadoc/build.gradle.kts
@@ -1,5 +1,4 @@
import org.jetbrains.configureBintrayPublication
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
publishing {
publications {
diff --git a/plugins/jekyll/build.gradle.kts b/plugins/jekyll/build.gradle.kts
index a5c10fa0..b47633db 100644
--- a/plugins/jekyll/build.gradle.kts
+++ b/plugins/jekyll/build.gradle.kts
@@ -1,3 +1,5 @@
+import org.jetbrains.configureBintrayPublication
+
publishing {
publications {
register<MavenPublication>("jekyllPlugin") {
@@ -7,7 +9,9 @@ publishing {
}
}
+configureBintrayPublication("jekyllPlugin")
+
dependencies {
compileOnly(project(":plugins:base"))
implementation(project(":plugins:gfm"))
-} \ No newline at end of file
+}
diff --git a/plugins/mathjax/build.gradle.kts b/plugins/mathjax/build.gradle.kts
index 0e9a16d0..67f4822f 100644
--- a/plugins/mathjax/build.gradle.kts
+++ b/plugins/mathjax/build.gradle.kts
@@ -1,3 +1,5 @@
+import org.jetbrains.configureBintrayPublication
+
publishing {
publications {
register<MavenPublication>("mathjaxPlugin") {
@@ -5,4 +7,6 @@ publishing {
from(components["java"])
}
}
-} \ No newline at end of file
+}
+
+configureBintrayPublication("mathjaxPlugin")
diff --git a/runners/gradle-plugin/build.gradle.kts b/runners/gradle-plugin/build.gradle.kts
index 77fbe4a7..a8345652 100644
--- a/runners/gradle-plugin/build.gradle.kts
+++ b/runners/gradle-plugin/build.gradle.kts
@@ -81,4 +81,4 @@ pluginBundle {
}
}
-configureBintrayPublication("dokkaGradlePlugin", "dokkaGradlePluginPluginMarkerMaven")
+configureBintrayPublication("dokkaGradlePlugin", "pluginMaven", "dokkaGradlePluginPluginMarkerMaven")