From 78591b27c6b236d73a465676c4b497c762eaaf41 Mon Sep 17 00:00:00 2001 From: Shreck Ye Date: Fri, 20 May 2022 22:18:22 +0800 Subject: [PATCH] Refactor the project into "gradle-common" Major tasks done: 1. separate some more opinionated plugins into "architecture-common-gradle-plugins" 1. add a "common-gradle-dependencies" subproject to organize dependencies and their versions, which should probably be extracted into a separate project in the future 1. continue adapting for the "kotlin-common" project --- README.md | 10 +- .../build.gradle.kts | 68 +++++++++++ ...KotlinJsBrowserWebrootForVertxWebPlugin.kt | 0 .../main/kotlin/com/huanshankeji/OptIns.kt | 2 + ...terial-web-frontend-conventions.gradle.kts | 0 ...efault-web-frontend-conventions.gradle.kts | 0 ...jvm-application-app-conventions.gradle.kts | 2 +- ...tlin-jvm-common-app-conventions.gradle.kts | 36 ++++++ ...lin-jvm-library-app-conventions.gradle.kts | 4 +- ...n-multiplatform-app-conventions.gradle.kts | 6 +- ...form-js-browser-app-conventions.gradle.kts | 0 ...-and-js-browser-app-conventions.gradle.kts | 0 buildSrc/build.gradle.kts | 12 ++ buildSrc/src/main/kotlin/ScriptPlugins.kt | 10 ++ ...-dependency-library-conventions.gradle.kts | 16 +++ .../main/kotlin/plugin-conventions.gradle.kts | 17 +++ common-gradle-dependencies/build.gradle.kts | 5 + .../com/huanshankeji/CommonDependencies.kt | 101 ++++++++++++++++ .../com/huanshankeji/DefaultVersions.kt | 20 ++++ .../KotlinxDependencyExtensions.kt | 0 gradle.properties | 1 + kotlin-common-gradle-plugins/build.gradle.kts | 42 +++++++ .../huanshankeji/GradleKotlinExtensions.kt | 0 .../kotlin/com/huanshankeji/ProjectNames.kt | 0 .../default-maven-publish.gradle.kts | 0 .../kotlin-jvm-common-conventions.gradle.kts | 12 ++ ...fault-maven-publish-conventions.gradle.kts | 10 +- ...otlin-multiplatform-conventions.gradle.kts | 0 ...platform-js-browser-conventions.gradle.kts | 0 ...-jvm-and-js-browser-conventions.gradle.kts | 3 + ...fault-maven-publish-conventions.gradle.kts | 0 plugin/build.gradle.kts | 113 ------------------ .../main/kotlin/com/huanshankeji/Versions.kt | 3 - .../kotlin-jvm-common-conventions.gradle.kts | 45 ------- settings.gradle.kts | 11 +- 35 files changed, 365 insertions(+), 184 deletions(-) create mode 100644 architecture-common-gradle-plugins/build.gradle.kts rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/GenerateKotlinJsBrowserWebrootForVertxWebPlugin.kt (100%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/OptIns.kt (86%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/default-material-web-frontend-conventions.gradle.kts (100%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/default-web-frontend-conventions.gradle.kts (100%) rename plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-conventions.gradle.kts => architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-app-conventions.gradle.kts (86%) create mode 100644 architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-app-conventions.gradle.kts rename plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-conventions.gradle.kts => architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-app-conventions.gradle.kts (75%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts (65%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-app-conventions.gradle.kts (100%) rename {plugin => architecture-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-app-conventions.gradle.kts (100%) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/ScriptPlugins.kt create mode 100644 buildSrc/src/main/kotlin/build-dependency-library-conventions.gradle.kts create mode 100644 buildSrc/src/main/kotlin/plugin-conventions.gradle.kts create mode 100644 common-gradle-dependencies/build.gradle.kts create mode 100644 common-gradle-dependencies/src/main/kotlin/com/huanshankeji/CommonDependencies.kt create mode 100644 common-gradle-dependencies/src/main/kotlin/com/huanshankeji/DefaultVersions.kt rename {plugin => common-gradle-dependencies}/src/main/kotlin/com/huanshankeji/KotlinxDependencyExtensions.kt (100%) create mode 100644 gradle.properties create mode 100644 kotlin-common-gradle-plugins/build.gradle.kts rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/GradleKotlinExtensions.kt (100%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/ProjectNames.kt (100%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/default-maven-publish.gradle.kts (100%) create mode 100644 kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts (67%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-conventions.gradle.kts (100%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-conventions.gradle.kts (100%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts (55%) rename {plugin => kotlin-common-gradle-plugins}/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts (100%) delete mode 100644 plugin/build.gradle.kts delete mode 100644 plugin/src/main/kotlin/com/huanshankeji/Versions.kt delete mode 100644 plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts diff --git a/README.md b/README.md index ffb8fab..133973e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# Huanshankeji Kotlin Common Gradle plugin -Huanshankeji's Gradle plugin for common projects in Kotlin +# Huanshankeji Gradle Common (in and for Kotlin) + +Huanshankeji's Gradle common code in Kotlin, mainly for common projects in Kotlin + +## Notices + +1. IntelliJ IDEA doesn't work well with applying plugins to script plugins in project sources. If a script plugin's code + does not resolve, try restarting IntelliJ IDEA. \ No newline at end of file diff --git a/architecture-common-gradle-plugins/build.gradle.kts b/architecture-common-gradle-plugins/build.gradle.kts new file mode 100644 index 0000000..275e6a6 --- /dev/null +++ b/architecture-common-gradle-plugins/build.gradle.kts @@ -0,0 +1,68 @@ +plugins { + id("plugin-conventions") +} + +repositories { + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") +} + +dependencies { + implementation(project(":kotlin-common-gradle-plugins")) + //api(project(":common-gradle-dependencies")) + implementation(project(":common-gradle-dependencies")) + + implementation("org.jetbrains.compose:compose-gradle-plugin:1.2.0-alpha01-dev686") +} + +gradlePlugin { + plugins { + val `package` = group as String + fun scriptConventionsPlugin(shortName: String, displayNameAndDescription: String) = + scriptPlugin(`package`, shortName, displayNameAndDescription) + + scriptConventionsPlugin( + "kotlin-jvm-common-app-conventions", + "Kotlin/JVM common app conventions" + ) + scriptConventionsPlugin( + "kotlin-jvm-application-app-conventions", + "Kotlin/JVM application app conventions" + ) + scriptConventionsPlugin( + "kotlin-jvm-library-app-conventions", + "Kotlin/JVM library app conventions" + ) + + scriptConventionsPlugin( + "kotlin-multiplatform-app-conventions", + "Kotlin Multiplatform app conventions" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-js-browser-app-conventions", + "Kotlin Multiplatform app conventions with the JS browser target" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-jvm-and-js-browser-app-conventions", + "Kotlin Multiplatform app conventions with the JVM target and the JS browser target" + ) + + scriptConventionsPlugin( + "default-web-frontend-conventions", + "Default web frontend conventions for our projects with Compose for Web and kotlinx.html HTML generation" + ) + /* TODO + scriptConventionsPlugin( + "default-material-web-frontend-conventions", + "Default web frontend conventions for our projects with Compose for Web, kotlinx.html HTML generation, and Material Design" + ) + */ + + val name = "generate-kotlin-js-browser-webroot-for-vertx-web" + create(name) { + id = "$`package`.$name" + implementationClass = "$`package`.GenerateKotlinJsBrowserWebrootForVertxWebPlugin" + displayName = "Generate Kotlin/JS browser webroot for Vert.x Web" + description = "Generate webroot from a Kotlin/JS subproject with browser target for Vert.x Web" + } + } +} diff --git a/plugin/src/main/kotlin/com/huanshankeji/GenerateKotlinJsBrowserWebrootForVertxWebPlugin.kt b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GenerateKotlinJsBrowserWebrootForVertxWebPlugin.kt similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/GenerateKotlinJsBrowserWebrootForVertxWebPlugin.kt rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GenerateKotlinJsBrowserWebrootForVertxWebPlugin.kt diff --git a/plugin/src/main/kotlin/com/huanshankeji/OptIns.kt b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/OptIns.kt similarity index 86% rename from plugin/src/main/kotlin/com/huanshankeji/OptIns.kt rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/OptIns.kt index 7beea4d..cfecdb5 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/OptIns.kt +++ b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/OptIns.kt @@ -4,6 +4,8 @@ import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder fun LanguageSettingsBuilder.defaultOptIns() { optIn("kotlin.RequiresOptIn") + + optIn("kotlin.ExperimentalStdlibApi") optIn("kotlin.ExperimentalUnsignedTypes") optIn("kotlinx.serialization.ExperimentalSerializationApi") } diff --git a/plugin/src/main/kotlin/com/huanshankeji/default-material-web-frontend-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-material-web-frontend-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/default-material-web-frontend-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-material-web-frontend-conventions.gradle.kts diff --git a/plugin/src/main/kotlin/com/huanshankeji/default-web-frontend-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-web-frontend-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/default-web-frontend-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-web-frontend-conventions.gradle.kts diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-app-conventions.gradle.kts similarity index 86% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-app-conventions.gradle.kts index 60cb15d..103efa6 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-conventions.gradle.kts +++ b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-application-app-conventions.gradle.kts @@ -6,7 +6,7 @@ package com.huanshankeji plugins { // Apply the common convention plugin for shared build configuration between library and application projects. - id("com.huanshankeji.kotlin-jvm-common-conventions") + id("com.huanshankeji.kotlin-jvm-common-app-conventions") // Apply the application plugin to add support for building a CLI application in Java. application diff --git a/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-app-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-app-conventions.gradle.kts new file mode 100644 index 0000000..64ce4a3 --- /dev/null +++ b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-app-conventions.gradle.kts @@ -0,0 +1,36 @@ +package com.huanshankeji + +plugins { + id("com.huanshankeji.kotlin-jvm-common-conventions") +} + +dependencies { + implementation(platform(kotlin("bom"))) + + testImplementation(kotlin("test")) + testImplementation("org.junit.jupiter:junit-jupiter-api:${DefaultVersions.junitJupiter}") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") + + implementation(CommonDependencies.Kotlinx.Coroutines.core()) + testImplementation(CommonDependencies.Kotlinx.Coroutines.test()) +} + +tasks.test { + // Use junit platform for unit tests. + useJUnitPlatform() +} + +/* +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +tasks.withType { + kotlinOptions.jvmTarget = "11" +} +*/ + +kotlin.sourceSets.all { + languageSettings.defaultOptIns() +} diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-app-conventions.gradle.kts similarity index 75% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-app-conventions.gradle.kts index f1d8980..6a5be43 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-conventions.gradle.kts +++ b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-app-conventions.gradle.kts @@ -1,14 +1,12 @@ package com.huanshankeji -import org.gradle.kotlin.dsl.`java-library` - /* * This file was generated by the Gradle 'init' task. */ plugins { // Apply the common convention plugin for shared build configuration between library and application projects. - id("com.huanshankeji.kotlin-jvm-common-conventions") + id("com.huanshankeji.kotlin-jvm-common-app-conventions") // Apply the java-library plugin for API and implementation separation. `java-library` diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts similarity index 65% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts index 486f8ab..c884e1c 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts +++ b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-app-conventions.gradle.kts @@ -6,19 +6,17 @@ plugins { kotlin { sourceSets { - val kotlinCoroutinesVersion: String by project - val commonMain by getting { dependencies { //implementation(platform(kotlin("bom", kotlinVersion))) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion") + implementation(CommonDependencies.Kotlinx.Coroutines.core()) } } val commonTest by getting { dependencies { implementation(kotlin("test")) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion") + implementation(CommonDependencies.Kotlinx.Coroutines.test()) } } diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-app-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-app-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-app-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-app-conventions.gradle.kts diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-app-conventions.gradle.kts b/architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-app-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-app-conventions.gradle.kts rename to architecture-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-app-conventions.gradle.kts diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..1a030f1 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() +} + +dependencies { + implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:2.1.7") // It seems this version has to be used for Gradle 7.4.2. + implementation("com.gradle.publish:plugin-publish-plugin:1.0.0-rc-2") +} diff --git a/buildSrc/src/main/kotlin/ScriptPlugins.kt b/buildSrc/src/main/kotlin/ScriptPlugins.kt new file mode 100644 index 0000000..ecfda09 --- /dev/null +++ b/buildSrc/src/main/kotlin/ScriptPlugins.kt @@ -0,0 +1,10 @@ +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.plugin.devel.PluginDeclaration + +fun NamedDomainObjectContainer.scriptPlugin( + `package`: String, shortName: String, displayNameAndDescription: String +) = + getByName("$`package`.$shortName") { + displayName = displayNameAndDescription + description = displayNameAndDescription + } diff --git a/buildSrc/src/main/kotlin/build-dependency-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/build-dependency-library-conventions.gradle.kts new file mode 100644 index 0000000..35c05cb --- /dev/null +++ b/buildSrc/src/main/kotlin/build-dependency-library-conventions.gradle.kts @@ -0,0 +1,16 @@ +// Maybe it's better to use Maven publish and Maven repositories (Maven Central) +plugins { + kotlin("jvm") + id("com.gradle.plugin-publish") +} + +repositories { + gradlePluginPortal() +} + +group = "com.huanshankeji" + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} diff --git a/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts b/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts new file mode 100644 index 0000000..cb13aad --- /dev/null +++ b/buildSrc/src/main/kotlin/plugin-conventions.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("build-dependency-library-conventions") + id("org.gradle.kotlin.kotlin-dsl") +} + +dependencies { + // Not specifying version can cause build issues when added to a project's buildscript dependencies. + implementation(kotlin("gradle-plugin", "1.6.21")) +} + +version = "0.1.1-SNAPSHOT" + +pluginBundle { + website = "https://github.com/huanshankeji/gradle-plugin" + vcsUrl = "https://github.com/huanshankeji/gradle-plugin.git" + tags = listOf("kotlin", "multiplatform") +} diff --git a/common-gradle-dependencies/build.gradle.kts b/common-gradle-dependencies/build.gradle.kts new file mode 100644 index 0000000..969c828 --- /dev/null +++ b/common-gradle-dependencies/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("build-dependency-library-conventions") +} + +version = "0.1.0-20220520-dev" diff --git a/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/CommonDependencies.kt b/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/CommonDependencies.kt new file mode 100644 index 0000000..914e372 --- /dev/null +++ b/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/CommonDependencies.kt @@ -0,0 +1,101 @@ +package com.huanshankeji + +// some but not all default dependencies +object CommonDependencies { + object KotlinCommon { + val defaultVersion = DefaultVersions.kotlinCommon + fun module(module: String, version: String = defaultVersion) = + "com.huanshankeji:kotlin-common-$module:$version" + + fun core(version: String = defaultVersion) = module("core", version) + fun net(version: String = defaultVersion) = module("net", version) + fun web(version: String = defaultVersion) = module("web", version) + fun arrow(version: String = defaultVersion) = module("arrow", version) + fun coroutines(version: String = defaultVersion) = module("coroutines", version) + fun exposed(version: String = defaultVersion) = module("exposed", version) + + object Ktor { + fun module(module: String, version: String = defaultVersion) = + KotlinCommon.module("ktor-$module", version) + + fun client(version: String = defaultVersion) = module("client", version) + } + + fun serialization(version: String = defaultVersion) = module("serialization", version) + fun vertx(version: String = defaultVersion) = module("vertx", version) + } + + object Kotlinx { + object Coroutines { + val defaultVersion = DefaultVersions.kotlinxCoroutines + fun module(module: String, version: String = defaultVersion) = + kotlinx("coroutines-$module", version) + + fun core(version: String = defaultVersion) = module("core", version) + fun test(version: String = defaultVersion) = module("test", version) + } + + object Html { + val defaultVersion = DefaultVersions.kotlinxHtml + fun module(module: String, version: String = defaultVersion) = + "org.jetbrains.kotlinx:kotlinx-html-$module:$version" + } + + object Serialization { + val defaultVersion = DefaultVersions.kotlinxSerialization + fun module(module: String, version: String = defaultVersion) = + kotlinx("serialization-$module", version) + + fun core(version: String = defaultVersion) = module("core", version) + fun protobuf(version: String = defaultVersion) = module("protobuf", version) + fun json(version: String = defaultVersion) = module("json", version) + } + } + + + // official libraries from JetBrains + + object Exposed { + val defaultVersion = DefaultVersions.exposed + fun module(module: String, version: String = defaultVersion) = + "org.jetbrains.exposed:exposed-$module:$version" + + fun core(version: String = defaultVersion) = + module("core", version) + } + + object Ktor { + val defaultVersion = DefaultVersions.ktor + fun module(module: String, version: String = defaultVersion) = + "io.ktor:ktor-$module:$version" + + object Client { + fun module(module: String, version: String = defaultVersion) = + Ktor.module("client-$module", version) + + fun core(version: String = defaultVersion) = + module("core", version) + } + } + + + // others + + object Vertx { + val defaultVersion = DefaultVersions.vertx + fun stackDepchain(version: String = defaultVersion) = + "io.vertx:vertx-stack-depchain:$version" + + fun module(module: String) = + "io.vertx:vertx-$module" + } + + object Arrow { + val defaultVersion = DefaultVersions.arrow + fun module(module: String, version: String = defaultVersion) = + "io.arrow-kt:arrow-$module:$version" + + fun core(version: String = defaultVersion) = + module("core", version) + } +} \ No newline at end of file diff --git a/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/DefaultVersions.kt b/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/DefaultVersions.kt new file mode 100644 index 0000000..e9ebaef --- /dev/null +++ b/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/DefaultVersions.kt @@ -0,0 +1,20 @@ +package com.huanshankeji + +object DefaultVersions { + val kotlin = "1.6.21" + + val kotlinCommon = "0.1.0-SNAPSHOT" // TODO + + val exposed = "0.38.2" + val kotlinxCoroutines = "1.6.1" + val kotlinxHtml = "0.7.5" + val kotlinxSerialization = "1.3.3" + val ktor = "1.6.8" + + val arrow = "1.1.2" + val junitJupiter = "5.8.2" + val kotest = "5.2.3" + val postgreSql = "42.3.5" + val slf4j = "1.7.36" + val vertx = "4.2.7" // TODO: 4.3.0 +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/huanshankeji/KotlinxDependencyExtensions.kt b/common-gradle-dependencies/src/main/kotlin/com/huanshankeji/KotlinxDependencyExtensions.kt similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/KotlinxDependencyExtensions.kt rename to common-gradle-dependencies/src/main/kotlin/com/huanshankeji/KotlinxDependencyExtensions.kt diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..2dcadc5 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.mpp.stability.nowarn=true diff --git a/kotlin-common-gradle-plugins/build.gradle.kts b/kotlin-common-gradle-plugins/build.gradle.kts new file mode 100644 index 0000000..20c8d87 --- /dev/null +++ b/kotlin-common-gradle-plugins/build.gradle.kts @@ -0,0 +1,42 @@ +plugins { + id("plugin-conventions") +} + +dependencies { + //api(project(":common-gradle-dependencies")) +} + +gradlePlugin { + plugins { + val `package` = group as String + fun scriptConventionsPlugin(shortName: String, displayNameAndDescription: String) = + scriptPlugin(`package`, shortName, displayNameAndDescription) + + scriptConventionsPlugin( + "kotlin-jvm-common-conventions", + "Kotlin/JVM common conventions" + ) + + scriptConventionsPlugin( + "kotlin-multiplatform-conventions", + "Kotlin Multiplatform conventions" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-js-browser-conventions", + "Kotlin Multiplatform conventions with the JS browser target" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-jvm-and-js-browser-conventions", + "Kotlin Multiplatform conventions with the JVM target and the JS browser target" + ) + + scriptConventionsPlugin( + "kotlin-jvm-library-default-maven-publish-conventions", + "Kotlin/JVM library conventions with default Maven publish" + ) + scriptConventionsPlugin( + "kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions", + "Kotlin Multiplatform conventions with the JVM target and the JS browser target, and with default Maven publish" + ) + } +} diff --git a/plugin/src/main/kotlin/com/huanshankeji/GradleKotlinExtensions.kt b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GradleKotlinExtensions.kt similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/GradleKotlinExtensions.kt rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GradleKotlinExtensions.kt diff --git a/plugin/src/main/kotlin/com/huanshankeji/ProjectNames.kt b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/ProjectNames.kt similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/ProjectNames.kt rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/ProjectNames.kt diff --git a/plugin/src/main/kotlin/com/huanshankeji/default-maven-publish.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-maven-publish.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/default-maven-publish.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/default-maven-publish.gradle.kts diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts new file mode 100644 index 0000000..69aa1a6 --- /dev/null +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts @@ -0,0 +1,12 @@ +package com.huanshankeji + +plugins { + kotlin("jvm") +} + +repositories { + mavenCentral() +} + +// to prevent duplicate archive names and support Windows +base.archivesName.set(fullNameForFileSystem) diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts similarity index 67% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts index b0d872e..c478c50 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-jvm-library-default-maven-publish-conventions.gradle.kts @@ -1,19 +1,17 @@ package com.huanshankeji plugins { - // TODO: temporarily not using kotlin-jvm-library-conventions before architecture-specific logic is separated - kotlin("jvm") + id("com.huanshankeji.kotlin-jvm-common-conventions") `java-library` id("com.huanshankeji.default-maven-publish") } -repositories { - mavenCentral() -} - java { withJavadocJar() withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } publishing { diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-conventions.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-conventions.gradle.kts diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-conventions.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-js-browser-conventions.gradle.kts diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts similarity index 55% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts index 6557bd5..a968b50 100644 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-conventions.gradle.kts @@ -7,3 +7,6 @@ plugins { kotlin { jvm() } + +// to prevent duplicate archive names and support Windows +base.archivesName.set(fullNameForFileSystem) diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts similarity index 100% rename from plugin/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts rename to kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions.gradle.kts diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts deleted file mode 100644 index d0730c3..0000000 --- a/plugin/build.gradle.kts +++ /dev/null @@ -1,113 +0,0 @@ -plugins { - `kotlin-dsl` - id("com.gradle.plugin-publish") version "1.0.0-rc-1" -} - -repositories { - gradlePluginPortal() -} - -dependencies { - // Not specifying version can cause build issues when added to a project's buildscript dependencies. - implementation(kotlin("gradle-plugin", "1.6.21")) - implementation("org.jetbrains.compose:compose-gradle-plugin:1.1.1") -} - -pluginBundle { - website = "https://github.com/huanshankeji/kotlin-common-gradle-plugin" - vcsUrl = "https://github.com/huanshankeji/kotlin-common-gradle-plugin.git" - tags = listOf("kotlin", "multiplatform") -} - -group = "com.huanshankeji" -version = "0.1.1-SNAPSHOT" - -/*publishing { - publications { - create("pluginMaven") { - artifactId = rootProject.name - } - } -}*/ - -gradlePlugin { - plugins { - val commonPackage = group - fun scriptConventionsPlugin(shortName: String, displayNameAndDescription: String) = - getByName("$commonPackage.$shortName") { - displayName = displayNameAndDescription - description = displayNameAndDescription - } - - scriptConventionsPlugin( - "kotlin-jvm-common-conventions", - "Kotlin/JVM common conventions" - ) - scriptConventionsPlugin( - "kotlin-jvm-application-conventions", - "Kotlin/JVM application conventions" - ) - scriptConventionsPlugin( - "kotlin-jvm-library-conventions", - "Kotlin/JVM library conventions" - ) - - - scriptConventionsPlugin( - "kotlin-multiplatform-conventions", - "Kotlin Multiplatform conventions" - ) - /* There seems to be no need to use this currently. - scriptConventionsPlugin( - "kotlin-multiplatform-js-browser-conventions", - "Kotlin Multiplatform conventions with the JS browser target" - ) - */ - scriptConventionsPlugin( - "kotlin-multiplatform-jvm-and-js-browser-conventions", - "Kotlin Multiplatform conventions with the JVM target and the JS browser target" - ) - - scriptConventionsPlugin( - "kotlin-multiplatform-app-conventions", - "Kotlin Multiplatform app conventions" - ) - scriptConventionsPlugin( - "kotlin-multiplatform-js-browser-app-conventions", - "Kotlin Multiplatform app conventions with the JS browser target" - ) - scriptConventionsPlugin( - "kotlin-multiplatform-jvm-and-js-browser-app-conventions", - "Kotlin Multiplatform app conventions with the JVM target and the JS browser target" - ) - - scriptConventionsPlugin( - "default-web-frontend-conventions", - "Default web frontend conventions for our projects with Compose for Web and kotlinx.html HTML generation" - ) - /* TODO - scriptConventionsPlugin( - "default-material-web-frontend-conventions", - "Default web frontend conventions for our projects with Compose for Web, kotlinx.html HTML generation, and Material Design" - ) - */ - - val name = "generate-kotlin-js-browser-webroot-for-vertx-web" - create(name) { - id = "$commonPackage.$name" - implementationClass = "$commonPackage.GenerateKotlinJsBrowserWebrootForVertxWebPlugin" - displayName = "Generate Kotlin/JS browser webroot for Vert.x Web" - description = "Generate webroot from a Kotlin/JS with browser target for Vert.x Web" - } - - - scriptConventionsPlugin( - "kotlin-jvm-library-default-maven-publish-conventions", - "Kotlin/JVM library conventions with default Maven publish" - ) - scriptConventionsPlugin( - "kotlin-multiplatform-jvm-and-js-browser-default-maven-publish-conventions", - "Kotlin Multiplatform conventions with the JVM target and the JS browser target, and with default Maven publish" - ) - } -} diff --git a/plugin/src/main/kotlin/com/huanshankeji/Versions.kt b/plugin/src/main/kotlin/com/huanshankeji/Versions.kt deleted file mode 100644 index 6120e63..0000000 --- a/plugin/src/main/kotlin/com/huanshankeji/Versions.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.huanshankeji - -val junitJupiterVersion = "" // TODO diff --git a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts b/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts deleted file mode 100644 index b71a2e1..0000000 --- a/plugin/src/main/kotlin/com/huanshankeji/kotlin-jvm-common-conventions.gradle.kts +++ /dev/null @@ -1,45 +0,0 @@ -package com.huanshankeji - -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - kotlin("jvm") -} - -repositories { - mavenCentral() -} - -val junitJupiterVersion: String by project -val kotlinCoroutinesVersion: String by project -dependencies { - implementation(platform(kotlin("bom"))) - - testImplementation(kotlin("test")) - testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") - - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion") - testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion") -} - -tasks.test { - // Use junit platform for unit tests. - useJUnitPlatform() -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 -} - -tasks.withType { - kotlinOptions.jvmTarget = "11" -} - -// to prevent duplicate archive names and support Windows -base.archivesName.set(fullNameForFileSystem) - -kotlin.sourceSets.all { - languageSettings.defaultOptIns() -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 3152476..7d391e2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,11 +7,8 @@ * in the user manual at https://docs.gradle.org/7.4.2/userguide/multi_project_builds.html */ -rootProject.name = "kotlin-common-gradle-plugin" -include("plugin") -project(":plugin").name = rootProject.name +rootProject.name = "gradle-common" -/* to separate buildscript functions and constants from plugins if necessary -include("common") -project(":common").name = "kotlin-common-gradle-common" -*/ +include("kotlin-common-gradle-plugins") +include("architecture-common-gradle-plugins") +include("common-gradle-dependencies")