Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change project build structure and use version catalog for storing dependencies #50

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
22 changes: 11 additions & 11 deletions akkurate-arrow/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import dev.nesk.akkurate.gradle.IgnoredTarget
import dev.nesk.akkurate.gradle.configureTargets

plugins {
id("akkurate.kmp-library-conventions")
id("akkurate.component.kmp-library")
id("akkurate.feature.publishing")
id("org.jetbrains.dokka")
}

kotlin {
configureTargets(
IgnoredTarget.ANDROID_NATIVE,
IgnoredTarget.WASM_JS,
IgnoredTarget.WASM_WASI,
IgnoredTarget.WATCHOS_DEVICE_ARM64
)
component {
ignoredTargets {
wasmJs()
wasmWasi()
watchosDeviceArm64()
androidNative()
}
}

kotlin {
sourceSets {
commonMain {
dependencies {
Expand Down
43 changes: 43 additions & 0 deletions akkurate-build-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
`kotlin-dsl`
}

group = "dev.nesk.akkurate"
version = "1.0"

kotlin {
// see https://docs.gradle.org/current/userguide/compatibility.html
coreLibrariesVersion = "2.0.20"
}

java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompilationTask<KotlinJvmCompilerOptions>>().configureEach {
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_1_8
jvmTarget = JvmTarget.JVM_1_8
}
}

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation(libs.kotlin.plugin)
implementation(libs.kotlin.symbolProcessing.plugin)
implementation(libs.dokka.plugin)
implementation(libs.kotlinSnapshot.plugin)
implementation(libs.ktor.plugin)
implementation(libs.kotlin.serialization.plugin)
implementation(libs.testLogger.plugin)
}
9 changes: 9 additions & 0 deletions akkurate-build-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "akkurate-build-conventions"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group = "dev.nesk.akkurate"
version = "0.11.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension

extensions.configure<KotlinTopLevelExtension> {
jvmToolchain(8)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@file:OptIn(ExperimentalWasmDsl::class)

import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl

plugins {
kotlin("multiplatform")
id("akkurate.base.identity")
id("akkurate.base.repositories")
id("akkurate.base.kotlin-compilation")
id("com.adarshr.test-logger")
}

extensions.create<KmpLibraryPluginExtension>("component").apply {
ignoredTargets.configureEach {
val ignoredTargetName = this
kotlin.targets.removeIf { it.targetName == ignoredTargetName }
}
}

kotlin {
explicitApi()

iosArm64()
iosSimulatorArm64()
iosX64()
js(IR) { nodejs() }
jvm()
linuxArm64()
linuxX64()
macosArm64()
macosX64()
mingwX64()
tvosArm64()
tvosSimulatorArm64()
tvosX64()
watchosArm32()
watchosArm64()
watchosSimulatorArm64()
watchosX64()
androidNativeArm32()
androidNativeArm64()
androidNativeX86()
androidNativeX64()
wasmJs { nodejs() }
wasmWasi { nodejs() }
watchosDeviceArm64()

sourceSets {
all {
languageSettings {
// See: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#language-settings
languageVersion = "1.9"
apiVersion = "1.9"
}
}

commonTest {
dependencies {
implementation(kotlin("test"))
}
}
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

interface KmpLibraryPluginExtension {
val ignoredTargets: DomainObjectSet<String>

@Suppress("unused")
fun ignoredTargets(block: KmpLibraryTargetsScope.() -> Unit) {
object : KmpLibraryTargetsScope {
override fun wasmJs() {
ignoredTargets.add("wasmJs")
}

override fun wasmWasi() {
ignoredTargets.add("wasmWasi")
}

override fun androidNative() {
ignoredTargets.addAll(
listOf(
"androidNativeArm32",
"androidNativeArm64",
"androidNativeX86",
"androidNativeX64",
)
)
}

override fun watchosDeviceArm64() {
ignoredTargets.add("watchosDeviceArm64")
}
}.block()
}
}

interface KmpLibraryTargetsScope {
fun wasmJs()
fun wasmWasi()
fun androidNative()
fun watchosDeviceArm64()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("jvm")
id("akkurate.base.identity")
id("akkurate.base.repositories")
id("akkurate.base.kotlin-compilation")
id("com.adarshr.test-logger")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
kotlin("jvm")
id("akkurate.base.identity")
id("akkurate.base.repositories")
id("akkurate.base.kotlin-compilation")
id("com.adarshr.test-logger")
}

kotlin {
explicitApi()
}

tasks.test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import dev.nesk.akkurate.gradle.catalogVersion

plugins {
id("akkurate.base.repositories")
}

tasks.named<Wrapper>("wrapper") {
val expectedGradleVersion = project.catalogVersion(versionRef = "gradle-wrapper")
val actualGradleVersion = project.gradle.gradleVersion
validateDistributionUrl = expectedGradleVersion != actualGradleVersion
gradleVersion = expectedGradleVersion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("com.google.devtools.ksp")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
`maven-publish`
signing
}

// Create a Javadoc JAR
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier = "javadoc"
}

ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
ext["sonatypeUsername"] = System.getenv("SONATYPE_USERNAME")
ext["sonatypePassword"] = System.getenv("SONATYPE_PASSWORD")

fun hasExtra(name: String) = ext[name] != null
fun getExtra(name: String) = ext[name]?.toString()

publishing {
repositories {
maven {
name = "sonatype"
credentials {
username = getExtra("sonatypeUsername")
password = getExtra("sonatypePassword")
}

val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")
if (isSnapshot) {
setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
}
}

publications.withType<MavenPublication>().configureEach {
artifact(javadocJar.get())

pom {
name = "Akkurate"
description = "The expressive validation library for Kotlin"
url = "https://akkurate.dev"

licenses {
license {
name = "Apache License 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "nesk"
name = "Johann Pardanaud"
email = "[email protected]"
}
}
scm {
url = "https://github.com/nesk/akkurate"
}
}
}
}

if (hasExtra("signing.keyId") && hasExtra("signing.password") && hasExtra("signing.secretKeyRingFile")) {
signing {
sign(publishing.publications)
}
}

tasks.assemble { dependsOn(javadocJar) }

// Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies
// https://youtrack.jetbrains.com/issue/KT-46466#focus=Comments-27-6349423.0-0
val signingTasks = tasks.withType<Sign>()
tasks.withType<AbstractPublishToMaven>().configureEach { mustRunAfter(signingTasks) }
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,14 @@

package dev.nesk.akkurate.gradle

import org.gradle.api.publish.maven.MavenPublication
import com.google.devtools.ksp.gradle.KspGradleSubplugin
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import java.io.File

/**
* Configures artifact information requiter by Maven Central.
*/
fun MavenPublication.configurePom() {
pom {
name.set("Akkurate")
description.set("The expressive validation library for Kotlin")
url.set("https://akkurate.dev")

licenses {
license {
name.set("Apache License 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("nesk")
name.set("Johann Pardanaud")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/nesk/akkurate")
}
}
}
fun KotlinSourceSet.kspKotlinOutputDir(target: String): File {
return KspGradleSubplugin.getKspKotlinOutputDir(
project = project,
sourceSetName = name,
target = target,
)
}
Loading