Skip to content

Commit cc285ca

Browse files
committed
Use Kotlin DSL
1 parent 08a3b6f commit cc285ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+766
-623
lines changed

build.gradle

Lines changed: 0 additions & 41 deletions
This file was deleted.

build.gradle.kts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (C) 2020. Maximilian Keppeler (https://www.maxkeppeler.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import com.android.build.gradle.LibraryExtension
17+
18+
plugins {
19+
id(Plugins.APPLICATION.id) version (Plugins.APPLICATION.version) apply false
20+
id(Plugins.LIBRARY.id) version (Plugins.APPLICATION.version) apply false
21+
id(Plugins.KOTLIN.id) version (Plugins.KOTLIN.version) apply false
22+
id(Plugins.SPOTLESS.id) version (Plugins.SPOTLESS.version)
23+
id(Plugins.DOKKA.id) version (Plugins.DOKKA.version)
24+
}
25+
26+
buildscript {
27+
28+
repositories {
29+
google()
30+
mavenCentral()
31+
maven("https://plugins.gradle.org/m2/")
32+
}
33+
34+
dependencies {
35+
classpath(Dependencies.Kotlin.GRADLE_PLUGIN)
36+
classpath(Dependencies.Gradle.BUILD)
37+
classpath(Dependencies.MAVEN_PUBLISH)
38+
classpath(Dependencies.DOKKA)
39+
}
40+
}
41+
42+
allprojects {
43+
repositories {
44+
google()
45+
mavenCentral()
46+
maven("https://jitpack.io")
47+
}
48+
}
49+
50+
tasks.dokkaHtmlMultiModule.configure {
51+
outputDirectory.set(projectDir.resolve("docs/api"))
52+
}
53+
54+
subprojects {
55+
plugins.apply(Plugins.SPOTLESS.id)
56+
project.plugins.applyBaseConfig(project)
57+
spotless {
58+
kotlin {
59+
target("**/*.kt")
60+
licenseHeaderFile(rootProject.file("copyright.kt"))
61+
}
62+
kotlinGradle {
63+
target("*.gradle.kts", "gradle/*.gradle.kts", "buildSrc/*.gradle.kts")
64+
licenseHeaderFile(
65+
rootProject.file("copyright.kt"),
66+
"import|tasks|apply|plugins|rootProject"
67+
)
68+
}
69+
}
70+
}
71+
72+
73+
/**
74+
* Apply base configurations to the subjects that include specific custom plugins.
75+
*/
76+
fun PluginContainer.applyBaseConfig(project: Project) {
77+
whenPluginAdded {
78+
when (this) {
79+
is LibraryModulePlugin -> {
80+
project.extensions
81+
.getByType<LibraryExtension>()
82+
.apply {
83+
baseLibraryConfig()
84+
}
85+
}
86+
}
87+
}
88+
}
89+
90+
/**
91+
* Apply base library configurations to the subprojects that include the plugin [LibraryModulePlugin].
92+
*/
93+
fun com.android.build.gradle.BaseExtension.baseLibraryConfig() {
94+
95+
compileSdkVersion(App.COMPILE_SDK)
96+
97+
defaultConfig {
98+
minSdk = App.MIN_SDK
99+
targetSdk = App.TARGET_SDK
100+
testInstrumentationRunner = App.TEST_INSTRUMENTATION_RUNNER
101+
}
102+
103+
compileOptions.apply {
104+
sourceCompatibility(JavaVersion.VERSION_1_8)
105+
targetCompatibility(JavaVersion.VERSION_1_8)
106+
}
107+
108+
buildFeatures.viewBinding = true
109+
110+
packagingOptions.resources.excludes += listOf(
111+
"META-INF/DEPENDENCIES.txt",
112+
"META-INF/LICENSE",
113+
"META-INF/LICENSE.txt",
114+
"META-INF/NOTICE",
115+
"META-INF/NOTICE.txt",
116+
"META-INF/AL2.0",
117+
"META-INF/LGPL2.1"
118+
)
119+
120+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
121+
kotlinOptions {
122+
jvmTarget = "1.8"
123+
}
124+
}
125+
}

