Skip to content

Commit 6465e87

Browse files
author
Martin Styk
committed
Convention plugins and AGP 8.0.2 update
1 parent e06cc2f commit 6465e87

15 files changed

Lines changed: 257 additions & 64 deletions

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
plugins {
22
// Android studio bug shows libs as an error - https://youtrack.jetbrains.com/issue/KTIJ-19369
3-
alias(libs.plugins.android.application)
4-
alias(libs.plugins.kotlin.android)
5-
alias(libs.plugins.hilt.android)
6-
alias(libs.plugins.google.services)
7-
alias(libs.plugins.crashlytics)
8-
alias(libs.plugins.firebase.perf)
9-
alias(libs.plugins.spotless)
10-
alias(libs.plugins.dependency.updates)
3+
id("apkanalyzer.application")
4+
id("apkanalyzer.hilt")
5+
id("apkanalyzer.spotless")
116
id("kotlin-parcelize")
12-
kotlin("kapt")
7+
alias(libs.plugins.dependency.updates)
138
}
149
android {
1510
namespace = "sk.styk.martin.apkanalyzer"
1611

1712
defaultConfig {
1813
applicationId = "sk.styk.martin.apkanalyzer"
19-
20-
minSdk = 21
21-
targetSdk = 33
22-
compileSdk = 33
23-
24-
versionCode = 1
25-
versionName = "dev"
26-
27-
multiDexEnabled = true
28-
vectorDrawables.useSupportLibrary = true
2914
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
3015
}
3116

@@ -42,41 +27,14 @@ android {
4227
buildConfigField("boolean", "SHOW_PROMO", "false")
4328
}
4429
}
45-
buildTypes {
46-
getByName("release") {
47-
isMinifyEnabled = true
48-
isShrinkResources = true
49-
}
50-
getByName("debug") {
51-
isMinifyEnabled = false
52-
isShrinkResources = false
53-
}
54-
}
30+
5531
buildFeatures {
5632
viewBinding = true
5733
dataBinding = true
5834
}
59-
compileOptions {
60-
sourceCompatibility = JavaVersion.VERSION_1_8
61-
targetCompatibility = JavaVersion.VERSION_1_8
62-
}
63-
kotlinOptions {
64-
jvmTarget = JavaVersion.VERSION_1_8.toString()
65-
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn " +
66-
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi " +
67-
"-Xuse-experimental=kotlinx.coroutines.FlowPreview"
68-
}
6935
lint {
7036
disable += "MissingTranslation"
7137
}
72-
spotless {
73-
kotlin {
74-
target("**/*.kt")
75-
targetExclude("$buildDir/**/*.kt")
76-
targetExclude("bin/**/*.kt")
77-
ktlint("0.48.2")
78-
}
79-
}
8038
}
8139

