Skip to content

Commit

Permalink
Introduce 'evas-build' and 'evas-publish' plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sellmair committed Jul 17, 2024
1 parent 5104071 commit 5e0e834
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 195 deletions.
40 changes: 40 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}

repositories {
google {
mavenContent {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}

mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(gradleKotlinDsl())
implementation(kotlin("gradle-plugin:${deps.versions.kotlin.get()}"))
implementation("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:${deps.versions.kotlin.get()}")
implementation("com.android.tools.build:gradle:${deps.versions.androidGradlePlugin.get()}")
implementation("org.jetbrains.compose:org.jetbrains.compose.gradle.plugin:${deps.versions.compose.get()}")

implementation("org.jetbrains.kotlinx.atomicfu:org.jetbrains.kotlinx.atomicfu.gradle.plugin:0.25.0")
implementation("org.jetbrains.kotlinx.binary-compatibility-validator:org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin:0.15.1")
implementation("com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin:0.29.0")
implementation("org.jetbrains.kotlinx.benchmark:org.jetbrains.kotlinx.benchmark.gradle.plugin:${deps.versions.kotlinxBenchmark.get()}")
}

gradlePlugin.plugins.create("evas") {
id = "evas-build"
implementationClass = "EvasBuildPlugin"
}

gradlePlugin.plugins.create("evas-publish") {
id = "evas-publish"
implementationClass = "EvasPublishPlugin"
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("deps") {
from(files("../dependencies.toml"))
}
}
}
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/EvasBuildPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import conventions.androidLibraryConventions
import conventions.binaryCompatibilityValidatorConventions
import conventions.kotlinMultiplatformConventions
import org.gradle.api.Plugin
import org.gradle.api.Project

class EvasBuildPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
version = providers.gradleProperty("evas.version").get()
group = "io.sellmair"

target.kotlinMultiplatformConventions()
target.androidLibraryConventions()
target.binaryCompatibilityValidatorConventions()
}
}
14 changes: 14 additions & 0 deletions buildSrc/src/main/kotlin/EvasPublishPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import conventions.publishingConventions
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin

class EvasPublishPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {

plugins.apply(MavenPublishPlugin::class.java)
plugins.apply(com.vanniktech.maven.publish.MavenPublishPlugin::class.java)

target.publishingConventions()
}
}
22 changes: 22 additions & 0 deletions buildSrc/src/main/kotlin/conventions/androidLibraryConventions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package conventions

import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

