diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /build-logic/src/main/kotlin | |
parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
download | dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2 dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip |
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing
* Update Gradle to 8.4
* Refactor and simplify convention plugins and build scripts
Fixes #3132
---------
Co-authored-by: Adam <897017+aSemy@users.noreply.github.com>
Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'build-logic/src/main/kotlin')
26 files changed, 295 insertions, 519 deletions
diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts index b485520a..407a9800 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/base.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.base.gradle.kts @@ -2,9 +2,7 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - -import org.jetbrains.DokkaBuildProperties +import dokkabuild.DokkaBuildProperties /** * A convention plugin that sets up common config and sensible defaults for all subprojects. @@ -16,12 +14,7 @@ plugins { base } -val dokkaBuildProperties: DokkaBuildProperties = extensions.create(DokkaBuildProperties.EXTENSION_NAME) - -if (project != rootProject) { - project.group = rootProject.group - project.version = rootProject.version -} +extensions.create<DokkaBuildProperties>(DokkaBuildProperties.EXTENSION_NAME) tasks.withType<AbstractArchiveTask>().configureEach { // https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives diff --git a/build-logic/src/main/kotlin/dokkabuild.gradle-plugin.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.gradle-plugin.gradle.kts new file mode 100644 index 00000000..e61cc062 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.gradle-plugin.gradle.kts @@ -0,0 +1,35 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.gradle.kotlin.kotlin-dsl") + id("dokkabuild.java") + kotlin("jvm") + id("dokkabuild.publish-gradle-plugin") +} + +// org.gradle.kotlin.kotlin-dsl sets languageVersion and apiVersion to 1.8 by default starting from Gradle 8. +// As we need to be compatible with previous Gradle versions, we need to set it back to 1.4. +// Note: we should do it directly on tasks and not via top-level `kotlin.compilerOptions` +// because `kotlin-dsl plugin` declares them on task level, and so top-level config is overridden +tasks.withType<KotlinCompile>().configureEach { + compilerOptions { + languageVersion.set(dokkaBuild.kotlinLanguageLevel) + apiVersion.set(dokkaBuild.kotlinLanguageLevel) + + freeCompilerArgs.addAll( + // need 1.4 support, otherwise there might be problems + // with Gradle 6.x (it's bundling Kotlin 1.4) + "-Xsuppress-version-warnings", + "-Xjsr305=strict", + "-Xskip-metadata-version-check", + ) + } +} + +tasks.validatePlugins { + enableStricterValidation.set(true) +} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/base-java.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.java.gradle.kts index 9270be47..16cb7ebc 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/base-java.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.java.gradle.kts @@ -2,17 +2,12 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - /** - * Base configuration for Java projects. - * - * This convention plugin contains shared Java config for both the [KotlinJvmPlugin] convention plugin and - * the Gradle Plugin subproject (which cannot have the `kotlin("jvm")` plugin applied). + * Base configuration for Java/JVM projects. */ plugins { - id("org.jetbrains.conventions.base") + id("dokkabuild.base") java } @@ -20,7 +15,6 @@ java { toolchain { languageVersion.set(dokkaBuild.mainJavaVersion) } - withSourcesJar() } tasks.withType<Test>().configureEach { @@ -40,3 +34,7 @@ tasks.withType<Test>().configureEach { dependencies { testImplementation(platform(libs.junit.bom)) } + +tasks.processResources { + duplicatesStrategy = DuplicatesStrategy.FAIL +} diff --git a/build-logic/src/main/kotlin/dokkabuild.kotlin-jvm.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.kotlin-jvm.gradle.kts new file mode 100644 index 00000000..796ce6c9 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.kotlin-jvm.gradle.kts @@ -0,0 +1,36 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + id("dokkabuild.java") + kotlin("jvm") +} + +val rootProjectsWithoutDependencyOnDokkaCore = listOf("dokka-integration-tests") + +kotlin { + explicitApi() + compilerOptions { + allWarningsAsErrors.set(true) + languageVersion.set(dokkaBuild.kotlinLanguageLevel) + apiVersion.set(dokkaBuild.kotlinLanguageLevel) + + // These projects know nothing about the `@InternalDokkaApi` annotation, so the Kotlin compiler + // will complain about an unresolved opt-in requirement marker and fail the build if it's not excluded. + if (rootProject.name !in rootProjectsWithoutDependencyOnDokkaCore) { + optIn.addAll( + "kotlin.RequiresOptIn", + "org.jetbrains.dokka.InternalDokkaApi" + ) + } + + freeCompilerArgs.addAll( + // need 1.4 support, otherwise there might be problems + // with Gradle 6.x (it's bundling Kotlin 1.4) + "-Xsuppress-version-warnings", + "-Xjsr305=strict", + "-Xskip-metadata-version-check", + ) + } +} diff --git a/build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts new file mode 100644 index 00000000..85fca751 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.publish-base.gradle.kts @@ -0,0 +1,95 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +plugins { + `maven-publish` + signing +} + +publishing { + repositories { + maven { + name = "mavenCentral" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = System.getenv("DOKKA_SONATYPE_USER") + password = System.getenv("DOKKA_SONATYPE_PASSWORD") + } + } + maven { + name = "spaceDev" + url = uri("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") + credentials { + username = System.getenv("DOKKA_SPACE_PACKAGES_USER") + password = System.getenv("DOKKA_SPACE_PACKAGES_SECRET") + } + } + maven { + name = "spaceTest" + url = uri("https://maven.pkg.jetbrains.space/kotlin/p/dokka/test") + credentials { + username = System.getenv("DOKKA_SPACE_PACKAGES_USER") + password = System.getenv("DOKKA_SPACE_PACKAGES_SECRET") + } + } + // Publish to a project-local Maven directory, for verification. To test, run: + // ./gradlew publishAllPublicationsToProjectLocalRepository + // and check $rootDir/build/maven-project-local + maven { + name = "projectLocal" + url = uri(rootProject.layout.buildDirectory.dir("maven-project-local")) + } + } + + publications.withType<MavenPublication>().configureEach { + pom { + name.convention("Dokka ${project.name}") + description.convention("Dokka is an API documentation engine for Kotlin") + url.convention("https://github.com/Kotlin/dokka") + + licenses { + license { + name.convention("The Apache Software License, Version 2.0") + url.convention("https://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.convention("repo") + } + } + + developers { + developer { + id.convention("JetBrains") + name.convention("JetBrains Team") + organization.convention("JetBrains") + organizationUrl.convention("https://www.jetbrains.com") + } + } + + scm { + connection.convention("scm:git:git://github.com/Kotlin/dokka.git") + url.convention("https://github.com/Kotlin/dokka") + } + } + } +} + +signing { + useInMemoryPgpKeys( + System.getenv("DOKKA_SIGN_KEY_ID")?.takeIf(String::isNotBlank), + System.getenv("DOKKA_SIGN_KEY")?.takeIf(String::isNotBlank), + System.getenv("DOKKA_SIGN_KEY_PASSPHRASE")?.takeIf(String::isNotBlank), + ) + sign(publishing.publications) + setRequired(provider { !project.version.toString().endsWith("-SNAPSHOT") }) +} + +// This is a hack for a Gradle 8 problem, see https://github.com/gradle/gradle/issues/26091 +// +// Fails with the following error otherwise: +// > Task ':runner-gradle-plugin-classic:publishDokkaPluginMarkerMavenPublicationToSpaceTestRepository' uses +// > this output of task ':runner-gradle-plugin-classic:signPluginMavenPublication' without declaring an +// > explicit or implicit dependency. +tasks.withType<AbstractPublishToMaven>().configureEach { + val signingTasks = tasks.withType<Sign>() + mustRunAfter(signingTasks) +} diff --git a/build-logic/src/main/kotlin/dokkabuild.publish-gradle-plugin.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.publish-gradle-plugin.gradle.kts new file mode 100644 index 00000000..93718909 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.publish-gradle-plugin.gradle.kts @@ -0,0 +1,36 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import dokkabuild.PublicationName + +plugins { + id("dokkabuild.publish-base") + id("com.gradle.plugin-publish") +} + +@Suppress("UnstableApiUsage") +gradlePlugin { + website.set("https://kotl.in/dokka") + vcsUrl.set("https://github.com/kotlin/dokka.git") +} + +// com.gradle.plugin-publish configures publication in afterEvaluate block +// so to be able to configure it directly in build scripts (f.e. to change artifactId) we need to register it earlier +// more info: https://docs.gradle.org/current/userguide/java_gradle_plugin.html#maven_publish_plugin +publishing.publications.register<MavenPublication>(PublicationName.GRADLE_PLUGIN) + +// com.gradle.plugin-publish configures javadoc only for the main plugin artifact, +// so we need to link it manually to other publications +// specifically with artifact `org.jetbrains.dokka.gradle.plugin` +// which is used to resolve plugins via `plugins { id("org.jetbrains.dokka") }` +// it's not needed for gradle plugin portal, but needed for Maven Central +// NOTE: it should be configured in `afterEvaluate` +// because `javadocJar` task is created in `afterEvaluate` block in `com.gradle.plugin-publish` plugin +afterEvaluate { + publishing.publications.withType<MavenPublication>() + .matching { it.name != PublicationName.GRADLE_PLUGIN } + .configureEach { + artifact(tasks.named("javadocJar")) + } +} diff --git a/build-logic/src/main/kotlin/dokkabuild.publish-jvm.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.publish-jvm.gradle.kts new file mode 100644 index 00000000..6c7a978d --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.publish-jvm.gradle.kts @@ -0,0 +1,19 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import dokkabuild.PublicationName + +plugins { + id("dokkabuild.java") + id("dokkabuild.publish-base") +} + +java { + withSourcesJar() + withJavadocJar() +} + +publishing.publications.register<MavenPublication>(PublicationName.JVM) { + from(components["java"]) +} diff --git a/build-logic/src/main/kotlin/dokkabuild.publish-shadow.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.publish-shadow.gradle.kts new file mode 100644 index 00000000..7abb3376 --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild.publish-shadow.gradle.kts @@ -0,0 +1,31 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +import dokkabuild.PublicationName + +plugins { + id("dokkabuild.java") + id("dokkabuild.publish-base") + id("com.github.johnrengelman.shadow") +} + +java { + withSourcesJar() + withJavadocJar() +} + +tasks.shadowJar { + // separate directory because otherwise Gradle complains about multiple tasks writing into the same file + destinationDirectory.set(project.layout.buildDirectory.dir("shadowLibs")) + // removes the `-all` classifier from the artifact name + archiveClassifier.set("") +} + +publishing.publications.register<MavenPublication>(PublicationName.JVM) { + // shadow.component call should be after the shadowJar task is configured in a build script, + // because if not, shadow uses the wrong archiveFile (as we change destinationDirectory and archiveClassifier) + shadow.component(this) + artifact(tasks.named("sourcesJar")) + artifact(tasks.named("javadocJar")) +} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka-html-frontend-files.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.setup-html-frontend-files.gradle.kts index 198194b1..c172c4e3 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka-html-frontend-files.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.setup-html-frontend-files.gradle.kts @@ -2,8 +2,6 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE /** @@ -11,7 +9,7 @@ import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE */ plugins { - id("org.jetbrains.conventions.base") + id("dokkabuild.base") } /** Apply a distinct attribute to the incoming/outgoing configuration */ diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts index f07ff98d..13d311a1 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-cli-setup.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.setup-maven-cli.gradle.kts @@ -2,8 +2,6 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - import org.gradle.kotlin.dsl.support.serviceOf /** @@ -45,7 +43,7 @@ val mavenCliSetupExtension = mavenInstallDir.convention(layout.buildDirectory.dir("apache-maven")) val isWindowsProvider = - providers.systemProperty("os.name").map { "win" in it.toLowerCase() } + providers.systemProperty("os.name").map { "win" in it.lowercase() } mvn.convention( providers.zip(mavenInstallDir, isWindowsProvider) { mavenInstallDir, isWindows -> diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka-integration-test.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.test-integration.gradle.kts index 75e27a62..16bf8620 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka-integration-test.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.test-integration.gradle.kts @@ -2,13 +2,11 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent plugins { - id("org.jetbrains.conventions.kotlin-jvm") + id("dokkabuild.kotlin-jvm") } val integrationTestSourceSet: SourceSet = sourceSets.create("integrationTest") { @@ -59,7 +57,6 @@ val integrationTest by tasks.registering(NonCacheableIntegrationTest::class) { maxParallelForks = parallelism } - environment( "isExhaustive", project.properties["dokka_integration_test_is_exhaustive"]?.toString()?.toBoolean() @@ -75,7 +72,3 @@ val integrationTest by tasks.registering(NonCacheableIntegrationTest::class) { showStackTraces = true } } - -tasks.check { - dependsOn(integrationTest) -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/base-unit-test.gradle.kts b/build-logic/src/main/kotlin/dokkabuild.test-k2.gradle.kts index 4911499d..d1467dab 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/base-unit-test.gradle.kts +++ b/build-logic/src/main/kotlin/dokkabuild.test-k2.gradle.kts @@ -2,15 +2,13 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains.conventions - /** - * Utility to run ynit tests for K1 and K2 (analysis API). + * Utility to run unit tests for K1 and K2 (analysis API). */ plugins { - id("org.jetbrains.conventions.base") - id("org.jetbrains.conventions.base-java") + id("dokkabuild.base") + id("dokkabuild.java") } val descriptorsTestConfiguration: Configuration by configurations.creating { diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaBuildProperties.kt b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt index 6d1e0ae4..ad39177c 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/DokkaBuildProperties.kt +++ b/build-logic/src/main/kotlin/dokkabuild/DokkaBuildProperties.kt @@ -2,7 +2,7 @@ * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ -package org.jetbrains +package dokkabuild import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory diff --git a/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt b/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt new file mode 100644 index 00000000..dd83cf5f --- /dev/null +++ b/build-logic/src/main/kotlin/dokkabuild/PublicationUtils.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package dokkabuild + +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType + +object PublicationName { + const val JVM = "jvm" + const val GRADLE_PLUGIN = "pluginMaven" +} + +fun Project.overridePublicationArtifactId( + artifactId: String, + publicationName: String = PublicationName.JVM +) { + extensions.configure<PublishingExtension> { + publications.withType<MavenPublication>().named(publicationName) { + this.artifactId = artifactId + } + } +} diff --git a/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt b/build-logic/src/main/kotlin/dokkabuild/internal/GradleKotlinDslAccessors.kt index 6558568c..7b854f16 100644 --- a/build-logic/src/main/kotlin/org/jetbrains/internal/gradleKotlinDslAccessors.kt +++ b/build-logic/src/main/kotlin/dokkabuild/internal/GradleKotlinDslAccessors.kt @@ -8,7 +8,7 @@ package org.gradle.kotlin.dsl // for convenience use a default package for gradl import org.gradle.api.Project import org.gradle.accessors.dm.LibrariesForLibs -import org.jetbrains.DokkaBuildProperties +import dokkabuild.DokkaBuildProperties /* * Utility functions for accessing Gradle extensions that are created by convention plugins. diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt b/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt deleted file mode 100644 index 34981302..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/DokkaPublicationChannel.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:Suppress("LocalVariableName") - -package org.jetbrains - -import org.gradle.api.Project - -enum class DokkaPublicationChannel { - SPACE_DOKKA_DEV, - MAVEN_CENTRAL, - MAVEN_CENTRAL_SNAPSHOT, - GRADLE_PLUGIN_PORTAL; - - val acceptedDokkaVersionTypes: List<DokkaVersionType> - get() = when(this) { - MAVEN_CENTRAL -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC) - MAVEN_CENTRAL_SNAPSHOT -> listOf(DokkaVersionType.SNAPSHOT) - SPACE_DOKKA_DEV -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC, DokkaVersionType.DEV, DokkaVersionType.SNAPSHOT) - GRADLE_PLUGIN_PORTAL -> listOf(DokkaVersionType.RELEASE, DokkaVersionType.RC) - } - - fun isSpaceRepository() = this == SPACE_DOKKA_DEV - - fun isMavenRepository() = this == MAVEN_CENTRAL || this == MAVEN_CENTRAL_SNAPSHOT - - fun isGradlePluginPortal() = this == GRADLE_PLUGIN_PORTAL - - companion object { - fun fromPropertyString(value: String): DokkaPublicationChannel = when (value) { - "space-dokka-dev" -> SPACE_DOKKA_DEV - "maven-central-release" -> MAVEN_CENTRAL - "maven-central-snapshot" -> MAVEN_CENTRAL_SNAPSHOT - "gradle-plugin-portal" -> GRADLE_PLUGIN_PORTAL - else -> throw IllegalArgumentException("Unknown dokka_publication_channel=$value") - } - } -} - -val Project.publicationChannels: Set<DokkaPublicationChannel> - get() { - val publicationChannel = this.properties["dokka_publication_channel"]?.toString() - val publicationChannels = this.properties["dokka_publication_channels"]?.toString() - if (publicationChannel != null && publicationChannels != null) { - throw IllegalArgumentException( - "Only one of dokka_publication_channel and dokka_publication_channel*s* can be set. Found: \n" + - "dokka_publication_channel=$publicationChannel\n" + - "dokka_publication_channels=$publicationChannels" - ) - } - - if (publicationChannel != null) { - return setOf(DokkaPublicationChannel.fromPropertyString(publicationChannel)) - } - - if (publicationChannels != null) { - return publicationChannels.split("&").map { channel -> - DokkaPublicationChannel.fromPropertyString(channel) - }.toSet() - } - - return emptySet() - } - diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaVersion.kt b/build-logic/src/main/kotlin/org/jetbrains/DokkaVersion.kt deleted file mode 100644 index 9028e8cf..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/DokkaVersion.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains - -import org.gradle.api.Project -import org.gradle.kotlin.dsl.extra -import org.gradle.kotlin.dsl.provideDelegate - -@Suppress("LocalVariableName") // property name with underscore as taken from gradle.properties -fun Project.configureDokkaVersion(): String { - val dokka_version: String? by this.extra - return checkNotNull(dokka_version) -} - -val Project.dokkaVersion: String - get() = configureDokkaVersion() - -val Project.dokkaVersionType: DokkaVersionType? - get() = DokkaVersionType.values().find { - it.suffix.matches(dokkaVersion.substringAfter("-", "")) - } diff --git a/build-logic/src/main/kotlin/org/jetbrains/DokkaVersionType.kt b/build-logic/src/main/kotlin/org/jetbrains/DokkaVersionType.kt deleted file mode 100644 index 7ceb595b..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/DokkaVersionType.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains - -enum class DokkaVersionType(val suffix: Regex) { - RELEASE("^$".toRegex()), - RC("RC\\d?".toRegex()), - SNAPSHOT("SNAPSHOT".toRegex()), - DEV("dev-\\d+".toRegex()); -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/ValidatePublications.kt b/build-logic/src/main/kotlin/org/jetbrains/ValidatePublications.kt deleted file mode 100644 index 293ae96b..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/ValidatePublications.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -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 -import org.gradle.api.tasks.TaskAction -import org.gradle.kotlin.dsl.findByType - -open class ValidatePublications : DefaultTask() { - - init { - group = "verification" - project.tasks.named("check") { - dependsOn(this@ValidatePublications) - } - } - - @TaskAction - fun validatePublicationConfiguration() { - project.subprojects.forEach { subProject -> - val publishing = subProject.extensions.findByType<PublishingExtension>() ?: return@forEach - publishing.publications - .filterIsInstance<MavenPublication>() - .filter { it.version == project.dokkaVersion } - .forEach { _ -> - subProject.assertPublicationVersion() - } - } - } - - 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") - } - } -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka.gradle.kts deleted file mode 100644 index 5abd8575..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/dokka.gradle.kts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.conventions - -import org.gradle.kotlin.dsl.invoke -import org.jetbrains.isLocalPublication - -plugins { - id("org.jetbrains.dokka") -} - -tasks.dokkaHtml { - onlyIf { !isLocalPublication } - outputDirectory.set(layout.buildDirectory.dir("dokka")) -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/gradle-plugin.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/gradle-plugin.gradle.kts deleted file mode 100644 index fb2ca119..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/gradle-plugin.gradle.kts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.conventions - -plugins { - id("org.gradle.kotlin.kotlin-dsl") - id("org.jetbrains.conventions.maven-publish") - id("com.gradle.plugin-publish") - id("org.jetbrains.conventions.base-java") - kotlin("jvm") -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts deleted file mode 100644 index d2425ce3..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/kotlin-jvm.gradle.kts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.conventions - -import org.jetbrains.configureDokkaVersion -import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - id("org.jetbrains.conventions.base-java") - kotlin("jvm") -} - -configureDokkaVersion() - -kotlin { - explicitApi = ExplicitApiMode.Strict - - compilerOptions { - allWarningsAsErrors.set(true) - languageVersion.set(dokkaBuild.kotlinLanguageLevel) - apiVersion.set(dokkaBuild.kotlinLanguageLevel) - - freeCompilerArgs.addAll( - listOf( - // need 1.4 support, otherwise there might be problems - // with Gradle 6.x (it's bundling Kotlin 1.4) - "-Xsuppress-version-warnings", - "-Xjsr305=strict", - "-Xskip-metadata-version-check", - ) - ) - } -} - -val projectsWithoutInternalDokkaApiUsage = setOf( - ":integration-tests", - ":integration-tests:gradle", - ":integration-tests:maven", - ":integration-tests:cli" -) - -tasks.withType<KotlinCompile>().configureEach { - // By path because Dokka has multiple projects with the same name (i.e. 'cli') - if (project.path in projectsWithoutInternalDokkaApiUsage) { - return@configureEach - } - compilerOptions { - freeCompilerArgs.addAll( - listOf( - "-opt-in=kotlin.RequiresOptIn", - "-opt-in=org.jetbrains.dokka.InternalDokkaApi", - ) - ) - } -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-publish.gradle.kts b/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-publish.gradle.kts deleted file mode 100644 index a5ab6b91..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/conventions/maven-publish.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains.conventions - -import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin - -plugins { - id("org.jetbrains.conventions.base") - `maven-publish` - signing - id("org.jetbrains.conventions.dokka") -} - -val javadocJar by tasks.registering(Jar::class) { - group = JavaBasePlugin.DOCUMENTATION_GROUP - description = "Assembles a Javadoc JAR using Dokka HTML" - archiveClassifier.set("javadoc") - from(tasks.dokkaHtml) -} - -publishing { - repositories { - // Publish to a project-local Maven directory, for verification. To test, run: - // ./gradlew publishAllPublicationsToMavenProjectLocalRepository - // and check $rootDir/build/maven-project-local - maven(rootProject.layout.buildDirectory.dir("maven-project-local")) { - name = "MavenProjectLocal" - } - } - - publications.withType<MavenPublication>().configureEach { - artifact(javadocJar) - - pom { - name.convention(provider { "Dokka ${project.name}" }) - description.convention("Dokka is an API documentation engine for Kotlin and Java, performing the same function as Javadoc for Java") - url.convention("https://github.com/Kotlin/dokka") - - licenses { - license { - name.convention("The Apache Software License, Version 2.0") - url.convention("https://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.convention("repo") - } - } - - developers { - developer { - id.convention("JetBrains") - name.convention("JetBrains Team") - organization.convention("JetBrains") - organizationUrl.convention("https://www.jetbrains.com") - } - } - - scm { - connection.convention("scm:git:git://github.com/Kotlin/dokka.git") - url.convention("https://github.com/Kotlin/dokka/tree/master") - } - } - } -} - -plugins.withType<ShadowPlugin>().configureEach { - // manually disable publication of Shadow elements https://github.com/johnrengelman/shadow/issues/651#issue-839148311 - // This is done to preserve compatibility and have the same behaviour as previous versions of Dokka. - // For more details, see https://github.com/Kotlin/dokka/pull/2704#issuecomment-1499517930 - val javaComponent = components["java"] as AdhocComponentWithVariants - javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() } -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/projectUtils.kt b/build-logic/src/main/kotlin/org/jetbrains/projectUtils.kt deleted file mode 100644 index 446f386c..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/projectUtils.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains - -import org.gradle.api.Project - -fun Project.whenEvaluated(action: Project.() -> Unit) { - if (state.executed) { - action() - } else { - afterEvaluate { action() } - } -} - -fun Project.invokeWhenEvaluated(action: (project: Project) -> Unit) { - whenEvaluated { action(this) } -} - diff --git a/build-logic/src/main/kotlin/org/jetbrains/publication.kt b/build-logic/src/main/kotlin/org/jetbrains/publication.kt deleted file mode 100644 index 2a6b7a61..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/publication.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains - -import com.github.jengelman.gradle.plugins.shadow.ShadowExtension -import org.gradle.api.Project -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.publish.maven.tasks.PublishToMavenRepository -import org.gradle.kotlin.dsl.* -import org.gradle.plugins.signing.SigningExtension -import org.jetbrains.DokkaPublicationChannel.* -import java.net.URI - -class DokkaPublicationBuilder { - enum class Component { - Java, Shadow - } - - var artifactId: String? = null - var component: Component = Component.Java -} - - -fun Project.registerDokkaArtifactPublication( - publicationName: String, - configure: DokkaPublicationBuilder.() -> Unit -) { - configure<PublishingExtension> { - publications { - register<MavenPublication>(publicationName) { - val builder = DokkaPublicationBuilder().apply(configure) - artifactId = builder.artifactId - when (builder.component) { - DokkaPublicationBuilder.Component.Java -> from(components["java"]) - DokkaPublicationBuilder.Component.Shadow -> run { - extensions.getByType<ShadowExtension>().component(this) - artifact(tasks["sourcesJar"]) - } - } - } - } - } - - configureSpacePublicationIfNecessary(publicationName) - configureSonatypePublicationIfNecessary(publicationName) - createDokkaPublishTaskIfNecessary() -} - -fun Project.configureSpacePublicationIfNecessary(vararg publications: String) { - if (SPACE_DOKKA_DEV in this.publicationChannels) { - configure<PublishingExtension> { - repositories { - /* already registered */ - findByName(SPACE_DOKKA_DEV.name)?.let { return@repositories } - maven { - name = SPACE_DOKKA_DEV.name - url = URI.create("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev") - credentials { - username = System.getenv("SPACE_PACKAGES_USER") - password = System.getenv("SPACE_PACKAGES_SECRET") - } - } - } - } - } - - whenEvaluated { - tasks.withType<PublishToMavenRepository> { - if (this.repository.name == SPACE_DOKKA_DEV.name) { - this.isEnabled = this.isEnabled && publication.name in publications - if (!this.isEnabled) { - this.group = "disabled" - } - } - } - } -} - -fun Project.createDokkaPublishTaskIfNecessary() { - tasks.maybeCreate("dokkaPublish").run { - if (publicationChannels.any { it.isSpaceRepository() }) { - dependsOn(tasks.named("publish")) - } - - if (publicationChannels.any { it.isMavenRepository() }) { - dependsOn(tasks.named("publishToSonatype")) - } - - if (publicationChannels.any { it.isGradlePluginPortal() }) { - dependsOn(tasks.named("publishPlugins")) - } - } -} - -fun Project.configureSonatypePublicationIfNecessary(vararg publications: String) { - if (publicationChannels.any { it.isMavenRepository() }) { - signPublicationsIfKeyPresent(*publications) - } -} - -@Suppress("UnstableApiUsage") -private fun Project.signPublicationsIfKeyPresent(vararg publications: String) { - val signingKeyId: String? = System.getenv("SIGN_KEY_ID") - val signingKey: String? = System.getenv("SIGN_KEY") - val signingKeyPassphrase: String? = System.getenv("SIGN_KEY_PASSPHRASE") - - if (!signingKey.isNullOrBlank()) { - extensions.configure<SigningExtension>("signing") { - if (signingKeyId?.isNotBlank() == true) { - useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassphrase) - } else { - useInMemoryPgpKeys(signingKey, signingKeyPassphrase) - } - publications.forEach { publicationName -> - extensions.getByType<PublishingExtension>() - .publications - .findByName(publicationName) - ?.let { sign(it) } - } - } - } -} diff --git a/build-logic/src/main/kotlin/org/jetbrains/taskUtils.kt b/build-logic/src/main/kotlin/org/jetbrains/taskUtils.kt deleted file mode 100644 index b492d9a9..00000000 --- a/build-logic/src/main/kotlin/org/jetbrains/taskUtils.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. - */ - -package org.jetbrains - -import org.gradle.api.Project -import org.gradle.api.Task - -fun Task.dependsOnMavenLocalPublication() { - project.rootProject.allprojects.forEach { otherProject -> - otherProject.invokeWhenEvaluated { evaluatedProject -> - evaluatedProject.tasks.findByName("publishToMavenLocal")?.let { publishingTask -> - this.dependsOn(publishingTask) - } - } - } -} - -val Project.isLocalPublication: Boolean - get() = gradle.startParameter.taskNames.any { - it.endsWith("publishToMavenLocal", ignoreCase = true) || - it.endsWith("integrationTest", ignoreCase = true) || - it.endsWith("check", ignoreCase = true) || - it.endsWith("test", ignoreCase = true) - } |