Skip to content

Commit

Permalink
update project configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Dec 12, 2023
1 parent cf4acd1 commit 95ed1ed
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nl.littlerobots.vcu.plugin.versionCatalogUpdate
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
Expand All @@ -24,9 +24,20 @@ buildscript {
}
}


allprojects {
group = Config.artifactId
version = Config.versionName
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(Config.jvmTarget)
languageVersion.set(Config.kotlinVersion)
freeCompilerArgs.apply {
addAll(Config.jvmCompilerArgs)
}
optIn.addAll(Config.optIns.map { "-opt-in=$it" })
}
}
}

atomicfu {
Expand All @@ -44,22 +55,19 @@ subprojects {
}

tasks {
withType<AbstractDokkaTask> {
val className =
"org.jetbrains.kotlin.gradle.targets.native.internal.CInteropMetadataDependencyTransformationTask"

@Suppress("UNCHECKED_CAST")
val taskClass = Class.forName(className) as Class<Task>
parent?.subprojects?.forEach {
dependsOn(it.tasks.withType(taskClass))
}
withType<Test>().configureEach {
useJUnitPlatform()
filter { isFailOnNoMatchingTests = true }
}

register<org.gradle.jvm.tasks.Jar>("dokkaJavadocJar") {
dependsOn(dokkaJavadoc)
from(dokkaJavadoc.flatMap { it.outputDirectory })
archiveClassifier.set("javadoc")
}

register<org.gradle.jvm.tasks.Jar>("emptyJavadocJar") {
archiveClassifier.set("javadoc")
}
}
}

Expand Down Expand Up @@ -144,10 +152,8 @@ tasks {
distributionType = Wrapper.DistributionType.BIN
}
}
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
extensions.findByType<YarnRootExtension>()!!.run {
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
reportNewYarnLock = true
yarnLockAutoReplace = false
}
extensions.findByType<YarnRootExtension>()?.run {
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
reportNewYarnLock = true
yarnLockAutoReplace = false
}
12 changes: 10 additions & 2 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