buildSrc/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import org.gradle.kotlin.dsl.`kotlin-dsl`
2+
3+
plugins {
4+
`kotlin-dsl`
5+
}
6+
7+
repositories {
8+
google()
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
12+
13+
gradlePlugin {
14+
plugins {
15+
register("library-module") {
16+
id = "library-module"
17+
implementationClass = "LibraryModulePlugin"
18+
}
19+
}
20+
}

buildSrc/src/main/java/App.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object App {
2+
3+
const val ID = "com.maxkeppeler.sample"
4+
5+
const val COMPILE_SDK = 33
6+
const val MIN_SDK = 21
7+
const val TARGET_SDK = 33
8+
9+
const val VERSION_CODE = 27
10+
const val VERSION_NAME = "2.3.0"
11+
12+
const val TEST_INSTRUMENTATION_RUNNER = "androidx.test.runner.AndroidJUnitRunner"
13+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
object Dependencies {
2+
3+
object Google {
4+
const val MATERIAL= "com.google.android.material:material:1.5.0"
5+
}
6+
7+
object AndroidX {
8+
9+
const val CORE_KTX = "androidx.core:core-ktx:1.8.0"
10+
const val LIFECYCLE_KTX = "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
11+
const val CONSTRAINT_LAYOUT = "androidx.constraintlayout:constraintlayout:2.1.3"
12+
const val ANNOTATIONS = "androidx.annotation:annotation:1.3.0"
13+
const val APP_COMPAT = "androidx.appcompat:appcompat:1.4.1"
14+
const val PREFERENCE = "androidx.preference:preference-ktx:1.2.0"
15+
const val RECYCLER_VIEW = "androidx.recyclerview:recyclerview:1.2.1"
16+
}
17+
18+
object Coil {
19+
const val COIL_BASE = "io.coil-kt:coil:1.4.0"
20+
const val COIL_VIDEO = "io.coil-kt:coil-video:1.4.0"
21+
}
22+
23+
object AirBnb {
24+
const val LOTTIE = "com.airbnb.android:lottie:4.2.1"
25+
}
26+
27+
object Kotlin {
28+
const val GRADLE_PLUGIN = "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
29+
const val KOTLIN_STD = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.KOTLIN}"
30+
}
31+
32+
object Gradle {
33+
const val BUILD = "com.android.tools.build:gradle:7.3.0"
34+
}
35+
36+
const val CALENDAR_VIEW = "com.github.kizitonwose:CalendarView:1.1.0"
37+
const val DOKKA = "org.jetbrains.dokka:dokka-gradle-plugin:1.6.0"
38+
const val DESUGAR = "com.android.tools:desugar_jdk_libs:1.1.5"
39+
40+
const val MAVEN_PUBLISH = "com.vanniktech:gradle-maven-publish-plugin:0.21.0"
41+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
import org.gradle.kotlin.dsl.project
4+
5+
class LibraryModulePlugin : Plugin<Project> {
6+
7+
override fun apply(project: Project) {
8+
with(project) {
9+
applyPlugins()
10+
applyDependencies()
11+
}
12+
}
13+
14+
private fun Project.applyPlugins() {
15+
plugins.run {
16+
apply(Plugins.LIBRARY.id)
17+
apply(Plugins.KOTLIN.id)
18+
apply(Plugins.DOKKA.id)
19+
apply(Plugins.MAVEN_PUBLISH.id)
20+
}
21+
}
22+
23+
private fun Project.applyDependencies() {
24+
25+
dependencies.apply {
26+
27+
// All modules require the core module
28+
29+
if (name != Modules.CORE.moduleName) {
30+
apis(project(Modules.CORE.path))
31+
}
32+
33+
// Google libs
34+
35+
implementations(Dependencies.Google.MATERIAL)
36+
37+
// Kotlin libs
38+
39+
implementations(Dependencies.Kotlin.KOTLIN_STD)
40+
41+
// AndroidX libs
42+
43+
implementations(
44+
Dependencies.AndroidX.ANNOTATIONS,
45+
Dependencies.AndroidX.CORE_KTX,
46+
Dependencies.AndroidX.CONSTRAINT_LAYOUT,
47+
Dependencies.AndroidX.RECYCLER_VIEW,
48+
)
49+
}
50+
}
51+
}

buildSrc/src/main/java/Modules.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@file:Suppress("PropertyName")
2+
3+
enum class Modules(val moduleName: String) {
4+
5+
CORE("core"),
6+
INFO("info"),
7+
COLOR("color"),
8+
CALENDAR("calendar"),
9+
CLOCK("clock"),
10+
DURATION("duration"),
11+
OPTION("option"),
12+
INPUT("input"),
13+
LOTTIE("lottie"),
14+
STORAGE("storage");
15+
16+
val path: String
17+
get() = ":$moduleName"
18+
19+
val namespace: String
20+
get() = "com.maxkeppeler.sheets.$moduleName"
21+
}

buildSrc/src/main/java/Plugins.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import models.Plugin
2+
3+
object Plugins {
4+
5+
val APPLICATION = Plugin("com.android.application", "7.2.2")
6+
val LIBRARY = Plugin("com.android.library", "7.2.2")
7+
val KOTLIN = Plugin("org.jetbrains.kotlin.android", "1.7.0")
8+
val SPOTLESS = Plugin("com.diffplug.spotless", "6.10.0")
9+
val MAVEN_PUBLISH = Plugin("com.vanniktech.maven.publish")
10+
val DOKKA = Plugin("org.jetbrains.dokka", "1.7.10")
11+
12+
val CUSTOM_LIBRARY_MODULE = Plugin("library-module")
13+
}

buildSrc/src/main/java/Versions.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Versions {
2+
3+
const val KOTLIN = "1.7.0"
4+
const val COMPOSE = "1.2.0"
5+
6+
const val KT_LINT = "0.47.1"
7+
8+
// Test
9+
10+
const val JUNIT = "4.13.2"
11+
const val ESPRESSO_CORE = "3.4.0"
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package models
2+
3+
data class Plugin(
4+
val id: String,
5+
val version: String? = ""
6+
)

0 commit comments

Comments
 (0)