Skip to content

Commit

Permalink
Adds a new :result module (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayShortway authored Feb 22, 2024
1 parent c05cb42 commit 8a91ec2
Show file tree
Hide file tree
Showing 17 changed files with 612 additions and 107 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build with Gradle Wrapper
run: ./gradlew assemble
- name: Build libraries
run: ./gradlew assemble -x :composeApp:assemble
- name: Build sample
run: ./gradlew :composeApp:assembleDebug

dependency-submission:
needs: build
Expand Down Expand Up @@ -87,11 +89,11 @@ jobs:
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Generate Dokkatoo site
run: ./gradlew dokkatooGenerate
run: ./gradlew :dokkatooGenerate
- name: Upload GitHub Pages artifact
uses: actions/[email protected]
with:
path: 'core/build/dokka/html'
path: 'build/dokka/html'

deploy-api-reference:
needs: generate-api-reference
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ jobs:
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle Wrapper
run: ./gradlew assemble
- name: Build libraries
run: ./gradlew assemble -x :composeApp:assemble
- name: Build sample
run: ./gradlew :composeApp:assembleDebug
1 change: 1 addition & 0 deletions build-logic/convention/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

group = "io.shortway.kobankat.buildlogic"

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
}

gradlePlugin {
plugins {
register("Library") {
id = "kobankat.library"
implementationClass = "io.shortway.kobankat.buildlogic.plugin.LibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.shortway.kobankat.buildlogic.ktx

import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionConstraint

internal fun VersionCatalog.getVersion(alias: String): String =
findVersion(alias).get().version

/**
* Uses the same logic as VersionFactory.doGetVersion().
*/
internal val VersionConstraint.version: String
get() = requiredVersion.ifEmpty {
strictVersion.ifEmpty {
preferredVersion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.shortway.kobankat.buildlogic.plugin

import com.android.build.gradle.LibraryExtension
import io.shortway.kobankat.buildlogic.ktx.getVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

/**
* A build convention plugin to be applied to all published library modules, to reduce duplication
* in build scripts.
*/
class LibraryConventionPlugin : Plugin<Project> {

override fun apply(target: Project) = with(target) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
val javaVersion = libs.getVersion("java")

with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")
apply("com.android.library")
apply("dev.adamko.dokkatoo-html")
apply("io.gitlab.arturbosch.detekt")
apply("com.vanniktech.maven.publish")
apply("com.gradleup.nmcp")
}

extensions.configure<KotlinMultiplatformExtension> {
// Compilation targets:
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = javaVersion
}
}

publishLibraryVariants("release")
}
iosX64()
iosArm64()
iosSimulatorArm64()

// Compiler flags:
targets.all {
compilations.all {
compilerOptions.configure {
freeCompilerArgs.apply {
add("-Xexpect-actual-classes")
}
}
}
}
sourceSets.all {
languageSettings.apply {
if (name.lowercase().startsWith("ios")) {
optIn("kotlinx.cinterop.ExperimentalForeignApi")
}
}
}

// Explicit API:
explicitApi()
}

// Android library setup:
extensions.configure<LibraryExtension> {
compileSdk = libs.getVersion("android-compileSdk").toInt()
defaultConfig {
minSdk = libs.getVersion("android-minSdk").toInt()
}
compileOptions {
sourceCompatibility(javaVersion)
targetCompatibility(javaVersion)
}
}
}

}
3 changes: 3 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
16 changes: 16 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@file:Suppress("UnstableApiUsage")

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")
51 changes: 50 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.MavenPublishPlugin
import io.gitlab.arturbosch.detekt.Detekt
import nmcp.NmcpExtension
import nmcp.NmcpPlugin
import org.gradle.configurationcache.extensions.capitalized

plugins {
//trick: for the same plugin versions in all sub-modules
Expand All @@ -12,7 +14,7 @@ plugins {
alias(libs.plugins.jetbrains.compose).apply(false)
alias(libs.plugins.kotlin.multiplatform).apply(false)
alias(libs.plugins.kotlin.cocoapods).apply(false)
alias(libs.plugins.adamko.dokkatoo.html).apply(false)
alias(libs.plugins.adamko.dokkatoo.html)
alias(libs.plugins.arturbosch.detekt).apply(false)
alias(libs.plugins.vanniktech.mavenPublish).apply(false)
alias(libs.plugins.gradleup.nmcp).apply(false)
Expand Down Expand Up @@ -79,5 +81,52 @@ allprojects {
}
}
}

