Skip to content

Commit

Permalink
Added build-logic module
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Aug 27, 2024
1 parent 1eb5f52 commit 4fb4be1
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 201 deletions.
17 changes: 17 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation(Kotlin.stdlib)
implementation(Kotlin.gradlePlugin)

implementation("com.mooncloak.kodetools.kenv:kenv-core:_")
}

gradlePlugin {
plugins.register("parcelable.variables") {
id = "parcelable.variables"
implementationClass = "BuildVariablesPlugin"
}
}
28 changes: 28 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://plugins.gradle.org/m2/")
mavenCentral()
google()
}
}

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
google()
gradlePluginPortal()
maven("https://repo.repsy.io/mvn/mooncloak/public")
}
}

plugins {
// This is the plugin we use to handle our dependency versions. See the versions.properties file for the latest versions.
// See https://jmfayard.github.io/refreshVersions
id("de.fayard.refreshVersions") version "0.60.5"

// See root build.gradle.kts file for the rest of the plugins applied.
}

rootProject.name = "build-logic"
48 changes: 48 additions & 0 deletions build-logic/src/main/kotlin/BuildVariablesPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import com.mooncloak.kodetools.kenv.Kenv
import com.mooncloak.kodetools.kenv.properties
import org.gradle.api.Plugin
import org.gradle.api.Project

abstract class BuildVariablesPlugin : Plugin<Project> {

override fun apply(target: Project) {
projectBuildVariables[target.name] = BuildVariables(
kenv = Kenv {
system()
properties(file = target.rootProject.layout.projectDirectory.file("library.properties").asFile)
}
)
}
}

class BuildVariables internal constructor(
private val kenv: Kenv
) {

val group: String
get() = kenv["group"].value

val version: String
get() = kenv["version"].value

val versionCode: Int
get() = TODO("Use git commit count.")
}

val Project.buildVariables: BuildVariables
get() {
var variables = projectBuildVariables[this.name]

if (variables == null) {
this.logger.warn("The '${BuildVariablesPlugin::class.simpleName}' was not applied to project with name '${this.name}'. Attempting to load root project build variables.")
}

if (this != this.rootProject) {
variables = projectBuildVariables[this.rootProject.name]
}

return variables
?: error("Failed to load required build variables. Make sure the '${BuildVariablesPlugin::class.simpleName}' is applied to the project.")
}

private val projectBuildVariables = mutableMapOf<String, BuildVariables>()
11 changes: 11 additions & 0 deletions build-logic/src/main/kotlin/LibraryConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:Suppress("MemberVisibilityCanBePrivate")

object LibraryConstants {

object Android {

const val compileSdkVersion = 34
const val minSdkVersion = 21
const val targetSdkVersion = 34
}
}
109 changes: 109 additions & 0 deletions build-logic/src/main/kotlin/parcelable.multiplatform.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinTest

plugins {
kotlin("multiplatform")
}

kotlin {
applyDefaultHierarchyTemplate()

js {
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}

binaries.executable()
}

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}

binaries.executable()
}

//@OptIn(ExperimentalWasmDsl::class)
// TODO: Re-enable when library supports WASI: wasmWasi()

linuxArm64()
linuxX64()

mingwX64()

macosX64()
macosArm64()

iosArm64()
iosX64()
iosSimulatorArm64()

tvosArm64()
tvosX64()
tvosSimulatorArm64()

watchosArm32()
watchosArm64()
watchosX64()
watchosSimulatorArm64()

androidTarget {
publishAllLibraryVariants()
}

jvm()

explicitApi()

// Ensure xml test reports are generated
tasks.named("jvmTest", Test::class).configure {
reports.junitXml.required.set(true)
}
}

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

tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget = JvmTarget.JVM_11
}

tasks.withType<KotlinTest> {
if (targetName == "tvosSimulatorArm64" || targetName == "watchosSimulatorArm64") {
enabled = false
}
}

// Don't run npm install scripts, protects against
// https://blog.jetbrains.com/kotlin/2021/10/important-ua-parser-js-exploit-and-kotlin-js/ etc.
tasks.withType<KotlinNpmInstallTask> {
args += "--ignore-scripts"
}

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
118 changes: 118 additions & 0 deletions build-logic/src/main/kotlin/parcelable.publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
plugins {
`maven-publish`
signing
}

