Last active
May 15, 2023 12:08
-
-
Save Schadenfeude/8ed81dd06f01d6eeab571555fc8308d1 to your computer and use it in GitHub Desktop.
Gradle configuration for better dependency management in a multi-module project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
apply from: "$rootDir/common.gradle" | |
apply plugin: 'androidx.navigation.safeargs.kotlin' | |
android { | |
defaultConfig { | |
applicationId app_config.app_id | |
setProperty("archivesBaseName", app_config.archive_file) | |
} | |
signingConfigs { | |
def debugPass = getDebugPass() | |
debug { | |
storeFile file("../debug.jks") | |
storePassword debugPass | |
keyAlias "debug" | |
keyPassword debugPass | |
} | |
} | |
} | |
dependencies { | |
// Design | |
implementation deps.support.constraint_layout | |
// Navigation | |
implementation deps.navigation.fragment_ktx | |
implementation deps.navigation.ui_ktx | |
} | |
String getDebugPass() { | |
Properties properties = new Properties() | |
properties.load(project.rootProject.file('local.properties').newDataInputStream()) | |
return properties.getProperty('DebugKsPass') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
apply plugin: "com.github.ben-manes.versions" | |
buildscript { | |
apply from: "versions.gradle" | |
addRepos(repositories) | |
dependencies { | |
classpath deps.android_gradle_plugin | |
classpath deps.gradle_versions | |
classpath deps.kotlin.plugin | |
classpath deps.navigation.safe_args_plugin | |
} | |
} | |
allprojects { | |
addRepos(repositories) | |
} | |
task clean(type: Delete) { | |
delete rootProject.buildDir | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
android { | |
compileSdkVersion build_versions.compile_sdk | |
buildToolsVersion build_versions.build_tools | |
defaultConfig { | |
minSdkVersion build_versions.min_sdk | |
targetSdkVersion build_versions.target_sdk | |
versionCode app_config.version_code | |
versionName app_config.version_name | |
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
shrinkResources false | |
debuggable true | |
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |
} | |
debug { | |
minifyEnabled false | |
shrinkResources false | |
debuggable true | |
} | |
} | |
androidExtensions { | |
experimental = true | |
} | |
kotlinOptions { | |
jvmTarget = '1.8' | |
} | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_8 | |
targetCompatibility JavaVersion.VERSION_1_8 | |
} | |
} | |
dependencies { | |
// Kotlin | |
implementation deps.kotlin.stdlib | |
// Coroutines | |
implementation deps.coroutines.core | |
implementation deps.coroutines.android | |
// Test | |
androidTestImplementation deps.atsl.runner | |
androidTestImplementation deps.atsl.rules | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2018 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
/** | |
* Shared file between builds so that they can all use the same dependencies and | |
* maven repositories. | |
**/ | |
def app_version = [:] | |
app_version.major = 1 | |
app_version.minor = 0 | |
app_version.patch = 0 | |
app_version.build = 0 | |
def app_config = [:] | |
app_config.app_id = "com.my.app" | |
app_config.version_code = app_version.major * 1000000 + app_version.minor * 10000 + app_version.patch * 100 + app_version.build | |
app_config.version_name = "$app_version.major.$app_version.minor.$app_version.patch" | |
app_config.archive_file = "appname-$app_config.version_name" | |
ext.app_config = app_config | |
def build_versions = [:] | |
build_versions.compile_sdk = 28 | |
build_versions.min_sdk = 21 | |
build_versions.target_sdk = 28 | |
build_versions.build_tools = "28.0.3" | |
ext.build_versions = build_versions | |
ext.deps = [:] | |
def deps = [:] | |
def versions = [:] | |
versions.android_gradle_plugin = '3.4.2' | |
versions.anko = "0.10.8" | |
versions.apache_commons = "2.5" | |
versions.arch_core = "2.0.1" | |
versions.atsl_rules = "1.1.1" | |
versions.atsl_runner = "1.1.1" | |
versions.atsl_junit = "1.1.0" | |
versions.constraint_layout = "2.0.0-alpha2" | |
versions.core_ktx = "1.0.0" | |
versions.coroutines = "1.2.1" | |
versions.dagger = "2.16" | |
versions.dexmaker = "2.2.0" | |
versions.espresso = "3.1.1" | |
versions.fragment = "1.1.0-alpha05" | |
versions.glide = "4.8.0" | |
versions.hamcrest = "1.3" | |
versions.junit = "4.12" | |
versions.kotlin = "1.3.40" | |
versions.koin = "2.0.1" | |
versions.lifecycle = "2.0.0" | |
versions.mockito = "2.25.0" | |
versions.mockito_all = "1.10.19" | |
versions.mockito_android = "2.25.0" | |
versions.mockwebserver = "3.8.1" | |
versions.navigation = "2.1.0-alpha06" | |
versions.okhttp_logging_interceptor = "3.9.0" | |
versions.paging = "2.1.0-rc01" | |
versions.places = "1.1.0" | |
versions.retrofit = "2.3.0" | |
versions.robolectric = "4.2" | |
versions.room = "2.1.0-alpha06" | |
versions.rx_android = "2.1.1" | |
versions.rxjava2 = "2.2.10" | |
versions.support = "1.0.0" | |
versions.timber = "4.5.1" | |
versions.work = "2.1.0-alpha01" | |
def support = [:] | |
support.annotations = "androidx.annotation:annotation:$versions.support" | |
support.app_compat = "androidx.appcompat:appcompat:$versions.support" | |
support.recyclerview = "androidx.recyclerview:recyclerview:$versions.support" | |
support.cardview = "androidx.cardview:cardview:$versions.support" | |
support.constraint_layout = "androidx.constraintlayout:constraintlayout:$versions.constraint_layout" | |
support.design = "com.google.android.material:material:$versions.support" | |
support.v4 = "androidx.legacy:legacy-support-v4:$versions.support" | |
support.core_utils = "androidx.legacy:legacy-support-core-utils:$versions.support" | |
support.core_ktx = "androidx.core:core-ktx:$versions.core_ktx" | |
support.fragment_runtime = "androidx.fragment:fragment:${versions.fragment}" | |
support.fragment_runtime_ktx = "androidx.fragment:fragment-ktx:${versions.fragment}" | |
support.fragment_testing = "androidx.fragment:fragment-testing:${versions.fragment}" | |
deps.support = support | |
def room = [:] | |
room.runtime = "androidx.room:room-runtime:$versions.room" | |
room.compiler = "androidx.room:room-compiler:$versions.room" | |
room.rxjava2 = "androidx.room:room-rxjava2:$versions.room" | |
room.testing = "androidx.room:room-testing:$versions.room" | |
deps.room = room | |
def lifecycle = [:] | |
lifecycle.runtime = "androidx.lifecycle:lifecycle-runtime:$versions.lifecycle" | |
lifecycle.extensions = "androidx.lifecycle:lifecycle-extensions:$versions.lifecycle" | |
lifecycle.java8 = "androidx.lifecycle:lifecycle-common-java8:$versions.lifecycle" | |
lifecycle.compiler = "androidx.lifecycle:lifecycle-compiler:$versions.lifecycle" | |
lifecycle.viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$versions.lifecycle" | |
deps.lifecycle = lifecycle | |
def arch_core = [:] | |
arch_core.runtime = "androidx.arch.core:core-runtime:$versions.arch_core" | |
arch_core.testing = "androidx.arch.core:core-testing:$versions.arch_core" | |
deps.arch_core = arch_core | |
def retrofit = [:] | |
retrofit.runtime = "com.squareup.retrofit2:retrofit:$versions.retrofit" | |
retrofit.gson = "com.squareup.retrofit2:converter-gson:$versions.retrofit" | |
retrofit.mock = "com.squareup.retrofit2:retrofit-mock:$versions.retrofit" | |
retrofit.scalars = "com.squareup.retrofit2:converter-scalars:$versions.retrofit" | |
deps.retrofit = retrofit | |
deps.okhttp_logging_interceptor = "com.squareup.okhttp3:logging-interceptor:${versions.okhttp_logging_interceptor}" | |
deps.mock_web_server = "com.squareup.okhttp3:mockwebserver:$versions.mockwebserver" | |
def dagger = [:] | |
dagger.runtime = "com.google.dagger:dagger:$versions.dagger" | |
dagger.android = "com.google.dagger:dagger-android:$versions.dagger" | |
dagger.android_support = "com.google.dagger:dagger-android-support:$versions.dagger" | |
dagger.compiler = "com.google.dagger:dagger-compiler:$versions.dagger" | |
dagger.android_support_compiler = "com.google.dagger:dagger-android-processor:$versions.dagger" | |
deps.dagger = dagger | |
def espresso = [:] | |
espresso.core = "androidx.test.espresso:espresso-core:$versions.espresso" | |
espresso.contrib = "androidx.test.espresso:espresso-contrib:$versions.espresso" | |
espresso.intents = "androidx.test.espresso:espresso-intents:$versions.espresso" | |
deps.espresso = espresso | |
def atsl = [:] | |
atsl.runner = "androidx.test:runner:$versions.atsl_runner" | |
atsl.rules = "androidx.test:rules:$versions.atsl_runner" | |
atsl.ext_junit = "androidx.test.ext:junit:$versions.atsl_junit" | |
atsl.junit = "junit:junit:$versions.junit" | |
deps.atsl = atsl | |
def mockito = [:] | |
mockito.core = "org.mockito:mockito-core:$versions.mockito" | |
mockito.all = "org.mockito:mockito-all:$versions.mockito_all" | |
mockito.android = "org.mockito:mockito-android:$versions.mockito_android" | |
deps.mockito = mockito | |
def kotlin = [:] | |
kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin" | |
kotlin.test = "org.jetbrains.kotlin:kotlin-test-junit:$versions.kotlin" | |
kotlin.plugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" | |
kotlin.allopen = "org.jetbrains.kotlin:kotlin-allopen:$versions.kotlin" | |
deps.kotlin = kotlin | |
def koin = [:] | |
koin.core = "org.koin:koin-core:$versions.koin" | |
deps.koin = koin | |
def glide = [:] | |
glide.runtime = "com.github.bumptech.glide:glide:$versions.glide" | |
glide.compiler = "com.github.bumptech.glide:compiler:$versions.glide" | |
deps.glide = glide | |
def work = [:] | |
work.runtime = "androidx.work:work-runtime:$versions.work" | |
work.testing = "androidx.work:work-testing:$versions.work" | |
work.firebase = "androidx.work:work-firebase:$versions.work" | |
work.runtime_ktx = "androidx.work:work-runtime-ktx:$versions.work" | |
deps.work = work | |
def navigation = [:] | |
navigation.runtime = "androidx.navigation:navigation-runtime:$versions.navigation" | |
navigation.runtime_ktx = "androidx.navigation:navigation-runtime-ktx:$versions.navigation" | |
navigation.fragment = "androidx.navigation:navigation-fragment:$versions.navigation" | |
navigation.fragment_ktx = "androidx.navigation:navigation-fragment-ktx:$versions.navigation" | |
navigation.ui = "androidx.navigation:navigation-ui:$versions.navigation" | |
navigation.ui_ktx = "androidx.navigation:navigation-ui-ktx:$versions.navigation" | |
navigation.safe_args_plugin = "androidx.navigation:navigation-safe-args-gradle-plugin:$versions.navigation" | |
deps.navigation = navigation | |
def android_libraries = [:] | |
android_libraries.places = "com.google.android.libraries.places:places:$versions.places" | |
deps.android_libraries = android_libraries | |
def coroutines = [:] | |
coroutines.core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.coroutines" | |
coroutines.android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutines" | |
deps.coroutines = coroutines | |
def rx = [:] | |
rx.java = "io.reactivex.rxjava2:rxjava:$versions.rxjava2" | |
rx.android = "io.reactivex.rxjava2:rxandroid:$versions.rx_android" | |
deps.rx = rx | |
def anko = [:] | |
anko.commons = "org.jetbrains.anko:anko-commons:$versions.anko" | |
deps.anko = anko | |
deps.paging_ktx = "androidx.paging:paging-runtime-ktx:$versions.paging" | |
// ./gradlew dependencyUpdates -Drevision=release | |
deps.gradle_versions = "com.github.ben-manes:gradle-versions-plugin:0.21.0" | |
deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin" | |
deps.dexmaker = "com.linkedin.dexmaker:dexmaker-mockito:$versions.dexmaker" | |
deps.timber = "com.jakewharton.timber:timber:$versions.timber" | |
deps.hamcrest = "org.hamcrest:hamcrest-all:$versions.hamcrest" | |
deps.robolectric = "org.robolectric:robolectric:$versions.robolectric" | |
ext.deps = deps | |
static def addRepos(RepositoryHandler handler) { | |
handler.google() | |
handler.jcenter() | |
handler.maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } | |
handler.maven { url "https://kotlin.bintray.com/kotlinx/" } | |
// For kotlinx-metadata-jvm used by Room 2.1.0 (KT-27991) | |
} | |
ext.addRepos = this.&addRepos |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment