Skip to content

Commit

Permalink
Set up library convention plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed May 10, 2024
1 parent 90dfd9f commit bfec6e0
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/local.properties
/.idea
.DS_Store
/build
build/
/captures
.externalNativeBuild
.cxx
Expand Down
32 changes: 32 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

//group = "com.google.samples.apps.nowinandroid.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.android.tools.common)
compileOnly(libs.kotlin.gradlePlugin)
}

gradlePlugin {
plugins {
register("androidLibrary") {
id = "co.zsmb.requirektx.library"
implementationClass = "AndroidLibraryConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class AndroidLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
}

extensions.configure<KotlinMultiplatformExtension> {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}

explicitApi()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-progressive")
}
}

extensions.configure<LibraryExtension> {
compileSdk = 34
defaultConfig {
minSdk = 21
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
}
}
}
14 changes: 14 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ navigation-runtime = "2.7.7"
robolectric = "4.12.1"
work-runtime = "2.9.0"

# TODO
androidTools = "31.3.0"

[libraries]
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
Expand All @@ -25,7 +28,13 @@ navigation-runtime = { module = "androidx.navigation:navigation-runtime", versio
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
work-runtime = { module = "androidx.work:work-runtime", version.ref = "work-runtime" }

# TODO STOPSHIP fix these
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
requireKtxLibrary = { id = "co.zsmb.requirektx.library", version = "unspecified" }
33 changes: 3 additions & 30 deletions requirektx-bundle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.requireKtxLibrary)
}

kotlin {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
android.namespace = "co.zsmb.requirektx.bundle"

kotlin {
sourceSets {
commonMain.dependencies {}
commonTest.dependencies {
Expand All @@ -25,23 +17,4 @@ kotlin {
}
}
}

explicitApi()
compilerOptions {
freeCompilerArgs.add("-progressive")
}
}

android {
namespace = "co.zsmb.requirektx.bundle"
compileSdk = 34

defaultConfig {
minSdk = 21
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
32 changes: 3 additions & 29 deletions requirektx-intent/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.requireKtxLibrary)
}

kotlin {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
android.namespace = "co.zsmb.requirektx.intent"

kotlin {
sourceSets {
commonMain.dependencies {
api(project(":requirektx-bundle"))
Expand All @@ -27,22 +19,4 @@ kotlin {
}
}
}

explicitApi()
compilerOptions {
freeCompilerArgs.add("-progressive")
}
}

android {
namespace = "co.zsmb.requirektx.intent"
compileSdk = 34

defaultConfig {
minSdk = 21
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
32 changes: 3 additions & 29 deletions requirektx-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.requireKtxLibrary)
}

kotlin {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
android.namespace = "co.zsmb.requirektx.navigation"

kotlin {
sourceSets {
commonMain.dependencies {
api(project(":requirektx-bundle"))
Expand All @@ -30,22 +22,4 @@ kotlin {
}
}
}

explicitApi()
compilerOptions {
freeCompilerArgs.add("-progressive")
}
}

android {
namespace = "co.zsmb.requirektx.navigation"
compileSdk = 34

defaultConfig {
minSdk = 21
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
35 changes: 3 additions & 32 deletions requirektx-work/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.requireKtxLibrary)
}

kotlin {
androidTarget {
publishLibraryVariants("release")
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
android.namespace = "co.zsmb.requirektx.work"

kotlin {
sourceSets {
commonMain.dependencies {}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
Expand All @@ -31,28 +22,8 @@ kotlin {
}
}
}

explicitApi()
compilerOptions {
freeCompilerArgs.add("-progressive")
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

android {
namespace = "co.zsmb.requirektx.work"
compileSdk = 34

defaultConfig {
minSdk = 21
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFile("consumer-rules.pro")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
Expand Down

0 comments on commit bfec6e0

Please sign in to comment.