version = rootProject.version
group = rootProject.group

afterEvaluate {
publishing {
repositories {
maven { // TODO: Update to use mavenCentral
url = uri("https://repo.repsy.io/mvn/chrynan/public")

credentials {
username = (project.findProperty("repsyUsername")
?: System.getenv("repsyUsername")) as? String

password = (project.findProperty("repsyPassword")
?: System.getenv("repsyPassword")) as? String
}
}
}

if (plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
// already has publications, just need to add javadoc task
val javadocJar by tasks.creating(Jar::class) {
from("javadoc")
archiveClassifier.set("javadoc")
}

publications.all {
if (this is MavenPublication) {
artifact(javadocJar)
mavenCentralPom()
}
}

// create task to publish all apple (macos, ios, tvos, watchos) artifacts
val publishApple by tasks.registering {
publications.all {
if (name.contains(Regex("macos|ios|tvos|watchos"))) {
val publicationNameForTask = name.replaceFirstChar(Char::uppercase)
dependsOn("publish${publicationNameForTask}PublicationToSonatypeRepository")
}
}
}
} else {
// Need to create source, javadoc & publication
val java = extensions.getByType<JavaPluginExtension>()

java.withSourcesJar()
java.withJavadocJar()

publications {
create<MavenPublication>("lib") {
from(components["java"])
mavenCentralPom()
}
}
}
}
}

fun MavenPublication.mavenCentralPom() {
pom {
name.set("serialization-parcelable")
description.set("Android Parcelable support for the Kotlinx Serialization library.")
url.set("https://github.com/chRyNaN/serialization-parcelable")

organization {
url.set("https://chrynan.codes")
name.set("chRyNaN")
}

issueManagement {
url.set("https://github.com/chRyNaN/serialization-parcelable/issues")
system.set("Github Issues")
}

licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}

developers {
developer {
id.set("ckeenan")
name.set("Chris Keenan")
url.set("https://github.com/chRyNaN")
roles.set(setOf("Primary serialization-parcelable developer. 💪"))
}
}

scm {
connection.set("https://github.com/chRyNaN/serialization-parcelable.git")
developerConnection.set("https://github.com/chRyNaN/serialization-parcelable.git")
url.set("https://github.com/chRyNaN/serialization-parcelable")
}
}
}

signing {
setRequired {
findProperty("signing.keyId") != null
}

publishing.publications.all {
sign(this)
}
}

// TODO: remove after https://youtrack.jetbrains.com/issue/KT-46466 is fixed
project.tasks.withType(AbstractPublishToMaven::class.java).configureEach {
dependsOn(project.tasks.withType(Sign::class.java))
}
12 changes: 12 additions & 0 deletions build-logic/versions.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#### Dependencies and Plugin versions with their available updates.
#### Generated by `./gradlew refreshVersions` version 0.60.5
####
#### Don't manually edit or split the comments that start with four hashtags (####),
#### they will be overwritten by refreshVersions.
####
#### suppress inspection "SpellCheckingInspection" for whole file
#### suppress inspection "UnusedProperty" for whole file

version.com.mooncloak.kodetools.kenv..kenv-core=1.2.0

version.kotlin=2.0.20
29 changes: 4 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import com.chrynan.parcelable.buildSrc.LibraryConstants

group = LibraryConstants.group
version = LibraryConstants.versionName

plugins {
kotlin("jvm") version "2.0.20" apply false
kotlin("multiplatform") version "2.0.20" apply false
Expand All @@ -15,29 +10,13 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
id("com.vanniktech.dependency.graph.generator") version "0.7.0"
}

allprojects {
repositories {
google()
mavenCentral()
maven { url = uri("https://repo.repsy.io/mvn/chrynan/public") }
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
}
}

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin::class.java) {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().yarnLockMismatchReport =
org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport.WARNING // NONE | FAIL
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().reportNewYarnLock = false // true
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().yarnLockAutoReplace = false // true
}

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
id("parcelable.variables")
}

// Documentation
tasks.named<org.jetbrains.dokka.gradle.DokkaMultiModuleTask>("dokkaGfmMultiModule").configure {
outputDirectory.set(file("${projectDir.path}/docs"))
}

group = buildVariables.group
version = buildVariables.version
Loading

0 comments on commit 4fb4be1

Please sign in to comment.