Skip to content

Commit

Permalink
Use buildSrc for dependencies
Browse files Browse the repository at this point in the history
Summary:
Using `constants.gradle` is an older way of managing dependencies. The recommendation is now to use the kotlin-dsl plugin which allows an reserved `buildSrc` module which is accessible to all other modules. This enables IDE support which is a huge QoL improvement when dealing with dependencies as we no longer have to rely on full text search only.

See:
https://docs.gradle.org/current/userguide/organizing_gradle_projects.html
https://proandroiddev.com/better-dependencies-management-using-buildsrc-kotlin-dsl-eda31cdb81bf
https://github.com/antoniolg/Bandhook-Kotlin

Reviewed By: linmx0130

Differential Revision: D38715544

fbshipit-source-id: a700cf59ce10c1ff863a88b060b886c1b19e61fa
  • Loading branch information
mingcaozhang authored and facebook-github-bot committed Aug 22, 2022
1 parent b7a1c9c commit 3191cef
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 205 deletions.
18 changes: 9 additions & 9 deletions build.gradle → build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
project.apply from: "${rootDir}/constants.gradle"
apply(from = "${rootDir}/constants.gradle")

repositories {
maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") }
mavenCentral()
google()
}

dependencies {
classpath "com.android.tools.build:gradle:${project.ext.gradleVersion}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${project.ext.dokkaVersion}"
classpath 'org.jacoco:org.jacoco.core:0.8.7'
classpath(Plugins.android_gradle)
classpath(Plugins.kotlin_gradle)
classpath(Plugins.dokka)
classpath(Libs.jacoco_core)
}
}

allprojects {
repositories {
mavenCentral()
google()
maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" }
maven { url 'https://jitpack.io' }
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven") }
maven { url = uri("https://jitpack.io") }
}

project.apply from: "${rootDir}/constants.gradle"
apply(from = "${rootDir}/constants.gradle")
}
9 changes: 9 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.gradle.kotlin.dsl.`kotlin-dsl`

plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
121 changes: 121 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
object Config {
const val minSdk = 15
const val compileSdk = 29
const val targetSdk = 29
}

object Versions {
const val acra = "5.5.0"
const val analytics = "4.+"
const val android_billingclient = "3.0.0"
const val android_installreferrer = "1.0" // there are issues with 1.1 regarding permissions, asks for unnecessary permissions
const val androidx = "1.1.0"
const val androidxActivity = "1.2.0"
const val androidxAnnotation = "1.1.0"
const val androidxBrowser = "1.0.0"
const val androidxCardview = "1.0.0"
const val androidxConstraintLayout = "1.1.3"
const val androidxCore = "1.0.0"
const val androidxCoreKtx = "1.3.2"
const val androidxEspressoCore = "3.1.0"
const val androidxFragment = "1.3.0"
const val androidxLegacy = "1.0.0"
const val androidxTest = "1.0.0"
const val assertj = "3.15.0"
const val dexmaker = "1.2"
const val dokka = "1.4.30"
const val firebaseBom = "29.3.1"
const val firebaseMessaging = "23.0.3"
const val fresco = "2.6.0"
const val glide = "4.13.0"
const val googleServices = "4.3.5"
const val gradle = "4.2.0" // Android gradle plugin version
const val gson = "2.8.8"
const val guava = "18.0"
const val junit = "4.13"
const val jacoco = "0.8.7"
const val json = "20180130"
const val kotlin = "1.5.10"
const val leakcanaryAndroid = "2.8.1"
const val liquidcore = "0.6.2"
const val material = "1.0.0"
const val mockitoInline = "2.26.0"
const val mockitoKotlin = "2.2.0"
const val mockwebserver = "4.9.0"
const val playServicesAuth = "16.0.0"
const val playServicesGcm = "17.0.0"
const val powerMock = "2.0.2"
const val robolectric = "4.4"
const val stetho = "1.5.0"
const val testng = "6.9.6"
const val zxing = "3.3.3"
}

object Plugins {
const val android_gradle = "com.android.tools.build:gradle:${Versions.gradle}"
const val kotlin_gradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}"
const val google_services = "com.google.gms:google-services:${Versions.googleServices}"
}

object Libs {

// android
const val android_billingclient = "com.android.billingclient:billing:${Versions.android_billingclient}"
const val android_installreferrer = "com.android.installreferrer:installreferrer:${Versions.android_installreferrer}" //https://developer.android.com/google/play/installreferrer/library.html#java
const val androidx_activity = "androidx.activity:activity:${Versions.androidxActivity}"
const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidxAnnotation}"
const val androidx_appcompat = "androidx.appcompat:appcompat:${Versions.androidx}"
const val androidx_browser = "androidx.browser:browser:${Versions.androidxBrowser}"
const val androidx_cardview = "androidx.cardview:cardview:${Versions.androidxCardview}"
const val androidx_constraintlayout = "androidx.constraintlayout:constraintlayout:${Versions.androidxConstraintLayout}"
const val androidx_core = "androidx.core:core:${Versions.androidxCore}"
const val androidx_core_ktx = "androidx.core:core-ktx:${Versions.androidxCoreKtx}"
const val androidx_espresso_core = "androidx.test.espresso:espresso-core:${Versions.androidxEspressoCore}"
const val androidx_fragment = "androidx.fragment:fragment:${Versions.androidxFragment}"
const val androidx_legacy_support_v4 = "androidx.legacy:legacy-support-v4:${Versions.androidxLegacy}"
const val androidx_legacy_support_core_utils = "androidx.legacy:legacy-support-core-utils:${Versions.androidxLegacy}"
const val androidx_recyclerview = "androidx.recyclerview:recyclerview:${Versions.androidx}"
const val androidx_test_core = "androidx.test:core:${Versions.androidxTest}"