fun Project.androidLibraryConventions() {
plugins.withId("com.android.library") {
extensions.configure<LibraryExtension> {
compileSdk = 34
defaultConfig {
minSdk = 15
namespace = "io.sellmair.${project.name}"
}
}

extensions.configure<KotlinMultiplatformExtension> {
androidTarget().publishLibraryVariants("release")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package conventions

import kotlinx.validation.ExperimentalBCVApi
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

internal fun Project.binaryCompatibilityValidatorConventions() =
plugins.withId("org.jetbrains.kotlinx.binary-compatibility-validator") {
extensions.configure<kotlinx.validation.ApiValidationExtension> {
@OptIn(kotlinx.validation.ExperimentalBCVApi::class)
klib {
enabled = true
strictValidation = true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package conventions

import org.gradle.api.Project
import org.gradle.api.tasks.testing.AbstractTestTask
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper

internal fun Project.kotlinMultiplatformConventions() {
plugins.withType<KotlinMultiplatformPluginWrapper>().all {
extensions.configure<KotlinMultiplatformExtension> {
/* Targets */


/*
Jvm options
*/
jvmToolchain(17)

/*
Kotlin Compiler Options
*/
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
if (!project.path.startsWith(":samples")) {
explicitApi()
}
}
}

/* Tests */
tasks.withType<AbstractTestTask>().configureEach {
outputs.upToDateWhen { false }
testLogging {
showStandardStreams = true
events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED, TestLogEvent.SKIPPED)
}
}
}
}
69 changes: 69 additions & 0 deletions buildSrc/src/main/kotlin/conventions/publishingConventions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package conventions

import com.vanniktech.maven.publish.KotlinMultiplatform
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.withType

internal fun Project.publishingConventions() {
plugins.withType<MavenPublishPlugin>().configureEach {
/* Publish locally to the 'build/repository' folder. Can be useful to check publication issues locally */
extensions.configure<PublishingExtension> {
repositories {
maven(rootDir.resolve("build/repository")) {
name = "local"
}
}

/* Publish to GitHub packages */
repositories {
maven("https://maven.pkg.github.com/sellmair/evas") {
name = "github"
credentials {
username = providers.gradleProperty("evas.github.user").orNull
password = providers.gradleProperty("evas.github.token").orNull
}
}
}
}
}

/* Publish to maven central */
plugins.withType<com.vanniktech.maven.publish.MavenPublishPlugin>().all {
extensions.configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.CENTRAL_PORTAL)
signAllPublications()
configure(KotlinMultiplatform(sourcesJar = true))

pom {
name = "Evas"
inceptionYear = "2024"
url = "https://github.com/sellmair/evas"
description = provider { project.description }

licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}

scm {
url = "https://github.com/sellmair/evas"
}

developers {
developer {
id = "sellmair"
name = "Sebastian Sellmair"
email = "sebastian@sellmair.io"
}
}
}
}
}
}
17 changes: 17 additions & 0 deletions dependencies.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[versions]
kotlin = "2.0.0"
androidGradlePlugin = "8.5.1"
compose = "1.6.11"
coroutines = "1.9.0-RC"
kotlinxBenchmark = "0.4.11"
ktor = "2.3.12"

[libraries]
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
kotlinxBenchmarkRuntime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinxBenchmark" }

ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktorClientCio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktorClientDarwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
3 changes: 1 addition & 2 deletions evas-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ plugins {
kotlin("plugin.compose")
id("org.jetbrains.compose")
id("org.jetbrains.kotlinx.binary-compatibility-validator")
`maven-publish`
com.vanniktech.maven.publish
`evas-publish`
}

description = "Compose (Multiplatform) extensions for evas"
Expand Down
9 changes: 4 additions & 5 deletions evas/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ plugins {
id("org.jetbrains.kotlinx.atomicfu")
org.jetbrains.kotlinx.`binary-compatibility-validator`
org.jetbrains.kotlinx.benchmark
`maven-publish`
com.vanniktech.maven.publish
`evas-publish`
}

description = "Events and States Library for Kotlin (Multiplatform)"
Expand Down Expand Up @@ -52,12 +51,12 @@ kotlin {
}

sourceSets.commonMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
implementation(deps.coroutines.core)
}

sourceSets.commonTest.dependencies {
implementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0-RC")
implementation(deps.coroutines.test)
}
}

Expand All @@ -69,7 +68,7 @@ run {
}

kotlin.sourceSets.getByName("jvmBenchmark").dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.11")
implementation(deps.kotlinxBenchmarkRuntime)
}

benchmark {
Expand Down
7 changes: 4 additions & 3 deletions samples/joke-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ kotlin {
implementation(compose.foundation)
implementation(compose.material)

implementation("io.ktor:ktor-client-core:$ktorClientVersion")
implementation(deps.ktorClientCore)
}

sourceSets.commonTest.dependencies {
Expand All @@ -49,11 +49,12 @@ kotlin {

sourceSets.jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation("io.ktor:ktor-client-cio:$ktorClientVersion")
implementation(deps.ktorClientCio)

}

sourceSets.appleMain.dependencies {
implementation("io.ktor:ktor-client-darwin:$ktorClientVersion")
implementation(deps.ktorClientDarwin)
}
}

Expand Down
10 changes: 5 additions & 5 deletions samples/login-screen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ kotlin {
implementation(compose.material)
implementation(compose.materialIconsExtended)

implementation("io.ktor:ktor-client-core:$ktorClientVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
implementation(deps.ktorClientCore)
implementation(deps.coroutines.core)
}

sourceSets.commonTest.dependencies {
Expand All @@ -49,13 +49,13 @@ kotlin {
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("io.ktor:ktor-client-cio:$ktorClientVersion")
implementation(deps.ktorClientCio)
}

sourceSets.jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation("io.ktor:ktor-client-cio:$ktorClientVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.0")
implementation(deps.coroutines.swing)
implementation(deps.ktorClientCio)
}

sourceSets.appleMain.dependencies {
Expand Down
Loading

0 comments on commit 5e0e834

Please sign in to comment.