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

V 2.0.0 #61

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[*.{kt,kts}]
ktlint_code_style = ktlint_official
[*.{kt,kts,gradle}]
ktlint_code_style = ktlint_official
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_allow_trailing_comma = true
7 changes: 5 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ plugins {
}

kotlin {
jvmToolchain(libs.versions.java.get().toInt())
jvmToolchain(
libs.versions.java
.get()
.toInt(),
)
}

repositories {
Expand Down Expand Up @@ -34,7 +38,6 @@ dependencies {
implementation(libs.kover.badge.gradlePlugin)
implementation(libs.dokka.gradlePlugin)
implementation(libs.detekt.gradlePlugin)
implementation(libs.shadow.gradlePlugin)
implementation(libs.gradle.release.gradlePlugin)

testImplementation(libs.kotest.runner.junit5)
Expand Down
30 changes: 11 additions & 19 deletions buildSrc/src/main/kotlin/io/github/flaxoos/ktor/Conventions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import org.gradle.kotlin.dsl.withGroovyBuilder
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.kpm.external.ExternalVariantApi
import org.jetbrains.kotlin.gradle.kpm.external.project
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.utils.named

open class Conventions : Plugin<Project> {
open fun KotlinMultiplatformExtension.conventionSpecifics() {}
open fun KotlinMultiplatformExtension.conventionSpecifics(project: Project) {}

override fun apply(project: Project) {
with(project) {
with(plugins) {
Expand All @@ -52,6 +52,7 @@ open class Conventions : Plugin<Project> {
apply(project.plugin("ktlint"))
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/flaxoos/flax-gradle-plugins")
Expand All @@ -61,15 +62,14 @@ open class Conventions : Plugin<Project> {
enableContextReceivers()

extensions.findByType(KotlinMultiplatformExtension::class)?.apply {
targetJvm()
targetJvm(project)
this.sourceSets.apply {
commonMainDependencies {
implementation(library("kotlinx-datetime"))
implementation(library("kotlinx-coroutines-core"))
implementation(library("arrow-core"))
implementation(library("arrow-fx-coroutines"))
implementation(library("kotlin-logging"))

}

commonTestDependencies {
Expand All @@ -90,7 +90,7 @@ open class Conventions : Plugin<Project> {
implementation(library("mockk-agent-jvm"))
}
}
this.conventionSpecifics()
this.conventionSpecifics(project)
}

setLanguageAndApiVersions()
Expand Down Expand Up @@ -149,7 +149,7 @@ open class Conventions : Plugin<Project> {
}

extensions.findByType(AtomicFUPluginExtension::class)?.apply {
dependenciesVersion = versionOf("atomicFu")
dependenciesVersion = versionOf("atomicfu")
transformJvm = true
jvmVariant = "FU"
}
Expand All @@ -164,14 +164,10 @@ open class Conventions : Plugin<Project> {
configurePublishing()
}
}


}

class KtorServerPluginConventions : Conventions() {

@OptIn(ExternalVariantApi::class)
override fun KotlinMultiplatformExtension.conventionSpecifics() {
override fun KotlinMultiplatformExtension.conventionSpecifics(project: Project) {
sourceSets.apply {
commonMainDependencies {
implementation(project.library("ktor-server-core"))
Expand All @@ -187,10 +183,8 @@ class KtorServerPluginConventions : Conventions() {
}

class KtorClientPluginConventions : Conventions() {

@OptIn(ExternalVariantApi::class)
override fun KotlinMultiplatformExtension.conventionSpecifics() {
with(this.project) {
override fun KotlinMultiplatformExtension.conventionSpecifics(project: Project) {
with(project) {
sourceSets.apply {
commonMainDependencies {
implementation(library("ktor-client-core"))
Expand Down Expand Up @@ -247,9 +241,7 @@ fun NamedDomainObjectCollection<KotlinSourceSet>.nativeTestDependencies(configur

private fun Project.ktorVersion() = versionOf("ktor")


fun Project.projectDependencies(configuration: DependencyHandlerScope.() -> Unit) =
DependencyHandlerScope.of(dependencies).configuration()
fun Project.projectDependencies(configuration: DependencyHandlerScope.() -> Unit) = DependencyHandlerScope.of(dependencies).configuration()

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER)
@Retention(AnnotationRetention.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.named
Expand All @@ -15,19 +16,21 @@ import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import java.util.Base64

private const val DOKKA = "dokka"
private const val DOKKA_JAR_TASK_NAME = "${DOKKA}Jar"

fun Project.configurePublishing() {
val dokkaJarTask = registerDokkaJarTask()
registerDokkaJarTask()
configureSigning()
configureMavenPublications(dokkaJarTask)

configureMavenPublications()
}

fun Project.registerDokkaJarTask() = tasks.register<Jar>("dokkaJar") {
val dokkaHtml = tasks.named<AbstractDokkaTask>("dokkaHtml")
archiveClassifier.set("javadoc")
from(dokkaHtml.get().outputDirectory)
}
fun Project.registerDokkaJarTask() =
tasks.register<Jar>(DOKKA_JAR_TASK_NAME) {
val dokkaHtml = tasks.named<AbstractDokkaTask>("${DOKKA}Html")
archiveClassifier.set("javadoc")
from(dokkaHtml.get().outputDirectory)
}

fun Project.configureSigning() {
tasks.withType<AbstractPublishToMaven>().configureEach {
Expand All @@ -40,40 +43,46 @@ fun Project.configureSigning() {
}
}

fun Project.configureMavenPublications(dokkaJar: TaskProvider<Jar>) {
the<PublishingExtension>().apply {
publications.withType<MavenPublication> {
artifact(dokkaJar)
pom {
name.set("${rootProject.name}: ${project.name}")
groupId = project.group.toString()
version = project.version.toString()
url.set("https://github.com/Flaxoos/extra-ktor-plugins")
inceptionYear.set("2023")
description.set(
"This project provides a suite of feature-rich, efficient, and highly customizable " + "plugins for your Ktor Server or Client, crafted in Kotlin, available for multiplatform."
)
scm {
connection.set("scm:git:https://github.com/Flaxoos/extra-ktor-plugins.git")
developerConnection.set("scm:git:https://github.com/Flaxoos/extra-ktor-plugins.git")
fun Project.configureMavenPublications() {
afterEvaluate {
the<PublishingExtension>().apply {
publications.withType<MavenPublication> {
artifact(tasks.dokkaJar)
pom {
name.set("${rootProject.name}: ${project.name}")
groupId = project.group.toString()
version = project.version.toString()
url.set("https://github.com/Flaxoos/extra-ktor-plugins")
}
inceptionYear.set("2023")
description.set(
"This project provides a suite of feature-rich, efficient, and highly customizable " +
"plugins for your Ktor Server or Client, crafted in Kotlin, available for multiplatform.",
)
scm {
connection.set("scm:git:https://github.com/Flaxoos/extra-ktor-plugins.git")
developerConnection.set("scm:git:https://github.com/Flaxoos/extra-ktor-plugins.git")
url.set("https://github.com/Flaxoos/extra-ktor-plugins")
}

licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://opensource.org/license/mit/")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://opensource.org/license/mit/")
}
}
}

developers {
developer {
id.set("flaxoos")
name.set("Ido Flax")
email.set("[email protected]")
developers {
developer {
id.set("flaxoos")
name.set("Ido Flax")
email.set("[email protected]")
}
}
}
}
}
}
}
}

val TaskContainer.dokkaJar: TaskProvider<Jar>
get() = named(DOKKA_JAR_TASK_NAME, Jar::class)
Original file line number Diff line number Diff line change
@@ -1,50 +1,18 @@
package io.github.flaxoos.ktor.extensions

import org.gradle.api.file.DuplicatesStrategy
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests

fun KotlinMultiplatformExtension.targetNative(
configure: KotlinNativeTargetWithHostTests.() -> Unit = {},
// hardTarget: (KotlinMultiplatformExtension.() -> KotlinNativeTargetWithHostTests)? = null
) {
// val hostOs = System.getProperty("os.name")
// val arch = System.getProperty("os.arch")
// val nativeTarget = hardTarget?.let { this.hardTarget() } ?: when {
// hostOs == "Mac OS X" && arch == "x86_64" -> macosX64("native")
// hostOs == "Mac OS X" && arch == "aarch64" -> macosArm64("native")
// hostOs == "Linux" -> linuxX64("native")
// // Other supported targets are listed here: https://ktor.io/docs/native-server.html#targets
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
// }
fun KotlinMultiplatformExtension.targetNative(configure: KotlinNativeTargetWithHostTests.() -> Unit = {}) {
val nativeTarget = linuxX64("native")
nativeTarget.apply {
binaries.sharedLib()
configure()
}
}


fun KotlinMultiplatformExtension.targetJvm() {
jvm {
jvmToolchain(project.versionOf("java").toInt())
project.tasks.named("jvmJar", Jar::class).configure {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(
listOf(
project.configurations["jvmCompileClasspath"],
project.configurations["jvmRuntimeClasspath"],
).map { config ->
config.map {
if (it.isDirectory) it
else project.zipTree(it)
}
},
)
}
}
fun KotlinMultiplatformExtension.targetJvm(project: Project) {
jvmToolchain(project.versionOf("java").toInt())
jvm()
}

11 changes: 6 additions & 5 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import io.github.flaxoos.ktor.extensions.configureMavenPublications
import io.github.flaxoos.ktor.extensions.configurePublishing
import io.github.flaxoos.ktor.extensions.configureSigning
import io.github.flaxoos.ktor.extensions.registerDokkaJarTask
import io.github.flaxoos.ktor.extensions.targetJvm
import io.github.flaxoos.ktor.extensions.targetNative

plugins {
kotlin("multiplatform")
`maven-publish`
id("signing")
id(libs.plugins.dokka.get().pluginId)
id(
libs.plugins.dokka
.get()
.pluginId,
)
}

kotlin {
targetJvm()
targetJvm(project)
targetNative()
macosArm64("native-macos") {
binaries {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ github.repository.name=extra-ktor-plugins
kotlin.native.cacheKind.linuxX64=none
kotlin.native.ignoreDisabledTargets=true
gradle.publish.enable.module-metadata=true
version=1.2.10
version=2.0.0
gpr.user=flaxoos
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=2g
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=2g
kotlin.mpp.applyDefaultHierarchyTemplate=false
Loading
Loading