// google
const val dexmaker = "com.google.dexmaker:dexmaker:${Versions.dexmaker}"
const val dexmaker_mockito = "com.google.dexmaker:dexmaker-mockito:${Versions.dexmaker}"
const val firebase_bom = "com.google.firebase:firebase-bom:${Versions.firebaseBom}"
const val firebase_analytics = "com.google.firebase:firebase-analytics"
const val firebase_messaging = "com.google.firebase:firebase-messaging:${Versions.firebaseMessaging}"
const val gson = "com.google.code.gson:gson:${Versions.gson}"
const val guava = "com.google.guava:guava:${Versions.guava}"
const val material = "com.google.android.material:material:${Versions.material}"
const val play_services_auth = "com.google.android.gms:play-services-auth:${Versions.playServicesAuth}"
const val play_services_gcm = "com.google.android.gms:play-services-gcm:${Versions.playServicesGcm}"
const val zxing = "com.google.zxing:core:${Versions.zxing}"

// 1st-party
const val fresco = "com.facebook.fresco:fresco:${Versions.fresco}"
const val stetho = "com.facebook.stetho:stetho:${Versions.stetho}"

const val acra = "ch.acra:acra-mail:${Versions.acra}"
const val analytics = "com.segment.analytics.android:analytics:${Versions.analytics}"
const val assertj_core = "org.assertj:assertj-core:${Versions.assertj}"
const val glide = "com.github.bumptech.glide:glide:${Versions.glide}"
const val glide_compiler = "com.github.bumptech.glide:compiler:${Versions.glide}"
const val jacoco_core = "org.jacoco:org.jacoco.core:${Versions.jacoco}"
const val json = "org.json:json:${Versions.json}"
const val junit = "junit:junit:${Versions.junit}"
const val kotlin_stdlib = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}"
const val kotlin_stdlib_jdk7 = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
const val kotlin_test_junit = "org.jetbrains.kotlin:kotlin-test-junit:${Versions.kotlin}"
const val leakcanary_android = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanaryAndroid}"
const val liquidcore = "com.github.LiquidPlayer:LiquidCore:${Versions.liquidcore}"
const val mockito_inline = "org.mockito:mockito-inline:${Versions.mockitoInline}"
const val mockito_kotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:${Versions.mockitoKotlin}"
const val mockwebserver = "com.squareup.okhttp3:mockwebserver:${Versions.mockwebserver}"
const val powermock_core = "org.powermock:powermock-core:${Versions.powerMock}"
const val powermock_api_mockito2 = "org.powermock:powermock-api-mockito2:${Versions.powerMock}"
const val powermock_junit4 = "org.powermock:powermock-module-junit4:${Versions.powerMock}"
const val powermock_junit4_rule = "org.powermock:powermock-module-junit4-rule:${Versions.powerMock}"
const val powermock_classloading_xstream = "org.powermock:powermock-classloading-xstream:${Versions.powerMock}"
const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
const val testng = "org.testng:testng:${Versions.testng}"
}
10 changes: 5 additions & 5 deletions facebook-applinks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ dependencies {
// Facebook Dependencies
api project(':facebook-core')
// Support Dependencies
implementation "androidx.annotation:annotation:${project.ext.androidxAnnotationVersion}"
implementation "androidx.legacy:legacy-support-core-utils:${project.ext.androidxLegacyVersion}"
implementation(Libs.androidx_annotation)
implementation(Libs.androidx_legacy_support_core_utils)
}