// Register a Detekt task for all published modules.
with(this@allprojects) {
projectDir
.resolve("src")
.listFiles { child -> child.isDirectory }
.orEmpty()
.also { sourceDirectories ->
tasks.registerDetektTask(
taskName = "detektAll",
taskDescription = "Runs Detekt on all source sets.",
reportName = "all",
sourceDirs = files(sourceDirectories)
)

sourceDirectories.forEach { sourceDir ->
val sourceSet = sourceDir.name
tasks.registerDetektTask(
taskName = "detekt${sourceSet.capitalized()}",
taskDescription = "Runs Detekt on the $sourceSet source set.",
reportName = "$name${sourceSet.capitalized()}",
sourceDirs = files(sourceDir)
)
}
}
}
}
}

dependencies {
dokkatoo(projects.core)
dokkatoo(projects.result)
}

private fun TaskContainer.registerDetektTask(
taskName: String,
taskDescription: String,
reportName: String,
sourceDirs: ConfigurableFileCollection,
) =
register<Detekt>(taskName) {
description = taskDescription
setSource(sourceDirs.map { it.resolve("kotlin") })
config = files("$rootDir/config/detekt/detekt.yml")
reports {
html.outputLocation = file("build/reports/detekt/$reportName.html")
xml.outputLocation = file("build/reports/detekt/$reportName.xml")
}
}
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ kotlin {
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(projects.core)
implementation(projects.result)
}
androidMain.dependencies {
implementation(libs.androidx.compose.ui.tooling.preview)
Expand Down Expand Up @@ -83,4 +84,3 @@ android {
debugImplementation(libs.androidx.compose.ui.tooling)
}
}

94 changes: 1 addition & 93 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,53 +1,10 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.configurationcache.extensions.capitalized

plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
id("kobankat.library")
alias(libs.plugins.kotlin.cocoapods)
alias(libs.plugins.adamko.dokkatoo.html)
alias(libs.plugins.arturbosch.detekt)
alias(libs.plugins.vanniktech.mavenPublish)
alias(libs.plugins.gradleup.nmcp)
}

kotlin {
explicitApi()
targets.all {
compilations.all {
compilerOptions.configure {
freeCompilerArgs.apply {
add("-Xexpect-actual-classes")
}
}
}
}

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = libs.versions.java.get()
}
}

publishLibraryVariants("release")
}

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
all {
languageSettings.apply {
if (name.lowercase().startsWith("ios")) {
optIn("kotlinx.cinterop.ExperimentalForeignApi")
}
}
}
commonMain.dependencies {
//put your multiplatform dependencies here
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
Expand All @@ -74,53 +31,4 @@ kotlin {

android {
namespace = "io.shortway.kobankat"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
compileOptions {
sourceCompatibility(libs.versions.java.get())
targetCompatibility(libs.versions.java.get())
}
}

file("src")
.listFiles { child -> child.isDirectory }
.orEmpty()
.also { sourceDirectories ->
registerDetektTask(
taskName = "detektAll",
taskDescription = "Runs Detekt on all source sets.",
reportName = "all",
sourceDirs = files(sourceDirectories)
)

sourceDirectories.forEach { sourceDir -> registerDetektTask(sourceDir) }
}

private fun registerDetektTask(sourceDir: File) =
registerDetektTask(sourceDir.name)

private fun registerDetektTask(sourceDir: String) =
registerDetektTask(
taskName = "detekt${sourceDir.capitalized()}",
taskDescription = "Runs Detekt on the $sourceDir source set.",
reportName = sourceDir,
sourceDirs = files("src/$sourceDir/kotlin")
)

private fun registerDetektTask(
taskName: String,
taskDescription: String,
reportName: String,
sourceDirs: ConfigurableFileCollection,
) =
tasks.register<Detekt>(taskName) {
description = taskDescription
setSource(sourceDirs)
config = files("$rootDir/config/detekt/detekt.yml")
reports {
html.outputLocation = file("build/reports/detekt/$reportName.html")
xml.outputLocation = file("build/reports/detekt/$reportName.xml")
}
}
Loading

0 comments on commit 8a91ec2

Please sign in to comment.