diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7d787090..c6b88303 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,9 +1,6 @@ -import java.awt.Color.red - plugins { - id("conventions.base") - id("conventions.kotlin") - application + alias(opensavvyConventions.plugins.base) + alias(opensavvyConventions.plugins.kotlin.application) } kotlin { @@ -19,7 +16,7 @@ kotlin { val commonTest by sourceSets.getting { dependencies { - implementation(playgroundLibs.kotlin.test) + implementation(opensavvyConventions.aligned.kotlin.test.junit) } } } diff --git a/build.gradle.kts b/build.gradle.kts index 4b754650..33856b88 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,24 +8,24 @@ */ plugins { - id("conventions.base") - id("conventions.root") + alias(opensavvyConventions.plugins.base) + alias(opensavvyConventions.plugins.root) // Some plugins *must* be configured on the root project. // In these cases, we explicitly tell Gradle not to apply them. - alias(playgroundLibs.plugins.kotlin) apply false - - alias(playgroundLibs.plugins.dokkatoo) + alias(opensavvyConventions.plugins.aligned.kotlin) apply false } dependencies { // List the 'library' projects dokkatoo(projects.core) +} - // This is required at the moment, see https://github.com/adamko-dev/dokkatoo/issues/14 - dokkatooPluginHtml( - dokkatoo.versions.jetbrainsDokka.map { dokkaVersion -> - "org.jetbrains.dokka:all-modules-page-plugin:$dokkaVersion" - } - ) +// region Check the users of the project didn't forget to rename the group + +val projectPath: String? = System.getenv("CI_PROJECT_PATH") +if (projectPath != null && projectPath != "opensavvy/playgrounds/gradle" && group == "dev.opensavvy.playground") { + error("The project is declared to be in the group '$group', which is recognized as the Gradle Playground, but it's hosted in '$projectPath', which is not the Playground. Maybe you forgot to rename the group when importing the Playground in your own project?") } + +// endregion diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 42ac38d0..66e21968 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,7 +1,6 @@ plugins { - id("conventions.base") - id("conventions.kotlin") - id("conventions.library") + alias(opensavvyConventions.plugins.base) + alias(opensavvyConventions.plugins.kotlin.library) } kotlin { @@ -12,4 +11,9 @@ library { name.set("Playground Core") description.set("Project template with configured MavenCentral publication") homeUrl.set("https://gitlab.com/opensavvy/playgrounds/gradle") + + license.set { + name.set("Apache 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } } diff --git a/gradle.properties b/gradle.properties index 83a44f61..75d1cef3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ +# Maven coordinates +appGroup=dev.opensavvy.playground # Allow Gradle to execute tasks from different subprojects in parallel. org.gradle.parallel=true diff --git a/gradle/conventions/base/build.gradle.kts b/gradle/conventions/base/build.gradle.kts deleted file mode 100644 index b9d90a24..00000000 --- a/gradle/conventions/base/build.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -plugins { - `kotlin-dsl` -} - -group = "conventions" diff --git a/gradle/conventions/base/src/main/kotlin/base.gradle.kts b/gradle/conventions/base/src/main/kotlin/base.gradle.kts deleted file mode 100644 index 013cb0ff..00000000 --- a/gradle/conventions/base/src/main/kotlin/base.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -package conventions - -plugins { - base -} - -val appVersion: String? by project - -group = "dev.opensavvy.playground" -version = appVersion ?: "0.0.0-DEV" - -// region Check the users of the project didn't forget to rename the group - -val projectPath: String? = System.getenv("CI_PROJECT_PATH") -if (projectPath != null && projectPath != "opensavvy/playgrounds/gradle" && group == "dev.opensavvy.playground") { - error("The project is declared to be in the group '$group', which is recognized as the Gradle Playground, but it's hosted in '$projectPath', which is not the Playground. Maybe you forgot to rename the group when importing the Playground in your own project?") -} - -// endregion diff --git a/gradle/conventions/kotlin/build.gradle.kts b/gradle/conventions/kotlin/build.gradle.kts deleted file mode 100644 index 786b1409..00000000 --- a/gradle/conventions/kotlin/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - `kotlin-dsl` -} - -group = "conventions" - -dependencies { - implementation(playgroundLibs.gradle.kotlin) -} diff --git a/gradle/conventions/kotlin/src/main/kotlin/kotlin.gradle.kts b/gradle/conventions/kotlin/src/main/kotlin/kotlin.gradle.kts deleted file mode 100644 index c26b54a4..00000000 --- a/gradle/conventions/kotlin/src/main/kotlin/kotlin.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -package conventions - -plugins { - // Currently, it is not possible to use version catalogs here… - kotlin("multiplatform") -} - -repositories { - mavenCentral() - google() -} - -kotlin { - jvmToolchain(17) -} - -tasks.withType().configureEach { - maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1 -} diff --git a/gradle/conventions/library/build.gradle.kts b/gradle/conventions/library/build.gradle.kts deleted file mode 100644 index dab59c0d..00000000 --- a/gradle/conventions/library/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - `kotlin-dsl` -} - -group = "conventions" - -dependencies { - implementation(playgroundLibs.gradle.dokkatoo) -} diff --git a/gradle/conventions/library/src/main/kotlin/library.gradle.kts b/gradle/conventions/library/src/main/kotlin/library.gradle.kts deleted file mode 100644 index bc327f26..00000000 --- a/gradle/conventions/library/src/main/kotlin/library.gradle.kts +++ /dev/null @@ -1,168 +0,0 @@ -package conventions - -import java.net.URI - -plugins { - id("maven-publish") - id("signing") - - id("dev.adamko.dokkatoo-html") -} - -// Global configuration for the repository -// Remember to change this when using in your own project! - -fun MavenPom.buildConfiguration() { - licenses { - license { - name.set("Apache 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0") - } - } - - developers { - developer { - id.set("clovis-ai") - name.set("Ivan “CLOVIS” Canet") - email.set("ivan.canet@gmail.com") - } - } - - scm { - url.set(System.getenv("CI_PROJECT_URL")) - } -} - -// region Metadata - -interface LibraryExtension { - val name: Property - val description: Property - val homeUrl: Property -} - -val config = extensions.create("library") - -// endregion -// region GitLab Maven Registry - -// When running in GitLab CI, uses the auto-created CI variables to configure the GitLab Maven Registry. -// For more information on the variables and their values, see: -// - https://docs.gitlab.com/ee/user/packages/maven_repository/ -// - https://docs.gitlab.com/ee/ci/variables/predefined_variables.html -publishing { - repositories { - val projectId = System.getenv("CI_PROJECT_ID") ?: return@repositories - val token = System.getenv("CI_JOB_TOKEN") ?: return@repositories - val api = System.getenv("CI_API_V4_URL") ?: return@repositories - - maven { - name = "GitLab" - url = uri("$api/projects/$projectId/packages/maven") - - credentials(HttpHeaderCredentials::class.java) { - name = "Job-Token" - value = token - } - - authentication { - create("header") - } - } - } -} - -// endregion -// region Maven Central - -val fakeJavadocJar by tasks.registering(Jar::class) { - description = "Fake documentation JAR for MavenCentral" - group = "publishing" - - archiveClassifier.set("javadoc") -} - -publishing { - publications.withType { - artifact(fakeJavadocJar.get()) - - pom { - name.set(config.name) - description.set(config.description) - url.set(config.homeUrl) - - buildConfiguration() - } - } -} - -run { - ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID") ?: return@run - ext["signing.password"] = System.getenv("SIGNING_PASSWORD") ?: return@run - ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_KEY_RING") ?: return@run - - // Workaround for https://youtrack.jetbrains.com/issue/KT-61858 - val signingTasks = tasks.withType(Sign::class) - tasks.withType(AbstractPublishToMaven::class).configureEach { - dependsOn(signingTasks) - } - - signing { - sign(publishing.publications) - } -} - -//endregion -// region Documentation - -dokkatoo { - moduleName.set(config.name) - - dokkatooSourceSets.configureEach { - // region Include the correct HTML file, if it exists - if (name.endsWith("Main") || name == "main") { - val setName = name.removeSuffix("Main") - - val headerName = - if (setName == "common" || name == "main") "README.md" - else "README.$setName.md" - - val headerPath = "${project.projectDir}/$headerName" - if (File(headerPath).exists()) - includes.from(headerPath) - else - logger.info("No specific documentation file found for $setName, expected to find $headerPath") - } - // endregion - // region Dependencies - - fun dependencyDocumentation(name: String, url: String) = externalDocumentationLinks.register(name) { - this.url.set(URI(url)) - } - - dependencyDocumentation("KotlinX.Coroutines", "https://kotlinlang.org/api/kotlinx.coroutines/") - dependencyDocumentation("KotlinX.Serialization", "https://kotlinlang.org/api/kotlinx.serialization/") - dependencyDocumentation("Ktor", "https://api.ktor.io/") - dependencyDocumentation("Arrow", "https://apidocs.arrow-kt.io") - - // endregion - // region Link to the sources - - val projectUrl = System.getenv("CI_PROJECT_URL") - val commit = System.getenv("CI_COMMIT_SHA") ?: "main" - - if (projectUrl != null) { - sourceLink { - val path = projectDir.relativeTo(rootProject.projectDir) - - localDirectory.set(file("src")) - remoteUrl.set(URI("$projectUrl/-/blob/$commit/$path/src")) - remoteLineSuffix.set("#L") - } - } - - // endregion - } -} - -// endregion diff --git a/gradle/conventions/root/build.gradle.kts b/gradle/conventions/root/build.gradle.kts deleted file mode 100644 index 1d430e71..00000000 --- a/gradle/conventions/root/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - `kotlin-dsl` -} - -group = "conventions" - -dependencies { - implementation(playgroundLibs.gradle.nexusPublish) -} diff --git a/gradle/conventions/root/src/main/kotlin/root.gradle.kts b/gradle/conventions/root/src/main/kotlin/root.gradle.kts deleted file mode 100644 index d7d7d62b..00000000 --- a/gradle/conventions/root/src/main/kotlin/root.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -package conventions - -plugins { - id("io.github.gradle-nexus.publish-plugin") -} - -nexusPublishing { - val projectPath = System.getenv("CI_PROJECT_PATH_SLUG") - val refSlug = System.getenv("CI_COMMIT_REF_SLUG") - val pipelineId = System.getenv("CI_PIPELINE_IID") - repositoryDescription.set("$projectPath for $refSlug (pipeline $pipelineId)") // must be globally unique for a pipeline to avoid issues with concurrent builds - - repositories { - sonatype { - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - - username.set(System.getenv("OSSRH_USERNAME")) - password.set(System.getenv("OSSRH_PASSWORD")) - } - } -} - -repositories { - mavenCentral() -} diff --git a/gradle/conventions/settings.gradle.kts b/gradle/conventions/settings.gradle.kts index 24253698..c08e5b5f 100644 --- a/gradle/conventions/settings.gradle.kts +++ b/gradle/conventions/settings.gradle.kts @@ -1,47 +1,24 @@ rootProject.name = "conventions" dependencyResolutionManagement { - repositories { - mavenCentral() - gradlePluginPortal() - } - versionCatalogs { create("libs") { from(files("../libs.versions.toml")) } - - create("playgroundLibs") { - from(files("../playground.versions.toml")) - } } } -include( - "base", - "root", - "kotlin", - "library", -) - -enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") - -buildCache { - val username = System.getenv("GRADLE_BUILD_CACHE_CREDENTIALS")?.split(':')?.get(0) - val password = System.getenv("GRADLE_BUILD_CACHE_CREDENTIALS")?.split(':')?.get(1) - - val mainBranch: String? = System.getenv("CI_DEFAULT_BRANCH") - val currentBranch: String? = System.getenv("CI_COMMIT_REF_NAME") - val runningForTag = System.getenv().containsKey("CI_COMMIT_TAG") - - remote { - url = uri("https://gradle.opensavvy.dev/cache/") - - if (username != null && password != null) credentials { - this.username = username - this.password = password - } +pluginManagement { + repositories { + gradlePluginPortal() - isPush = (mainBranch != null && currentBranch != null && mainBranch == currentBranch) || runningForTag + // OpenSavvy conventions + maven("https://gitlab.com/api/v4/projects/51233470/packages/maven") } } + +plugins { + id("dev.opensavvy.conventions.settings") version "0.2.1" +} + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6699f7ae..d7e5a2c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,4 @@ # List of dependencies of the project -# Dependencies shared between all projects based on the Playground are declared in playground.versions.toml [versions] diff --git a/gradle/playground.versions.toml b/gradle/playground.versions.toml deleted file mode 100644 index 60320e26..00000000 --- a/gradle/playground.versions.toml +++ /dev/null @@ -1,27 +0,0 @@ -# Library versions common between all projects based on the Playground -# This helps ensure all our projects are aligned - -[versions] -# https://kotlinlang.org/docs/releases.html -kotlin = "1.9.10" - -# https://github.com/adamko-dev/dokkatoo/releases -dokkatoo = "2.0.0" - -# https://github.com/gradle-nexus/publish-plugin/releases -nexus-publish = "1.3.0" - -[plugins] -kotlin = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -dokkatoo = { id = "dev.adamko.dokkatoo-html", version.ref = "dokkatoo" } - -kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } - -[libraries] -kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" } - -gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -gradle-nexusPublish = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-publish" } -gradle-dokkatoo = { module = "dev.adamko.dokkatoo:dokkatoo-plugin", version.ref = "dokkatoo" } - -[bundles] diff --git a/settings.gradle.kts b/settings.gradle.kts index b6f38cb0..f30d5590 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,44 +13,19 @@ pluginManagement { repositories { gradlePluginPortal() google() + + // OpenSavvy conventions + maven("https://gitlab.com/api/v4/projects/51233470/packages/maven") } includeBuild("gradle/conventions") } -dependencyResolutionManagement { - versionCatalogs { - create("playgroundLibs") { - from(files("gradle/playground.versions.toml")) - } - } -} - plugins { - id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" + id("dev.opensavvy.conventions.settings") version "0.2.2" } include( "app", "core", ) - -buildCache { - val username = System.getenv("GRADLE_BUILD_CACHE_CREDENTIALS")?.split(':')?.get(0) - val password = System.getenv("GRADLE_BUILD_CACHE_CREDENTIALS")?.split(':')?.get(1) - - val mainBranch: String? = System.getenv("CI_DEFAULT_BRANCH") - val currentBranch: String? = System.getenv("CI_COMMIT_REF_NAME") - val runningForTag = System.getenv().containsKey("CI_COMMIT_TAG") - - remote { - url = uri("https://gradle.opensavvy.dev/cache/") - - if (username != null && password != null) credentials { - this.username = username - this.password = password - } - - isPush = (mainBranch != null && currentBranch != null && mainBranch == currentBranch) || runningForTag - } -}