android {
compileSdkVersion project.ext.compileSdk
compileSdkVersion(Config.compileSdk)

defaultConfig {
minSdkVersion project.ext.minSdk
targetSdkVersion project.ext.targetSdk
minSdkVersion(Config.minSdk)
targetSdkVersion(Config.targetSdk)
consumerProguardFiles 'proguard-rules.pro'
}

Expand Down
49 changes: 22 additions & 27 deletions facebook-bolts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,40 @@ project.ext.description = 'Facebook Android SDK Bolts support library'
project.ext.url = 'https://github.com/facebook/facebook-android-sdk'

dependencies {
def kotlin_ver = project.ext.kotlinVersion

implementation "androidx.annotation:annotation:${project.ext.androidxVersion}"
implementation "androidx.core:core-ktx:1.3.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_ver"
implementation(Libs.androidx_annotation)
implementation(Libs.androidx_core_ktx)
implementation(Libs.kotlin_stdlib)

// Unit Tests
testImplementation project(":facebook-testutil")
testImplementation "junit:junit:$junitVersion"
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation 'androidx.test:core:1.0.0'

testImplementation "org.mockito:mockito-inline:2.26.0"
testImplementation "org.mockito.kotlin:mockito-kotlin:2.2.11"

def powerMockVersion = '2.0.2'
testImplementation "org.powermock:powermock-core:$powerMockVersion"
testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion"
testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion"
testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
testImplementation "org.powermock:powermock-classloading-xstream:$powerMockVersion"
testImplementation 'org.assertj:assertj-core:3.15.0'

testImplementation "com.android.installreferrer:installreferrer:1.0"
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_ver"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_ver"

testImplementation(Libs.junit)
testImplementation(Libs.robolectric)
testImplementation(Libs.androidx_test_core)
testImplementation(Libs.mockito_inline)
testImplementation(Libs.mockito_kotlin)

testImplementation(Libs.powermock_core)
testImplementation(Libs.powermock_api_mockito2)
testImplementation(Libs.powermock_junit4)
testImplementation(Libs.powermock_junit4_rule)
testImplementation(Libs.powermock_classloading_xstream)
testImplementation(Libs.assertj_core)

testImplementation(Libs.android_installreferrer)
testImplementation(Libs.kotlin_stdlib)
testImplementation(Libs.kotlin_test_junit)
}

android {
compileSdkVersion project.ext.compileSdk
compileSdkVersion(Config.compileSdk)
// The version of Jacoco used by the android gradle plugin
jacoco {
version "0.8.7"
}

defaultConfig {
minSdkVersion project.ext.minSdk
targetSdkVersion project.ext.targetSdk
minSdkVersion(Config.minSdk)
targetSdkVersion(Config.targetSdk)
consumerProguardFiles 'proguard-rules.pro'
}

Expand Down
57 changes: 27 additions & 30 deletions facebook-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,56 +29,53 @@ project.ext.description = 'Facebook Common Android SDK'
project.ext.url = 'https://github.com/facebook/facebook-android-sdk'

dependencies {
def kotlin_ver = project.ext.kotlinVersion
// Facebook Dependencies
api project(':facebook-core')
// Support Dependencies
api "androidx.legacy:legacy-support-v4:${project.ext.androidxLegacyVersion}"
implementation "androidx.appcompat:appcompat:${project.ext.androidxVersion}"
implementation "androidx.cardview:cardview:${project.ext.androidxCardviewVersion}"
implementation "androidx.browser:browser:${project.ext.androidxBrowserVersion}"
implementation("androidx.activity:activity:${project.ext.androidxActivityVersion}")
implementation("androidx.fragment:fragment:${project.ext.androidxFragmentVersion}")
api(Libs.androidx_legacy_support_v4)
implementation(Libs.androidx_appcompat)
implementation(Libs.androidx_cardview)
implementation(Libs.androidx_browser)
implementation(Libs.androidx_activity)
implementation(Libs.androidx_fragment)

// Third-party Dependencies
implementation 'com.google.zxing:core:3.3.3'
implementation(Libs.zxing)

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_ver"
implementation(Libs.kotlin_stdlib)

// Unit Tests
testImplementation project(":facebook-testutil")
testImplementation "junit:junit:$junitVersion"
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation 'androidx.test:core:1.0.0'

testImplementation "org.mockito:mockito-inline:2.26.0"
testImplementation "org.mockito.kotlin:mockito-kotlin:2.2.11"

def powerMockVersion = '2.0.2'
testImplementation "org.powermock:powermock-core:$powerMockVersion"
testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion"
testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion"
testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
testImplementation "org.powermock:powermock-classloading-xstream:$powerMockVersion"
testImplementation 'org.assertj:assertj-core:3.15.0'


testImplementation "com.android.installreferrer:installreferrer:1.0"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_ver"
testImplementation(Libs.junit)
testImplementation(Libs.robolectric)
testImplementation(Libs.androidx_test_core)
testImplementation(Libs.mockito_inline)
testImplementation(Libs.mockito_kotlin)

testImplementation(Libs.powermock_core)
testImplementation(Libs.powermock_api_mockito2)
testImplementation(Libs.powermock_junit4)
testImplementation(Libs.powermock_junit4_rule)
testImplementation(Libs.powermock_classloading_xstream)
testImplementation(Libs.assertj_core)

testImplementation(Libs.android_installreferrer)
testImplementation(Libs.kotlin_test_junit)
}

android {
compileSdkVersion project.ext.compileSdk
compileSdkVersion(Config.compileSdk)
// The version of Jacoco used by the android gradle plugin
jacoco {
version "0.8.7"
}

defaultConfig {
minSdkVersion project.ext.minSdk
targetSdkVersion project.ext.targetSdk
minSdkVersion(Config.minSdk)
targetSdkVersion(Config.targetSdk)
consumerProguardFiles 'proguard-rules.pro'
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
}

aaptOptions {
Expand Down
Loading

0 comments on commit 3191cef

Please sign in to comment.