8240
dependencies {
@@ -107,16 +65,6 @@ dependencies {
10765
annotationProcessor(libs.glide.compiler)
10866
implementation(libs.bundles.google.play)
10967

110-
// Firebase
111-
implementation(platform(libs.firebase.bom))
112-
implementation("com.google.firebase:firebase-crashlytics-ktx")
113-
implementation("com.google.firebase:firebase-analytics-ktx")
114-
implementation("com.google.firebase:firebase-perf")
115-
116-
// Hilt
117-
implementation(libs.hilt)
118-
kapt(libs.hilt.compiler)
119-
12068
debugImplementation(libs.leakcannary)
12169

12270
testImplementation(libs.junit)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
`kotlin-dsl`
5+
}
6+
7+
group = "sk.styk.martin.apkanalyzer.buildlogic"
8+
9+
java {
10+
sourceCompatibility = JavaVersion.VERSION_17
11+
targetCompatibility = JavaVersion.VERSION_17
12+
}
13+
tasks.withType<KotlinCompile>().configureEach {
14+
kotlinOptions {
15+
jvmTarget = JavaVersion.VERSION_17.toString()
16+
}
17+
}
18+
19+
dependencies {
20+
compileOnly(libs.android.gradle.plugin)
21+
compileOnly(libs.kotlin.gradle.plugin)
22+
compileOnly(libs.spotless.gradle.plugin)
23+
}
24+
25+
gradlePlugin {
26+
plugins {
27+
register("apkanalyzer.hilt") {
28+
id = "apkanalyzer.hilt"
29+
implementationClass = "HiltPlugin"
30+
}
31+
register("apkanalyzer.library") {
32+
id = "apkanalyzer.library"
33+
implementationClass = "LibraryPlugin"
34+
}
35+
register("apkanalyzer.application") {
36+
id = "apkanalyzer.application"
37+
implementationClass = "ApplicationPlugin"
38+
}
39+
register("apkanalyzer.spotless") {
40+
id = "apkanalyzer.spotless"
41+
implementationClass = "SpotlessPlugin"
42+
}
43+
}
44+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.VersionCatalogsExtension
5+
import org.gradle.kotlin.dsl.configure
6+
import org.gradle.kotlin.dsl.dependencies
7+
import org.gradle.kotlin.dsl.getByType
8+
import sk.styk.martin.apkanalyzer.MinSdk
9+
import sk.styk.martin.apkanalyzer.TargetSdk
10+
import sk.styk.martin.apkanalyzer.configureKotlin
11+
12+
class ApplicationPlugin : Plugin<Project> {
13+
override fun apply(target: Project) {
14+
with(target) {
15+
with(pluginManager) {
16+
apply("com.android.application")
17+
apply("org.jetbrains.kotlin.android")
18+
apply("com.google.gms.google-services")
19+
apply("com.google.firebase.firebase-perf")
20+
apply("com.google.firebase.crashlytics")
21+
}
22+
23+
extensions.configure<ApplicationExtension> {
24+
defaultConfig {
25+
targetSdk = TargetSdk
26+
compileSdk = TargetSdk
27+
minSdk = MinSdk
28+
29+
versionCode = 1
30+
versionName = "dev"
31+
32+
multiDexEnabled = true
33+
vectorDrawables.useSupportLibrary = true
34+
}
35+
36+
buildTypes {
37+
getByName("release") {
38+
isMinifyEnabled = true
39+
isShrinkResources = true
40+
}
41+
getByName("debug") {
42+
isMinifyEnabled = false
43+
isShrinkResources = false
44+
}
45+
}
46+
}
47+
48+
configureKotlin()
49+
50+
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
51+
dependencies {
52+
val bom = libs.findLibrary("firebase-bom").get()
53+
add("implementation", platform(bom))
54+
"implementation"(libs.findLibrary("firebase.analytics").get())
55+
"implementation"(libs.findLibrary("firebase.performance").get())
56+
"implementation"(libs.findLibrary("firebase.crashlytics").get())
57+
}
58+
}
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
import org.gradle.api.artifacts.VersionCatalogsExtension
4+
import org.gradle.kotlin.dsl.dependencies
5+
import org.gradle.kotlin.dsl.getByType
6+
7+
class HiltPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
with(pluginManager) {
11+
apply("dagger.hilt.android.plugin")
12+
apply("org.jetbrains.kotlin.kapt")
13+
}
14+
15+
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
16+
dependencies {
17+
"implementation"(libs.findLibrary("hilt").get())
18+
"kapt"(libs.findLibrary("hilt.compiler").get())
19+
}
20+
}
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import com.android.build.api.dsl.LibraryExtension
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.kotlin.dsl.configure
5+
import sk.styk.martin.apkanalyzer.MinSdk
6+
import sk.styk.martin.apkanalyzer.TargetSdk
7+
import sk.styk.martin.apkanalyzer.configureKotlin
8+
9+
class LibraryPlugin : Plugin<Project> {
10+
override fun apply(target: Project) {
11+
with(target) {
12+
with(pluginManager) {
13+
apply("com.android.library")
14+
apply("org.jetbrains.kotlin.android")
15+
}
16+
17+
extensions.configure<LibraryExtension> {
18+
compileSdk = TargetSdk
19+
defaultConfig {
20+
minSdk = MinSdk
21+
}
22+
}
23+
24+
configureKotlin()
25+
}
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import com.diffplug.gradle.spotless.SpotlessExtension
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.kotlin.dsl.configure
5+
6+
class SpotlessPlugin : Plugin<Project> {
7+
override fun apply(target: Project) {
8+
with(target) {
9+
with(pluginManager) {
10+
apply("com.diffplug.spotless")
11+
}
12+
extensions.configure<SpotlessExtension> {
13+
kotlin {
14+
target("**/*.kt")
15+
targetExclude("$buildDir/**/*.kt")
16+
targetExclude("bin/**/*.kt")
17+
ktlint("0.48.2")
18+
}
19+
}
20+
}
21+
}
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package sk.styk.martin.apkanalyzer
2+
3+
const val TargetSdk = 33
4+
const val MinSdk = 21
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package sk.styk.martin.apkanalyzer
2+
3+
import com.android.build.api.dsl.ApplicationExtension
4+
import org.gradle.api.JavaVersion
5+
import org.gradle.api.Project
6+
import org.gradle.kotlin.dsl.configure
7+
import org.gradle.kotlin.dsl.withType
8+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
9+
10+
11+
internal fun Project.configureKotlin() {
12+
extensions.configure<ApplicationExtension> {
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_11
15+
targetCompatibility = JavaVersion.VERSION_11
16+
}
17+
}
18+
19+
tasks.withType<KotlinCompile>().configureEach {
20+
kotlinOptions {
21+
jvmTarget = JavaVersion.VERSION_11.toString()
22+
freeCompilerArgs = freeCompilerArgs + listOf(
23+
"-opt-in=kotlin.RequiresOptIn",
24+
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
25+
"-Xuse-experimental=kotlinx.coroutines.FlowPreview"
26+
)
27+
}
28+
29+
}
30+
}

build-logic/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
2+
org.gradle.parallel=true
3+
org.gradle.caching=true
4+
org.gradle.configureondemand=true

0 commit comments

Comments
 (0)