Skip to content

Commit

Permalink
Layout rework
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetuska committed Apr 30, 2023
1 parent 1f58e2b commit fb87795
Show file tree
Hide file tree
Showing 122 changed files with 1,134 additions and 1,014 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os:
- runner: macos-11
- runner: macos-latest
shell: bash
- runner: ubuntu-latest
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=11.0.2-open
java=11.0.19-tem
62 changes: 37 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
# 2.0.0

## Changes

- Migrated to gradle version catalogs
- New kotlin target layout following support tiers and using `targetHierarchy`
- `local.properties` is now also respected at the module level and overrides root project
level `local.properties`
- New `wasm` target support
- Streamlined build host control

# 1.1.4

## Changes

* Back to spotless + ktlint
* Fixed GH actions issues with runners
* `local.properties` support
* Custom refreshVersions rules setup
* `.sdkmanrc` for easier local env setup
* Version bumps ([email protected], [email protected])
- Back to spotless + ktlint
- Fixed GH actions issues with runners
- `local.properties` support
- Custom refreshVersions rules setup
- `.sdkmanrc` for easier local env setup
- Version bumps ([email protected], [email protected])

# 1.1.3

## Changes

* Swapped out ktlint for spotless + ktfmt
* Disabling git hooks on CI
* Added android support
- Swapped out ktlint for spotless + ktfmt
- Disabling git hooks on CI
- Added android support

# 1.1.2

## Changes

* Removed incorrect hashed imports from gradle scripts
* Bumped versions
* Introduced nativeMain and nativeTest sourceSets
* Added BlockingTest utility interface
* Removed snapshot repository support
* macosArm64() target added
* iosSimulatorArm64() target added
* watchosSimulatorArm64() target added
* tvosSimulatorArm64() target added
- Removed incorrect hashed imports from gradle scripts
- Bumped versions
- Introduced nativeMain and nativeTest sourceSets
- Added BlockingTest utility interface
- Removed snapshot repository support
- macosArm64() target added
- iosSimulatorArm64() target added
- watchosSimulatorArm64() target added
- tvosSimulatorArm64() target added

# 1.1.1

## Changes

* Stricter publication and test control to avoid duplicate builds on matrix jobs
* Reworked gradle precompiled script plugins to better separate different functionalities
* Sandbox GH action to quickly check gradle scripts on different hosts
* Added baseline flow for setting up required native libraries on different CI hosts via [scripts/] directory
* Native library caching for check and release actions
* Upgraded versions
* Fixed detekt issues
- Stricter publication and test control to avoid duplicate builds on matrix jobs
- Reworked gradle precompiled script plugins to better separate different functionalities
- Sandbox GH action to quickly check gradle scripts on different hosts
- Added baseline flow for setting up required native libraries on different CI hosts via [scripts/]
directory
- Native library caching for check and release actions
- Upgraded versions
- Fixed detekt issues
59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,39 @@ except deprecated wasm32.
## Features

* Native target grouping and shared sourceSets
* Wrapper library module that declares dependencies on all lib modules
* Uniform configuration via conventional plugins `plugin.common`, `plugin.library-mpp` & `plugin.publishing-mpp`
* Local `test` module for shared test utilities (a helper function to run coroutine tests in common sourceSet included)
* Wrapper library module that declares dependencies on all library modules
* Uniform configuration via convention
plugins `convention.base`, `convention.library-mpp`, `convention.library-android` & `convention.publishing-mpp`
* Incremental kotlin target sets following support tiers
* Separation of source and tests to allow for lower support tier sources, being tested by higher and
more supported tier test module
* Local `sandbox` module for easy library consumer side checks
* Publication control to avoid multiple publications for targets that can be built on multiple hosts
* `ktlint` plugin with automatic `git-hooks`
* `refreshVersions` plugin for better library version control
* `detekt` plugin with automatic `git-hooks`
* Main host for publications can be changed via `gradle.properties#project.mainOS` property
* Gradle Build Scan setup
* Gradle version catalog with easy updates `./gradlew versionCatalogUpdate`
* GH dependabot setup
* GH release action for platform dependant publications
* GH check action for platform dependant tests on PRs
* Maven Central publishing setup
* GH Packages publishing setup
* `SDKMAN` support for local env (`sdk man env install` to get the required JDM and `sdkman env` to switch to it)
* `SDKMAN` support for local env (`sdk man env install` to get the required JDM and `sdkman env` to
switch to it)

## Setup

Here are some pointers to help you get up and running with this template

### Badges

This README contains some useful badges for your project. To tailor them to your artefacts the following changes needs
This README contains some useful badges for your project. To tailor them to your artefacts the
following changes needs
to be made:

* `Dokka docs` - change the link as `(http://$GH_USERNAME.github.io/$GH_PROJECT_NAME)`
* `Version maven-central` - change all occurrences of `dev.petuska` to your own group and `template-kmp-library` to your
* `Version maven-central` - change all occurrences of `dev.petuska` to your own group
and `template-kmp-library` to your
root library name