object Config {

Expand All @@ -18,8 +19,14 @@ object Config {
const val majorRelease = 1
const val minorRelease = 3
const val patch = 0
const val versionName = "$majorRelease.$minorRelease.$patch"
const val postfix = ""
const val versionName = "$majorRelease.$minorRelease.$patch$postfix"

const val url = "https://github.com/respawn-app/kmputils"
const val licenseName = "The Apache Software License, Version 2.0"
const val licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.txt"
const val scmUrl = "https://github.com/respawn-app/kmmutils.git"
const val description = """A collection of Kotlin Multiplatform essentials"""
// kotlin

val optIns = listOf(
Expand All @@ -36,12 +43,13 @@ object Config {
addAll(compilerArgs)
add("-Xjvm-default=all") // enable all jvm optimizations
add("-Xcontext-receivers")
add("-Xstring-concat=inline")
addAll(optIns.map { "-opt-in=$it" })
}

val jvmTarget = JvmTarget.JVM_11
val javaVersion = JavaVersion.VERSION_11
val kotlinVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
val kotlinVersion = KotlinVersion.KOTLIN_1_9
const val compileSdk = 34
const val targetSdk = compileSdk
const val minSdk = 21
Expand Down
37 changes: 22 additions & 15 deletions buildSrc/src/main/kotlin/ConfigureAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project

fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
fun Project.configureAndroid(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) = commonExtension.apply {
compileSdk = Config.compileSdk
// val libs by versionCatalog

defaultConfig {
minSdk = Config.minSdk
testInstrumentationRunner = Config.testRunner
Expand Down Expand Up @@ -42,13 +46,11 @@ fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
}

packaging {
resources {
excludes += setOf(
"DebugProbesKt.bin",
"/META-INF/{AL2.0,LGPL2.1}",
"/META-INF/versions/9/previous-compilation-data.bin"
)
}
resources.excludes += listOf(
"/META-INF/{AL2.0,LGPL2.1}",
"DebugProbesKt.bin",
"META-INF/versions/9/previous-compilation-data.bin"
)
}

testOptions {
Expand All @@ -64,13 +66,22 @@ fun CommonExtension<*, *, *, *, *, *>.configureAndroid() {
}
}
}

// composeOptions {
// kotlinCompilerExtensionVersion = libs.requireVersion("compose-compiler")
// useLiveLiterals = true
// }
}

fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
configureAndroid()
configureAndroid(this)

testFixtures {
enable = true
}

kotlinOptions {
freeCompilerArgs += "-Xexplicit-api=strict"
defaultConfig {
consumerProguardFiles(file(Config.consumerProguardFile))
}

buildTypes {
Expand All @@ -82,10 +93,6 @@ fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
}
}

defaultConfig {
consumerProguardFiles(file(Config.consumerProguardFile))
}

libraryVariants.all {
sourceSets {
getByName(name) {
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ fun Project.configureMultiplatform(

if (jvm) jvm()

if (iOs) {
sequence {
if (iOs) {
yield(iosX64())
Expand Down Expand Up @@ -69,7 +68,6 @@ fun Project.configureMultiplatform(
binaryOption("bundleVersion", Config.versionName)
baseName = Config.artifactId
}
}
}

sourceSets.apply {
Expand Down
31 changes: 14 additions & 17 deletions buildSrc/src/main/kotlin/ConfigurePublication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.maybeCreate
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.Sign

Expand All @@ -17,51 +18,47 @@ import org.gradle.plugins.signing.Sign
fun Project.publishMultiplatform() {
val properties by localProperties
val isReleaseBuild = properties["release"]?.toString().toBoolean()
val javadocJar = tasks.named("dokkaJavadocJar")

val javadocTask = tasks.named("emptyJavadocJar") // TODO: dokka does not support kmp javadocs yet

afterEvaluate {
requireNotNull(extensions.findByType<PublishingExtension>()).apply {
sonatypeRepository(isReleaseBuild, properties)

publications.withType<MavenPublication>().configureEach {
artifact(javadocJar)
artifact(javadocTask)
configurePom()
configureVersion(isReleaseBuild)
}
}
signPublications(properties)
signPublications(isReleaseBuild, properties)
}

tasks.withType<AbstractPublishToMaven> {
dependsOn(javadocJar)
dependsOn(javadocTask)
}
}

/**
* Publish the android artifact
*/
fun Project.publishAndroid() {
val properties by localProperties
requireNotNull(extensions.findByType<LibraryExtension>()).apply {
publishing {
singleVariant(Config.publishingVariant) {
withSourcesJar()
withJavadocJar()
}
}
testFixtures {
enable = true
fun Project.publishAndroid(ext: LibraryExtension) = with(ext) {
publishing {
singleVariant(Config.publishingVariant) {
withSourcesJar()
withJavadocJar()
}
}

afterEvaluate {
val properties by localProperties
val isReleaseBuild = properties["release"]?.toString().toBoolean()

requireNotNull(extensions.findByType<PublishingExtension>()).apply {
sonatypeRepository(isReleaseBuild, properties)

publications {
create(Config.publishingVariant, MavenPublication::class.java) {
maybeCreate(Config.publishingVariant, MavenPublication::class).apply {
from(components[Config.publishingVariant])
suppressPomMetadataWarningsFor(Config.publishingVariant)
groupId = rootProject.group.toString()
Expand All @@ -72,7 +69,7 @@ fun Project.publishAndroid() {
}
}
}
signPublications(properties)
signPublications(isReleaseBuild, properties)
}

tasks.withType<Sign>().configureEach {
Expand Down
30 changes: 13 additions & 17 deletions buildSrc/src/main/kotlin/PublishingExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ internal fun MavenPublication.configureVersion(release: Boolean) {

internal fun MavenPublication.configurePom() = pom {
name.set(Config.artifact)
description.set("A collection of Kotlin Multiplatform essentials")
url.set("https://github.com/respawn-app/kmmutils")
description.set(Config.description)
url.set(Config.url)

licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
name.set(Config.licenseName)
url.set(Config.licenseUrl)
distribution.set("repo")
}
}
Expand All @@ -40,12 +40,10 @@ internal fun MavenPublication.configurePom() = pom {
organizationUrl.set(url)
}
}
scm {
url.set("https://github.com/respawn-app/kmmutils.git")
}
scm { url.set(Config.scmUrl) }
}

internal fun PublishingExtension.sonatypeRepository(release: Boolean, properties: Properties) = repositories {
internal fun PublishingExtension.sonatypeRepository(release: Boolean, localProps: Properties) = repositories {
maven {
name = "sonatype"
url = URI(
Expand All @@ -56,22 +54,20 @@ internal fun PublishingExtension.sonatypeRepository(release: Boolean, properties
}
)
credentials {
username = properties["sonatypeUsername"]?.toString()
password = properties["sonatypePassword"]?.toString()
username = localProps["sonatypeUsername"]?.toString()
password = localProps["sonatypePassword"]?.toString()
}
}
}

internal fun Project.signPublications(properties: Properties) =
internal fun Project.signPublications(isRelease: Boolean, localProps: Properties) =
requireNotNull(extensions.findByType<SigningExtension>()).apply {
val isReleaseBuild = properties["release"]?.toString().toBoolean()

val publishing = requireNotNull(extensions.findByType<PublishingExtension>())

val signingKey: String? = properties["signing.key"]?.toString()
val signingPassword: String? = properties["signing.password"]?.toString()
val signingKey: String? = localProps["signing.key"]?.toString()
val signingPassword: String? = localProps["signing.password"]?.toString()

isRequired = isReleaseBuild
isRequired = isRelease

if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
Expand All @@ -81,7 +77,7 @@ internal fun Project.signPublications(properties: Properties) =

tasks.run {
withType<Sign>().configureEach {
onlyIf { isReleaseBuild }
onlyIf { isRelease }
}

withType<AbstractPublishToMaven>().configureEach {
Expand Down
8 changes: 0 additions & 8 deletions buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
"UndocumentedPublicFunction"
)

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.getByType
import org.gradle.plugin.use.PluginDependency
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.io.File
import java.io.FileInputStream
import java.util.Base64
Expand All @@ -34,13 +31,8 @@ fun VersionCatalog.requirePlugin(alias: String) = findPlugin(alias).get().toStri
fun VersionCatalog.requireLib(alias: String) = findLibrary(alias).get()
fun VersionCatalog.requireBundle(alias: String) = findBundle(alias).get()
fun VersionCatalog.requireVersion(alias: String) = findVersion(alias).get().toString()

val org.gradle.api.provider.Provider<PluginDependency>.id: String get() = get().pluginId

fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}

/**
* Creates a java array initializer code for a list of strings.
* Example: { "a", "b", "c" }
Expand Down
Loading

0 comments on commit 95ed1ed

Please sign in to comment.