Skip to content

Commit

Permalink
Refactor the project into "gradle-common"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ShreckYe committed May 20, 2022
1 parent 80a6dbc commit 78591b2
Show file tree
Hide file tree
Showing 35 changed files with 365 additions and 184 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
68 changes: 68 additions & 0 deletions architecture-common-gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
*/

kotlin.sourceSets.all {
languageSettings.defaultOptIns()
}
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
12 changes: 12 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/ScriptPlugins.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.plugin.devel.PluginDeclaration

fun NamedDomainObjectContainer<PluginDeclaration>.scriptPlugin(
`package`: String, shortName: String, displayNameAndDescription: String
) =
getByName("$`package`.$shortName") {
displayName = displayNameAndDescription
description = displayNameAndDescription
}
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions buildSrc/src/main/kotlin/plugin-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
5 changes: 5 additions & 0 deletions common-gradle-dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins {
id("build-dependency-library-conventions")
}

version = "0.1.0-20220520-dev"
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.mpp.stability.nowarn=true
Loading

0 comments on commit 78591b2

Please sign in to comment.