### gradle.properties
Expand All @@ -48,28 +54,45 @@ Have a look at `gradle.properties` file and change these properties as needed
* `gh.owner.id` - main library developer's username
* `gh.owner.name` - main library developer's name
* `gh.owner.email` - main library developer's email
* `project.mainOS` - main host to publish cross-platform artefacts from (to avoid duplicate publications)
* `project.mainOS` - main host to publish cross-platform artefacts from (to avoid duplicate
publications). Supported values are `linux`, `windows`, `macosX64` & `macosArm64`. Note that some
mac targets can be compiled on all architectures and are set to require `macosX64` by default.
This can be changed in [./build-conventions/src/main/kotlin/util/buildHost.kt].
* `group` - artefacts' group
* `description` - library description
* `version` - library version (overridden in CI, so doesn't really matter here)

### Modules

All the library modules should go to [./lib] directory and be included in [./settings.gradle.kts]. There are already two
sample modules to illustrate how simple the setup is ([./lib/template-kmp-library-core] & [./lib/template-kmp-library-dsl]).
They both contain some sample code and tests that make use of local [./test] module with testing utilities.
All the library modules should go to [./modules] directory and be included
in [./settings.gradle.kts].
There are already two sample modules to illustrate how simple the setup
is - [./modules/template-kmp-library-core] & [./modules/template-kmp-library-dsl].
They both contain some sample code and tests
in [./tests/template-kmp-library-core-tests] & [./tests/template-kmp-library-dsl-tests]

### Kotlin Targets

The template comes packed with all kotlin targets preconfigured, however if you want to remove some of them or tweak the
config, you only need to make changes as needed in [./buildSrc/src/main/kotlin/plugin.library-mpp.gradle.kts]. Removing
targets from this file will not break any publications as they're configured on top of pre-registered targets.
The template comes packed with all kotlin targets preconfigured and grouped by support tiers
controlled by a set of plugins. Lower tier plugins apply all of the higher tier plugins so you
should only ever need to pick one.

- `convention.kotlin-mpp-tier0`
- `convention.kotlin-mpp-tier1`
- `convention.kotlin-mpp-tier2`
- `convention.kotlin-mpp-tier3`

Changing tiers will not break any publications as they're configured on top of pre-registered
targets.

### GitHub Actions

The template also comes with GH actions to check builds on PRs and publish artefacts when creating a GH release. By
default, it'll publish to GH packages and Maven Central. However, to fully unlock Maven Central publishing, you'll need
to add these secrets to your GH repository. If you want to quickly disable Maven Central publishing, you can toggle it
The template also comes with GH actions to check builds on PRs and publish artefacts when creating a
GH release. By
default, it'll publish to GH packages and Maven Central. However, to fully unlock Maven Central
publishing, you'll need
to add these secrets to your GH repository. If you want to quickly disable Maven Central publishing,
you can toggle it
at [./.github/workflows/release.yml#L80]`

* `SIGNING_KEY` - GPG signing key
Expand Down
30 changes: 30 additions & 0 deletions build-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
google()
mavenCentral()
}

dependencies {
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))

implementation(libs.plugin.kotlin)
implementation(libs.plugin.kotlin.serialization)
implementation(libs.plugin.android)
implementation(libs.plugin.git.hooks)
implementation(libs.plugin.detekt)
implementation(libs.plugin.dokka)
implementation(libs.plugin.versions)
implementation(libs.plugin.versions.update)
implementation(libs.plugin.container.tasks)
}

gradleEnterprise {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
1 change: 1 addition & 0 deletions build-conventions/gradle
23 changes: 23 additions & 0 deletions build-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}

plugins {
id("com.gradle.enterprise") version "3.13"
}

@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
}

enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
17 changes: 17 additions & 0 deletions build-conventions/src/main/kotlin/convention.base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
idea
id("convention.local-properties")
}

idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}

repositories {
mavenCentral()
google()
mavenLocal()
}
28 changes: 28 additions & 0 deletions build-conventions/src/main/kotlin/convention.detekt.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import io.gitlab.arturbosch.detekt.Detekt

plugins {
id("convention.base")
id("io.gitlab.arturbosch.detekt")
}

dependencies {
detektPlugins(libs.detekt.formatting)
}

detekt {
config.from(rootDir.resolve("gradle/detekt.yml"))
buildUponDefaultConfig = true
}

tasks.withType<Detekt> {
reports {
// observe findings in your browser with structure and code snippets
html.required.set(true)
// checkstyle like format mainly for integrations like Jenkins
xml.required.set(true)
// similar to the console output, contains issue signature to manually edit baseline files
txt.required.set(true)
// standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with Github Code Scanning
sarif.required.set(true)
}
}
13 changes: 13 additions & 0 deletions build-conventions/src/main/kotlin/convention.git-hooks.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
id("convention.base")
id("com.github.jakemarsden.git-hooks") apply (System.getenv("CI") !in arrayOf(null, "0", "false", "n", "N"))
}

gitHooks {
setHooks(
mapOf(
"pre-commit" to "detekt --auto-correct",
"pre-push" to "detekt"
)
)
}
27 changes: 27 additions & 0 deletions build-conventions/src/main/kotlin/convention.jvm.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import com.android.build.gradle.LibraryExtension

plugins {
id("convention.base")
`java-base`
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(libs.versions.java.get().toInt()))
}
}

plugins.withId("com.android.library") {
configure<LibraryExtension> {
compileOptions {
sourceCompatibility = JavaVersion.toVersion(libs.versions.java.get())
targetCompatibility = sourceCompatibility
}
}
}

tasks {
withType<Test> {
useJUnitPlatform()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

plugins {
id("convention.jvm")
id("convention.kotlin-mpp")
}

plugins.withId("com.android.library") {
configure<KotlinMultiplatformExtension> {
android()
}
}

kotlin {
js {
useCommonJs()
browser {
commonWebpackConfig {
cssSupport { enabled.set(true) }
scssSupport { enabled.set(true) }
}
testTask { useKarma() }
}
}

jvm()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("convention.kotlin-mpp-tier0")
}

// https://kotlinlang.org/docs/native-target-support.html#tier-1
kotlin {
linuxX64()

macosX64()
macosArm64()

iosX64()
iosSimulatorArm64()
}
Loading

0 comments on commit fb87795

Please sign in to comment.