From b06f30ed3b7980c0cfc4c87ce0eb040fd5b1cf36 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 8 Sep 2022 14:45:15 -0400 Subject: [PATCH 01/10] converting koin branch over to kts stable build checkpoint --- app/build.gradle | 365 -------------------------- app/build.gradle.kts | 373 +++++++++++++++++++++++++++ build.gradle | 147 ----------- build.gradle.kts | 128 +++++++++ buildSrc/build.gradle.kts | 9 + buildSrc/src/main/kotlin/Versions.kt | 51 ++++ settings.gradle | 1 - settings.gradle.kts | 1 + 8 files changed, 562 insertions(+), 513 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/Versions.kt delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 089543d4..00000000 --- a/app/build.gradle +++ /dev/null @@ -1,365 +0,0 @@ -buildscript { - repositories { - google() - mavenCentral() - } -} - -plugins { - id "com.android.application" - id "org.jlleitschuh.gradle.ktlint" - - id "kotlin-android" - id "kotlin-kapt" - id "kotlin-allopen" - id "kotlin-parcelize" - - id "com.google.firebase.crashlytics" - - id "pmd" - id "checkstyle" - id "jacoco" -} - -android { - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 - } - - compileSdkVersion rootProject.ext.compileSdkVersion - - defaultConfig { - applicationId 'com.atomicrobot.carbon' - - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - multiDexEnabled true - - versionCode rootProject.ext.versionCode - versionName rootProject.ext.versionName - - buildConfigField "String", "VERSION_FINGERPRINT", rootProject.ext.versionFingerprint - - proguardFile getDefaultProguardFile('proguard-android.txt') - proguardFile 'proguard-rules.pro' - - testInstrumentationRunner 'com.atomicrobot.carbon.CustomAppTestRunner' - vectorDrawables { - useSupportLibrary true - } - } - - signingConfigs { - // If you are creating signing keys, consider setting up Google Play App Signing! - // See: https://developer.android.com/studio/publish/app-signing.html#google-play-app-signing - release { - apply from: rootProject.file('distribution/keys/sample.gradle') - - storeFile rootProject.file(sampleKeystore) - storePassword sampleKeystorePassword - keyAlias sampleKeyAlias - keyPassword sampleKeyPassword - } - // Use debug.keystore in this project so that debug version works with AR's Carbon web link - // setup. You can safely remove this section if you are not using web linking within your app - debug { - storeFile rootProject.file('distribution/keys/debug.keystore') - keyAlias 'androiddebugkey' - keyPassword 'android' - storePassword 'android' - } - } - - flavorDimensions "app" - productFlavors { - dev { - dimension "app" - applicationId 'com.atomicrobot.carbon.dev' - } - prod { - dimension "app" - applicationId 'com.atomicrobot.carbon' - } - } - - buildTypes { - debug { - minifyEnabled false - shrinkResources false - testCoverageEnabled true - } - - release { - minifyEnabled true - shrinkResources true - signingConfig signingConfigs.release - } - } - - - dataBinding { - enabled = true - } - - testOptions { - animationsDisabled true - - unitTests { - includeAndroidResources = true - } - } - buildFeatures { - compose true - } - composeOptions { - kotlinCompilerExtensionVersion compose_version - } - packagingOptions { - resources { - excludes += '/META-INF/{AL2.0,LGPL2.1}' - } - } - namespace 'com.atomicrobot.carbon' - lint { - abortOnError true - htmlReport true - lintConfig file('lint.xml') - } -} - -ext { - // App dependency versions - appCompatVersion = '1.4.1' - supportVersion = '1.0.0' - playServicesVersion = '18.0.1' - lifecycleVersion = '2.0.0' - lifecycleRuntimeVersion = '2.4.1' - koinVersion = '3.2.0' - retrofitVersion = '2.9.0' - okHttpVersion = '4.9.1' - moshiVersion = '1.13.0' - coreVersion = '1.7.0' - constraintLayoutVersion = '2.1.3' - recyclerViewVersion = '1.2.1' - materialVersion = '1.6.0' - rxJavaVersion = '2.2.21' - rxAndroidVersion = '2.1.1' - timberVersion = '5.0.1' - leakCanaryVersion = '2.7' - - // Test dependency versions - mockitoVersion = '4.4.0' - mockitoKotlinVersion = '1.6.0' - robolectricVersion = '4.7.3' - androidTestSupportVersion = '1.4.0' - espressoVersion = '3.4.0' - junitVersion = '4.13.2' - junitTestVersion = '1.1.3' -} - -dependencies { - implementation platform("com.google.firebase:firebase-bom:$rootProject.ext.firebase_bom_version") - implementation "com.google.firebase:firebase-analytics-ktx" - - // Add the Firebase Crashlytics SDK. - implementation "com.google.firebase:firebase-crashlytics:$rootProject.ext.firebase_crashlytics_version" - - // Recommended: Add the Google Analytics SDK. - implementation "com.google.firebase:firebase-analytics:$rootProject.ext.firebase_analytics_version" - - implementation "androidx.compose.ui:ui:$compose_version" - // Compose Material Design - implementation "androidx.compose.material:material:$compose_version" - // Animations - implementation "androidx.compose.animation:animation:$compose_version" - implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" - // Integration with activities - implementation "androidx.activity:activity-compose:$compose_act_version" - - androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" - // Tooling support (Previews, etc.) - debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" - // Integration with ViewModels - implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$compose_vm_version" - // UI Tests - debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" - - implementation "androidx.compose.foundation:foundation:$compose_foundation_verison" - - /* - * Starting from Kotlin 1.4 the Kotlin standard library dependency doesn't need to be added - * explicitly. An implicit dep. w/ the same version as the Kotlin Gradle plugin will - * implicitly be added. - * - * link: https://stackoverflow.com/a/64988522/3591491 - */ - /*implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"*/ - kapt "androidx.databinding:databinding-compiler:$rootProject.ext.android_plugin_version" - // Need this because of Kotlin - - // Android/Google libraries - implementation "androidx.core:core-ktx:$coreVersion" - implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion" - implementation "androidx.appcompat:appcompat:$appCompatVersion" - implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion" - implementation "androidx.cardview:cardview:$supportVersion" - implementation "androidx.annotation:annotation:$supportVersion" - implementation "com.google.android.material:material:$materialVersion" - - implementation "com.google.android.gms:play-services-base:$playServicesVersion" - - implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleRuntimeVersion" - implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" - implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" - - // App architecture - Koin - implementation "io.insert-koin:koin-android:$koinVersion" - implementation "io.insert-koin:koin-androidx-compose:$koinVersion" - - // App architecture - RxJava - implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion" - implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion" - - // JSON - implementation "com.squareup.moshi:moshi-kotlin:$moshiVersion" - kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion" - - // Navigation - implementation "androidx.navigation:navigation-compose:2.4.2" - implementation "android.arch.navigation:navigation-fragment-ktx:$navigation_version" - implementation "android.arch.navigation:navigation-ui-ktx:$navigation_version" - - // Networking - HTTP - implementation "com.squareup.okhttp3:okhttp:$okHttpVersion" - implementation "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion" - - // Networking - REST - implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" - implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion" - implementation "com.squareup.retrofit2:converter-moshi:$retrofitVersion" - - // Monitoring - Timber (logging) - implementation "com.jakewharton.timber:timber:$timberVersion" - - // Monitoring - Leak Canary - debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" - - // Unit test - testImplementation "junit:junit:$junitVersion" - testImplementation "androidx.test:rules:$androidTestSupportVersion" - testImplementation "androidx.test:core:$androidTestSupportVersion" - testImplementation "androidx.test.ext:junit:$junitTestVersion" - testImplementation "org.robolectric:robolectric:$robolectricVersion" - testImplementation "org.mockito:mockito-core:$mockitoVersion" - testImplementation "com.nhaarman:mockito-kotlin-kt1.1:$mockitoKotlinVersion" - testImplementation "com.squareup.okhttp3:mockwebserver:$okHttpVersion" - - - // Android JUnit Runner, JUnit Rules, and Espresso - // Android JUnit Runner, JUnit Rules, and Espresso - androidTestImplementation "androidx.test:runner:$androidTestSupportVersion" - androidTestImplementation "androidx.test:rules:$androidTestSupportVersion" - androidTestImplementation "androidx.test:core:$androidTestSupportVersion" - androidTestImplementation "androidx.test.ext:junit:$junitTestVersion" - androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion" - androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion" - - androidTestImplementation "org.mockito:mockito-android:$mockitoVersion" - androidTestImplementation "com.nhaarman:mockito-kotlin-kt1.1:$mockitoKotlinVersion" -} - - -task pmd(type: Pmd, dependsOn: "assembleDebug") { - ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") - ruleSets = [] - // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... - source = fileTree('src/main/java/') - exclude '**/gen/**' - reports { - // html.enabled = true - // xml.enabled = false - xml.required.set(false) - html.required.set(true) - } -} - -task checkstyle(type: Checkstyle, dependsOn: "assembleDebug") { - configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") - source 'src' - include '**/*.java' - exclude '**/gen/**', '**/test/**', '**/androidTest/**' - reports { - // xml.enabled false - // html.enabled true - xml.required.set(false) - html.required.set(true) - } - classpath = files(file("${project.rootDir}/app/build/intermediates/classes")) - configProperties = [ - 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), - ] -} - -jacoco { - toolVersion = rootProject.ext.jacoco_version -} - -tasks.withType(Test) { - jacoco.includeNoLocationClasses = true - jacoco.excludes = ['jdk.internal.*'] -} - -task jacocoTestReport(type: JacocoReport, dependsOn: ['testDevDebugUnitTest', 'createDevDebugCoverageReport']) { - reports { - // xml.enabled = true - // html.enabled = true - xml.required.set(true) - html.required.set(true) - } - - def excludes = [ - '**/R.class', - '**/R$*.class', - '**/BuildConfig.*', - '**/Manifest*.*', - '**/*Test*.*', - 'android/**/*.*', - /* Parcelize */ - '**/*Creator.*', - /* Data binding */ - '**/*Binding*.*', - '**/BR.**' - ] - - getClassDirectories().setFrom(fileTree( - // Java generated classes on Android project (debug build) - dir: "$buildDir/intermediates/classes/dev/debug", - excludes: excludes - ) + fileTree( - // Kotlin generated classes on Android project (debug build) - dir: "$buildDir/tmp/kotlin-classes/devDebug", - excludes: excludes - )) - - getSourceDirectories().setFrom(files([ - "src/main/java", - "src/main/kotlin" - ])) - - getExecutionData().setFrom(fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDevDebugUnitTest.exec', - 'outputs/code-coverage/connected/**/*coverage.ec' - ])) -} - -// Kotlin plugin for testing -allOpen { - annotation("com.atomicrobot.carbon.Mockable") -} - -apply plugin: 'com.google.gms.google-services' diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 00000000..24d3f062 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,373 @@ +buildscript { + repositories { + google() + mavenCentral() + } +} + +plugins { + id("com.android.application") + id("org.jlleitschuh.gradle.ktlint") + id("kotlin-android") + id("kotlin-kapt") + id("kotlin-allopen") + id("kotlin-parcelize") + id("com.google.firebase.crashlytics") + id("pmd") + id("checkstyle") + id("jacoco") + id("com.google.gms.google-services") +} + +var versionCode = 1 +if (project.hasProperty("buildNumber")) { + versionCode = Integer.parseInt(project.property("buildNumber").toString()) +} +val version = versionCode +var versionFingerprint = "\"DEV\"" +if (project.hasProperty("fingerprint")) { + versionFingerprint = "\"" + project.property("fingerprint").toString() + "\"" +} + +android { + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = "11" + } + + compileSdk = ConfigVals.compileSdkVersion + + defaultConfig { + applicationId = "com.atomicrobot.carbon" + + minSdk = ConfigVals.minSdkVersion + targetSdk = ConfigVals.targetSdkVersion + + multiDexEnabled = true + + versionCode = version + + buildConfigField("String", "VERSION_FINGERPRINT", versionFingerprint) + +// proguardFile getDefaultProguardFile("proguard-android.txt") +// proguardFile "proguard-rules.pro" + proguardFiles("proguard-android.txt", "proguard-rules.pro") + + testInstrumentationRunner = "com.atomicrobot.carbon.CustomAppTestRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + signingConfigs { + // If you are creating signing keys, consider setting up Google Play App Signing! + // See: https://developer.android.com/studio/publish/app-signing.html#google-play-app-signing + create("release") { + apply(rootProject.file("distribution/keys/sample.gradle")) + + storeFile = rootProject.file("sampleKeystore") + storePassword = "sampleKeystorePassword" + keyAlias = "sampleKeyAlias" + keyPassword = "sampleKeyPassword" + } + // Use debug.keystore in this project so that debug version works with AR"s Carbon web link + // setup. You can safely remove this section if you are not using web linking within your app + getByName("debug") { + storeFile = rootProject.file("distribution/keys/debug.keystore") + keyAlias = "androiddebugkey" + keyPassword = "android" + storePassword = "android" + } + } + + flavorDimensions("app") + productFlavors { + create("dev") { + dimension = "app" + applicationId = "com.atomicrobot.carbon.dev" + } + create("prod") { + dimension = "app" + applicationId = "com.atomicrobot.carbon" + } + } + + buildTypes { + getByName("debug") { + isMinifyEnabled = false + isShrinkResources = false + isTestCoverageEnabled = true + } + + getByName("release") { + isMinifyEnabled = true + isShrinkResources = true + signingConfig = signingConfigs.getByName("release") + } + } + + + dataBinding { + isEnabled = true + } + + testOptions { + animationsDisabled = true + + unitTests { + isIncludeAndroidResources = true + } + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "${Dependencies.composeVersion}" + } + packagingOptions { + resources { + excludes += ("/META-INF/{AL2.0,LGPL2.1}") + } + } + namespace = "com.atomicrobot.carbon" + lint { + abortOnError = true + htmlReport = true +// lintConfig file("lint.xml") + } +} + + // App dependency versions + val appCompatVersion = "1.4.1" + val supportVersion = "1.0.0" + val playServicesVersion = "18.0.1" + val lifecycleVersion = "2.0.0" + val lifecycleRuntimeVersion = "2.4.1" + val koinVersion = "3.2.0" + val retrofitVersion = "2.9.0" + val okHttpVersion = "4.9.1" + val moshiVersion = "1.13.0" + val coreVersion = "1.7.0" + val constraintLayoutVersion = "2.1.3" + val recyclerViewVersion = "1.2.1" + val materialVersion = "1.6.0" + val rxJavaVersion = "2.2.21" + val rxAndroidVersion = "2.1.1" + val timberVersion = "5.0.1" + val leakCanaryVersion = "2.7" + + // Test dependency versions + val mockitoVersion = "4.4.0" + val mockitoKotlinVersion = "1.6.0" + val robolectricVersion = "4.7.3" + val androidTestSupportVersion = "1.4.0" + val espressoVersion = "3.4.0" + val junitVersion = "4.13.2" + val junitTestVersion = "1.1.3" + + +dependencies { + implementation(platform("com.google.firebase:firebase-bom:${Dependencies.firebaseBomVersion}")) + implementation("com.google.firebase:firebase-analytics-ktx") + + // Add the Firebase Crashlytics SDK. + implementation("com.google.firebase:firebase-crashlytics:${Dependencies.firebaseCrashlyticsVersion}") + + // Recommended: Add the Google Analytics SDK. + implementation("com.google.firebase:firebase-analytics:${Dependencies.firebaseAnalyticsVersion}") + + implementation("androidx.compose.ui:ui:${Dependencies.composeVersion}") + // Compose Material Design + implementation("androidx.compose.material:material:${Dependencies.composeVersion}") + // Animations + implementation("androidx.compose.animation:animation:${Dependencies.composeVersion}") + implementation("androidx.compose.ui:ui-tooling-preview:${Dependencies.composeVersion}") + // Integration with activities + implementation("androidx.activity:activity-compose:${Dependencies.composeActVersion}") + + androidTestImplementation("androidx.compose.ui:ui-test-junit4:${Dependencies.composeVersion}") + // Tooling support (Previews, etc.) + debugImplementation("androidx.compose.ui:ui-tooling:${Dependencies.composeVersion}") + // Integration with ViewModels + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:${Dependencies.composeVmVersion}") + // UI Tests + debugImplementation("androidx.compose.ui:ui-test-manifest:${Dependencies.composeVersion}") + + implementation("androidx.compose.foundation:foundation:${Dependencies.composeFoundationVersion}") + + /* + * Starting from Kotlin 1.4 the Kotlin standard library dependency doesn't need to be added + * explicitly. An implicit dep. w/ the same version as the Kotlin Gradle plugin will + * implicitly be added. + * + * link: https://stackoverflow.com/a/64988522/3591491 + */ + /*implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"*/ + kapt("androidx.databinding:databinding-compiler:$ext.android_plugin_version") + // Need this because of Kotlin + + // Android/Google libraries + implementation("androidx.core:core-ktx:${Dependencies.coreVersion}") + implementation("androidx.constraintlayout:constraintlayout:${Dependencies.constraintLayoutVersion}") + implementation("androidx.appcompat:appcompat:${Dependencies.appCompatVersion}") + implementation("androidx.recyclerview:recyclerview:${Dependencies.recyclerViewVersion}") + implementation("androidx.cardview:cardview:${Dependencies.supportVersion}") + implementation("androidx.annotation:annotation:${Dependencies.supportVersion}") + implementation("com.google.android.material:material:${Dependencies.materialVersion}") + + implementation("com.google.android.gms:play-services-base:${Dependencies.playServicesVersion}") + + implementation("androidx.lifecycle:lifecycle-runtime-ktx:${Dependencies.lifecycleRuntimeVersion}") + implementation("androidx.lifecycle:lifecycle-extensions:${Dependencies.lifecycleVersion}") + implementation("androidx.lifecycle:lifecycle-common-java8:${Dependencies.lifecycleVersion}") + + // App architecture - Koin + implementation("io.insert-koin:koin-android:${Dependencies.koinVersion}") + implementation("io.insert-koin:koin-androidx-compose:${Dependencies.koinVersion}") + + // App architecture - RxJava + implementation("io.reactivex.rxjava2:rxjava:${Dependencies.rxJavaVersion}") + implementation("io.reactivex.rxjava2:rxandroid:${Dependencies.rxAndroidVersion}") + + // JSON + implementation("com.squareup.moshi:moshi-kotlin:${Dependencies.moshiVersion}") + kapt("com.squareup.moshi:moshi-kotlin-codegen:${Dependencies.moshiVersion}") + + // Navigation + implementation("androidx.navigation:navigation-compose:${Dependencies.composeNavigationVersion}") + implementation("android.arch.navigation:navigation-fragment-ktx:${Dependencies.navigationVersion}") + implementation("android.arch.navigation:navigation-ui-ktx:${Dependencies.navigationVersion}") + + // Networking - HTTP + implementation("com.squareup.okhttp3:okhttp:${Dependencies.okHttpVersion}") + implementation("com.squareup.okhttp3:okhttp-urlconnection:${Dependencies.okHttpVersion}") + + // Networking - REST + implementation("com.squareup.retrofit2:retrofit:${Dependencies.retrofitVersion}") + implementation("com.squareup.retrofit2:adapter-rxjava2:${Dependencies.retrofitVersion}") + implementation("com.squareup.retrofit2:converter-moshi:${Dependencies.retrofitVersion}") + + // Monitoring - Timber (logging) + implementation("com.jakewharton.timber:timber:${Dependencies.timberVersion}") + + // Monitoring - Leak Canary + debugImplementation("com.squareup.leakcanary:leakcanary-android:${Dependencies.leakCanaryVersion}") + + // Unit test + testImplementation("junit:junit:${Dependencies.junitVersion}") + testImplementation("androidx.test:rules:${Dependencies.androidTestSupportVersion}") + testImplementation("androidx.test:core:${Dependencies.androidTestSupportVersion}") + testImplementation("androidx.test.ext:junit:${Dependencies.junitTestVersion}") + testImplementation("org.robolectric:robolectric:${Dependencies.robolectricVersion}") + testImplementation("org.mockito:mockito-core:${Dependencies.mockitoVersion}") + testImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") + testImplementation("com.squareup.okhttp3:mockwebserver:${Dependencies.okHttpVersion}") + + + // Android JUnit Runner, JUnit Rules, and Espresso + // Android JUnit Runner, JUnit Rules, and Espresso + androidTestImplementation("androidx.test:runner:${Dependencies.androidTestSupportVersion}") + androidTestImplementation("androidx.test:rules:${Dependencies.androidTestSupportVersion}") + androidTestImplementation("androidx.test:core:${Dependencies.androidTestSupportVersion}") + androidTestImplementation("androidx.test.ext:junit:${Dependencies.junitTestVersion}") + androidTestImplementation("androidx.test.espresso:espresso-core:${Dependencies.espressoVersion}") + androidTestImplementation("androidx.test.espresso:espresso-contrib:${Dependencies.espressoVersion}") + + androidTestImplementation("org.mockito:mockito-android:${Dependencies.mockitoVersion}") + androidTestImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") +} + +// +//task pmd(type: Pmd, dependsOn: "assembleDebug") { +// ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") +// ruleSets = [] +// // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... +// source = fileTree('src/main/java/') +// exclude '**/gen/**' +// reports { +// // html.enabled = true +// // xml.enabled = false +// xml.required.set(false) +// html.required.set(true) +// } +//} +// +//task checkstyle(type: Checkstyle, dependsOn: "assembleDebug") { +// configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") +// source 'src' +// include '**/*.java' +// exclude '**/gen/**', '**/test/**', '**/androidTest/**' +// reports { +// // xml.enabled false +// // html.enabled true +// xml.required.set(false) +// html.required.set(true) +// } +// classpath = files(file("${project.rootDir}/app/build/intermediates/classes")) +// configProperties = [ +// 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), +// ] +//} +// +//jacoco { +// toolVersion = ext.jacoco_version +//} +// +//tasks.withType(Test) { +// jacoco.includeNoLocationClasses = true +// jacoco.excludes = ['jdk.internal.*'] +//} +// +//task jacocoTestReport(type: JacocoReport, dependsOn: ['testDevDebugUnitTest', 'createDevDebugCoverageReport']) { +// reports { +// // xml.enabled = true +// // html.enabled = true +// xml.required.set(true) +// html.required.set(true) +// } +// +// def excludes = [ +// '**/R.class', +// '**/R$*.class', +// '**/BuildConfig.*', +// '**/Manifest*.*', +// '**/*Test*.*', +// 'android/**/*.*', +// /* Parcelize */ +// '**/*Creator.*', +// /* Data binding */ +// '**/*Binding*.*', +// '**/BR.**' +// ] +// +// getClassDirectories().setFrom(fileTree( +// // Java generated classes on Android project (debug build) +// dir: "$buildDir/intermediates/classes/dev/debug", +// excludes: excludes +// ) + fileTree( +// // Kotlin generated classes on Android project (debug build) +// dir: "$buildDir/tmp/kotlin-classes/devDebug", +// excludes: excludes +// )) +// +// getSourceDirectories().setFrom(files([ +// "src/main/java", +// "src/main/kotlin" +// ])) +// +// getExecutionData().setFrom(fileTree(dir: project.buildDir, includes: [ +// 'jacoco/testDevDebugUnitTest.exec', +// 'outputs/code-coverage/connected/**/*coverage.ec' +// ])) +//} +// +//// Kotlin plugin for testing +//allOpen { +// annotation("com.atomicrobot.carbon.Mockable") +//} + +//apply plugin: 'com.google.gms.google-services' diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 85a2860b..00000000 --- a/build.gradle +++ /dev/null @@ -1,147 +0,0 @@ -buildscript { - ext { - compose_version = '1.1.1' - compose_act_version = '1.4.0' - compose_vm_version = '2.4.1' - compose_foundation_verison = '1.2.0-beta02' - } - ext.android_plugin_version = '7.2.1' - ext.kotlin_version = '1.6.10' - ext.jacoco_version = '0.8.6' - ext.navigation_version = '1.0.0' - ext.firebase_bom_version = '28.0.0' - ext.firebase_crashlytics_version = '18.2.10' - ext.firebase_analytics_version = '21.0.0' - ext.google_services_version = '4.3.10' - ext.firebase_crashlytics_gradle_version = '2.6.1' - ext.ktlint_version = '10.3.0' - - repositories { - google() - mavenCentral() - maven { - url "https://plugins.gradle.org/m2/" - } - } - - dependencies { - classpath "com.google.gms:google-services:$google_services_version" - classpath "com.google.firebase:firebase-crashlytics-gradle:$firebase_crashlytics_gradle_version" - classpath "com.android.tools.build:gradle:$android_plugin_version" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigation_version" - classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" - classpath "org.jacoco:org.jacoco.core:$jacoco_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_version" - } -} - -allprojects { - repositories { - google() - mavenCentral() - maven { url "https://jitpack.io" } - } - - // Automatically pull down javadocs and sources (if available) - apply plugin: 'idea' - idea { - module { - downloadJavadoc = true - downloadSources = true - } - } - - // Verbose output for usage of deprecated APIs - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:deprecation" - } -} - -// Disable predexing (enable on build servers) -project.ext.preDexLibs = !project.hasProperty('disablePreDex') -subprojects { - project.plugins.whenPluginAdded { plugin -> - if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { - project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs - } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { - project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs - } - } -} - -// Prevent wildcard dependencies -// https://gist.github.com/JakeWharton/2066f5e4f08fbaaa68fd -allprojects { - afterEvaluate { project -> - project.configurations.all { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - def requested = details.requested - if (requested.version.contains('+')) { - throw new GradleException("Wildcard dependency forbidden: ${requested.group}:${requested.name}:${requested.version}") - } - } - } - } -} - -ext { - // Build (this implementation assumes values are being provided as arguments, perhaps by a build server) - appVersion = "1.0" - versionFingerprint = project.hasProperty("fingerprint") ? ("\"" + fingerprint + "\"") : "\"DEV\"" - versionCode = project.hasProperty("buildNumber") ? Integer.parseInt(buildNumber) : 1 - versionName = "$appVersion b$versionCode" - - // Build settings that are likely to be reused across different modules - minSdkVersion = 21 - targetSdkVersion = 32 - compileSdkVersion = 32 -} - -evaluationDependsOnChildren() - -task initialCleanup() { - def cleanTasks = getProjectTask(this, 'clean') - def uninstallTasks = getProjectTask(this, 'uninstallAll') - - dependsOn cleanTasks - dependsOn uninstallTasks -} - -task testing() { - def appProject = subprojects.find { project -> 'app' == project.name } - - def unitTestTasks = getProjectTask(appProject, 'testDevDebugUnitTest') - def integrationTestTasks = getProjectTask(appProject, 'jacocoTestReport') - - dependsOn unitTestTasks - dependsOn integrationTestTasks - - integrationTestTasks.each { task -> task.mustRunAfter unitTestTasks } -} - -task release() { - def appProject = subprojects.find { project -> 'app' == project.name } - - def appTasks = getProjectTask(appProject, 'assemble') - - dependsOn appTasks -} - -static def getProjectTask(project, taskName) { - def tasks = project.getTasksByName(taskName, true) - if (tasks == null || tasks.empty) { - throw new IllegalArgumentException("Task " + taskName + " not found") - } - return tasks -} - -task continuousIntegration() { - dependsOn initialCleanup - dependsOn testing - dependsOn release - - // Static analysis first, then testing, then release - testing.mustRunAfter initialCleanup - release.mustRunAfter testing -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..4ef58b62 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,128 @@ +buildscript { + + val android_plugin_version = "7.2.1" + val kotlin_version = "1.6.10" + val jacoco_version = "0.8.6" + val navigation_version = "1.0.0" + val google_services_version = "4.3.10" + val firebase_crashlytics_gradle_version = "2.6.1" + val ktlint_version = "10.3.0" + + repositories { + google() + mavenCentral() + maven { + url = uri("https://plugins.gradle.org/m2/") + } + } + + dependencies { + classpath("com.google.gms:google-services:$google_services_version") + classpath("com.google.firebase:firebase-crashlytics-gradle:$firebase_crashlytics_gradle_version") + classpath("com.android.tools.build:gradle:$android_plugin_version") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") + classpath("android.arch.navigation:navigation-safe-args-gradle-plugin:$navigation_version") + classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version") + classpath("org.jacoco:org.jacoco.core:$jacoco_version") + classpath("org.jlleitschuh.gradle:ktlint-gradle:$ktlint_version") + } +} + +allprojects { + repositories { + google() + mavenCentral() + maven { url = uri("https://jitpack.io") } + } + + // Automatically pull down javadocs and sources (if available) +// apply(plugin = "idea") +// idea { +// module { +// isDownloadJavadoc = true +// isDownloadSources = true +// } +// } + + // Verbose output for usage of deprecated APIs + tasks.withType { + options.compilerArgs = mutableListOf("-Xlint:deprecation") + } +} + +//// Disable predexing (enable on build servers) +//project.ext.preDexLibs = !project.hasProperty('disablePreDex') +//subprojects { +// project.plugins.whenPluginAdded { plugin -> +// if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { +// project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs +// } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { +// project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs +// } +// } +//} + +// Prevent wildcard dependencies +// https://gist.github.com/JakeWharton/2066f5e4f08fbaaa68fd +//allprojects { +// afterEvaluate { project -> +// project.configurations.all { +// resolutionStrategy.eachDependency { DependencyResolveDetails details -> +// def requested = details.requested +// if (requested.version.contains('+')) { +// throw new GradleException("Wildcard dependency forbidden: ${requested.group}:${requested.name}:${requested.version}") +// } +// } +// } +// } +//} + + +// +//evaluationDependsOnChildren() +// +//task initialCleanup() { +// def cleanTasks = getProjectTask(this, 'clean') +// def uninstallTasks = getProjectTask(this, 'uninstallAll') +// +// dependsOn cleanTasks +// dependsOn uninstallTasks +//} +// +//task testing() { +// def appProject = subprojects.find { project -> 'app' == project.name } +// +// def unitTestTasks = getProjectTask(appProject, 'testDevDebugUnitTest') +// def integrationTestTasks = getProjectTask(appProject, 'jacocoTestReport') +// +// dependsOn unitTestTasks +// dependsOn integrationTestTasks +// +// integrationTestTasks.each { task -> task.mustRunAfter unitTestTasks } +//} +// +//task release() { +// def appProject = subprojects.find { project -> 'app' == project.name } +// +// def appTasks = getProjectTask(appProject, 'assemble') +// +// dependsOn appTasks +//} +// +//static def getProjectTask(project, taskName) { +// def tasks = project.getTasksByName(taskName, true) +// if (tasks == null || tasks.empty) { +// throw new IllegalArgumentException("Task " + taskName + " not found") +// } +// return tasks +//} +// +//task continuousIntegration() { +// dependsOn initialCleanup +// dependsOn testing +// dependsOn release +// +// // Static analysis first, then testing, then release +// testing.mustRunAfter initialCleanup +// release.mustRunAfter testing +//} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 00000000..8e88a958 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,9 @@ +import org.gradle.kotlin.dsl.`kotlin-dsl` + +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 00000000..a0182674 --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,51 @@ +object Dependencies { + const val composeVersion = "1.1.1" + const val composeActVersion = "1.4.0" + const val composeVmVersion = "2.4.1" + const val composeFoundationVersion = "1.2.0-beta02" + const val androidPluginVersion = "7.2.1" + const val kotlinVersion = "1.6.10" + const val jacocoVersion = "0.8.6" + const val navigationVersion = "1.0.0" + const val firebaseBomVersion = "28.0.0" + const val firebaseCrashlyticsVersion = "18.2.10" + const val firebaseAnalyticsVersion = "21.0.0" + const val googleServicesVersion = "4.3.10" + const val firebaseCrashlyticsGradleVersion = "2.6.1" + const val ktlintVersion = "10.3.0" + const val appCompatVersion = "1.4.1" + const val supportVersion = "1.0.0" + const val playServicesVersion = "18.0.1" + const val lifecycleVersion = "2.0.0" + const val lifecycleRuntimeVersion = "2.4.1" + const val koinVersion = "3.2.0" + const val retrofitVersion = "2.9.0" + const val okHttpVersion = "4.9.1" + const val moshiVersion = "1.13.0" + const val coreVersion = "1.7.0" + const val constraintLayoutVersion = "2.1.3" + const val recyclerViewVersion = "1.2.1" + const val materialVersion = "1.6.0" + const val rxJavaVersion = "2.2.21" + const val rxAndroidVersion = "2.1.1" + const val timberVersion = "5.0.1" + const val leakCanaryVersion = "2.7" + const val composeNavigationVersion = "2.4.2" + + // Test dependency versions + const val mockitoVersion = "4.4.0" + const val mockitoKotlinVersion = "1.6.0" + const val robolectricVersion = "4.7.3" + const val androidTestSupportVersion = "1.4.0" + const val espressoVersion = "3.4.0" + const val junitVersion = "4.13.2" + const val junitTestVersion = "1.1.3" +} + +object ConfigVals { + const val appVersion = "1.0" + const val versionFingerprint = "TODO" + const val minSdkVersion = 29 + const val targetSdkVersion = 32 + const val compileSdkVersion = 32 +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index e7b4def4..00000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..15a801b1 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +include(":app") From 42131d4a18ad8dd066be3f5fedb1515e3afcdc8b Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 8 Sep 2022 15:38:32 -0400 Subject: [PATCH 02/10] some cleanup --- app/build.gradle.kts | 173 ++++++++++++++++++++++++++----------------- build.gradle.kts | 161 +++++++++++++++++----------------------- 2 files changed, 177 insertions(+), 157 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 24d3f062..a92c8c7a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,8 +53,6 @@ android { buildConfigField("String", "VERSION_FINGERPRINT", versionFingerprint) -// proguardFile getDefaultProguardFile("proguard-android.txt") -// proguardFile "proguard-rules.pro" proguardFiles("proguard-android.txt", "proguard-rules.pro") testInstrumentationRunner = "com.atomicrobot.carbon.CustomAppTestRunner" @@ -207,7 +205,7 @@ dependencies { * link: https://stackoverflow.com/a/64988522/3591491 */ /*implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"*/ - kapt("androidx.databinding:databinding-compiler:$ext.android_plugin_version") + kapt("androidx.databinding:databinding-compiler:${Dependencies.androidPluginVersion}") // Need this because of Kotlin // Android/Google libraries @@ -281,13 +279,13 @@ dependencies { androidTestImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") } -// -//task pmd(type: Pmd, dependsOn: "assembleDebug") { +//task("pmd") { +// dependsOn = "assembleDebug" // ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") // ruleSets = [] // // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... -// source = fileTree('src/main/java/') -// exclude '**/gen/**' +// source = fileTree("src/main/java/") +// exclude "**/gen/**" // reports { // // html.enabled = true // // xml.enabled = false @@ -295,7 +293,8 @@ dependencies { // html.required.set(true) // } //} -// + + //task checkstyle(type: Checkstyle, dependsOn: "assembleDebug") { // configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") // source 'src' @@ -312,62 +311,104 @@ dependencies { // 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), // ] //} -// -//jacoco { -// toolVersion = ext.jacoco_version -//} -// -//tasks.withType(Test) { -// jacoco.includeNoLocationClasses = true -// jacoco.excludes = ['jdk.internal.*'] -//} -// -//task jacocoTestReport(type: JacocoReport, dependsOn: ['testDevDebugUnitTest', 'createDevDebugCoverageReport']) { -// reports { -// // xml.enabled = true -// // html.enabled = true -// xml.required.set(true) -// html.required.set(true) -// } -// -// def excludes = [ -// '**/R.class', -// '**/R$*.class', -// '**/BuildConfig.*', -// '**/Manifest*.*', -// '**/*Test*.*', -// 'android/**/*.*', -// /* Parcelize */ -// '**/*Creator.*', -// /* Data binding */ -// '**/*Binding*.*', -// '**/BR.**' -// ] -// -// getClassDirectories().setFrom(fileTree( -// // Java generated classes on Android project (debug build) -// dir: "$buildDir/intermediates/classes/dev/debug", -// excludes: excludes -// ) + fileTree( -// // Kotlin generated classes on Android project (debug build) -// dir: "$buildDir/tmp/kotlin-classes/devDebug", -// excludes: excludes -// )) -// -// getSourceDirectories().setFrom(files([ -// "src/main/java", -// "src/main/kotlin" -// ])) -// -// getExecutionData().setFrom(fileTree(dir: project.buildDir, includes: [ -// 'jacoco/testDevDebugUnitTest.exec', -// 'outputs/code-coverage/connected/**/*coverage.ec' -// ])) -//} -// -//// Kotlin plugin for testing -//allOpen { -// annotation("com.atomicrobot.carbon.Mockable") -//} -//apply plugin: 'com.google.gms.google-services' +jacoco { + toolVersion = Dependencies.jacocoVersion +} + +tasks.withType { + configure { + isIncludeNoLocationClasses = true + excludes = mutableListOf("jdk.internal.*") + } +} +// would not build as a private val +val fileFilter = mutableSetOf( + "**/R.class", + "**/R\$*.class", + "**/BuildConfig.*", + "**/Manifest*.*", + "**/*Test*.*", + "android/**/*.*", + /* Parcelize */ + "**/*Creator.*", + /* Data binding */ + "**/*Binding*.*", + "**/BR.**", + /* Dagger */ + "**/*_MembersInjector.*", + "**/*_Factory.*", + "**/*_*Factory.*", + "**/Dagger*Component*.*", + "**/Dagger*Subcomponent*.*", + "**/devsettings/**/*.*" +) +private val classDirectoriesTree = fileTree(project.buildDir) { + include( + "" + ) + exclude(fileFilter) +} + +private val sourceDirectoriesTree = fileTree("${project.buildDir}") { + include( + "src/main/java/**", + "src/main/kotlin/**" + ) +} +private val executionDataTree = fileTree(project.buildDir) { + include( + "outputs/code_coverage/**/*.ec", + "jacoco/jacocoTestReportDebug.exec", + "jacoco/testDevDebugUnitTest.exec", + "jacoco/test.exec" + ) +} +fun JacocoReportsContainer.reports() { + xml.required.set(true) + html.required.set(true) +} +fun JacocoCoverageVerification.setDirectories() { + sourceDirectories.setFrom(sourceDirectoriesTree) + classDirectories.setFrom(classDirectoriesTree) + executionData.setFrom(executionDataTree) +} +fun JacocoReport.setDirectories() { + sourceDirectories.setFrom(sourceDirectoriesTree) + classDirectories.setFrom(classDirectoriesTree) + executionData.setFrom(executionDataTree) +} + +if (tasks.findByName("jacocoTestReport") == null) { + + tasks.register("jacocoTestReport") { + description = "Code coverage report for both Android and Unit tests." + dependsOn("testDevDebugUnitTest") + reports { + reports() + } + setDirectories() + } +} +if (tasks.findByName("jacocoAndroidCoverageVerification") == null) { + tasks.register("jacocoAndroidCoverageVerification") { + description = "Code coverage verification for Android both Android and Unit tests." + dependsOn("testDevDebugUnitTest") + violationRules { + rule { + limit { + counter = "INSTRUCTIONAL" + value = "COVEREDRATIO" + minimum = "0.5".toBigDecimal() + } + } + } + setDirectories() + } +} +// Kotlin plugin for testing +allOpen { + annotation("com.atomicrobot.carbon.Mockable") +} + +apply(plugin = "com.google.gms.google-services") diff --git a/build.gradle.kts b/build.gradle.kts index 4ef58b62..333c348b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,5 @@ buildscript { - val android_plugin_version = "7.2.1" - val kotlin_version = "1.6.10" - val jacoco_version = "0.8.6" - val navigation_version = "1.0.0" - val google_services_version = "4.3.10" - val firebase_crashlytics_gradle_version = "2.6.1" - val ktlint_version = "10.3.0" - repositories { google() mavenCentral() @@ -17,14 +9,14 @@ buildscript { } dependencies { - classpath("com.google.gms:google-services:$google_services_version") - classpath("com.google.firebase:firebase-crashlytics-gradle:$firebase_crashlytics_gradle_version") - classpath("com.android.tools.build:gradle:$android_plugin_version") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - classpath("android.arch.navigation:navigation-safe-args-gradle-plugin:$navigation_version") - classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlin_version") - classpath("org.jacoco:org.jacoco.core:$jacoco_version") - classpath("org.jlleitschuh.gradle:ktlint-gradle:$ktlint_version") + classpath("com.google.gms:google-services:${Dependencies.googleServicesVersion}") + classpath("com.google.firebase:firebase-crashlytics-gradle:${Dependencies.firebaseCrashlyticsGradleVersion}") + classpath("com.android.tools.build:gradle:${Dependencies.androidPluginVersion}") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Dependencies.kotlinVersion}") + classpath("android.arch.navigation:navigation-safe-args-gradle-plugin:${Dependencies.navigationVersion}") + classpath("org.jetbrains.kotlin:kotlin-allopen:${Dependencies.kotlinVersion}") + classpath("org.jacoco:org.jacoco.core:${Dependencies.jacocoVersion}") + classpath("org.jlleitschuh.gradle:ktlint-gradle:${Dependencies.ktlintVersion}") } } @@ -36,7 +28,7 @@ allprojects { } // Automatically pull down javadocs and sources (if available) -// apply(plugin = "idea") + apply(plugin = "idea") // idea { // module { // isDownloadJavadoc = true @@ -50,79 +42,66 @@ allprojects { } } -//// Disable predexing (enable on build servers) -//project.ext.preDexLibs = !project.hasProperty('disablePreDex') -//subprojects { -// project.plugins.whenPluginAdded { plugin -> -// if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { -// project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs -// } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { -// project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs -// } -// } -//} - // Prevent wildcard dependencies +// Code in groovy below // https://gist.github.com/JakeWharton/2066f5e4f08fbaaa68fd -//allprojects { -// afterEvaluate { project -> -// project.configurations.all { -// resolutionStrategy.eachDependency { DependencyResolveDetails details -> -// def requested = details.requested -// if (requested.version.contains('+')) { -// throw new GradleException("Wildcard dependency forbidden: ${requested.group}:${requested.name}:${requested.version}") -// } -// } -// } -// } -//} - - -// -//evaluationDependsOnChildren() -// -//task initialCleanup() { -// def cleanTasks = getProjectTask(this, 'clean') -// def uninstallTasks = getProjectTask(this, 'uninstallAll') -// -// dependsOn cleanTasks -// dependsOn uninstallTasks -//} -// -//task testing() { -// def appProject = subprojects.find { project -> 'app' == project.name } -// -// def unitTestTasks = getProjectTask(appProject, 'testDevDebugUnitTest') -// def integrationTestTasks = getProjectTask(appProject, 'jacocoTestReport') -// -// dependsOn unitTestTasks -// dependsOn integrationTestTasks -// -// integrationTestTasks.each { task -> task.mustRunAfter unitTestTasks } -//} -// -//task release() { -// def appProject = subprojects.find { project -> 'app' == project.name } -// -// def appTasks = getProjectTask(appProject, 'assemble') -// -// dependsOn appTasks -//} -// -//static def getProjectTask(project, taskName) { -// def tasks = project.getTasksByName(taskName, true) -// if (tasks == null || tasks.empty) { -// throw new IllegalArgumentException("Task " + taskName + " not found") -// } -// return tasks -//} -// -//task continuousIntegration() { -// dependsOn initialCleanup -// dependsOn testing -// dependsOn release -// -// // Static analysis first, then testing, then release -// testing.mustRunAfter initialCleanup -// release.mustRunAfter testing -//} \ No newline at end of file +// modified Wharton's code for kts +allprojects { + afterEvaluate() { + project.configurations.all { + resolutionStrategy.eachDependency { + if (requested.version!!.contains("+")) { + throw GradleException("Wildcard dependency forbidden: ${requested.group}:" + + "${requested.name}:${requested.version}") + } + } + } + } +} + +evaluationDependsOnChildren() + +val initialCleanup by tasks.registering { + val cleanTasks = getProjectTask(rootProject, "clean") + val uninstallTasks = getProjectTask(rootProject, "uninstallAll") + dependsOn(cleanTasks) + dependsOn(uninstallTasks) +} + +val testing by tasks.registering { + val appProject = subprojects.find { project -> "app" == project.name } + + val unitTestTasks = getProjectTask(appProject!!, "testDevDebugUnitTest") + val integrationTestTasks = getProjectTask(appProject, "jacocoTestReport") + + dependsOn(unitTestTasks) + dependsOn(integrationTestTasks) + + integrationTestTasks.forEach { task -> task.mustRunAfter(unitTestTasks) } +} + +val release by tasks.registering { + val appProject = subprojects.find { project -> "app" == project.name } + + val appTasks = getProjectTask(appProject!!, "assemble") + + dependsOn(appTasks) +} + +release { + mustRunAfter(testing) +} + +fun getProjectTask(project: Project, taskName: String): MutableSet { + val tasks = project.getTasksByName(taskName, true) + if (tasks == null || tasks.isEmpty()) { + throw IllegalArgumentException("Task $taskName not found") + } + return tasks +} + +val continuousIntegration by tasks.registering { + dependsOn(initialCleanup) + dependsOn(testing) + dependsOn(release) +} \ No newline at end of file From a26c5ae68484f1d01c913ab10dbf9881efe9c03d Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 15 Sep 2022 09:34:47 -0400 Subject: [PATCH 03/10] stable checkpoint --- app/build.gradle.kts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a92c8c7a..e4754ac5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -108,7 +108,6 @@ android { } } - dataBinding { isEnabled = true } @@ -295,7 +294,10 @@ dependencies { //} -//task checkstyle(type: Checkstyle, dependsOn: "assembleDebug") { +//tasks.register("Checkstyle") { +// +////(type: Checkstyle, dependsOn: "assembleDebug") { +// dependsOn(assembleDebug) // configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") // source 'src' // include '**/*.java' From 8927268648f7eb4d497b721823ac44bff76e1468 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 15 Sep 2022 13:19:01 -0400 Subject: [PATCH 04/10] stable checkpoint --- app/build.gradle.kts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e4754ac5..80b2b19f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -278,13 +278,13 @@ dependencies { androidTestImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") } -//task("pmd") { -// dependsOn = "assembleDebug" +//tasks.named("pmd").configure { +// dependsOn("assembleDebug") // ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") -// ruleSets = [] +// ruleSets = mutableListOf() // // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... // source = fileTree("src/main/java/") -// exclude "**/gen/**" +// exclude("**/gen/**") // reports { // // html.enabled = true // // xml.enabled = false @@ -292,16 +292,16 @@ dependencies { // html.required.set(true) // } //} - - -//tasks.register("Checkstyle") { +// +// +//tasks.named("Checkstyle") { // ////(type: Checkstyle, dependsOn: "assembleDebug") { -// dependsOn(assembleDebug) +// dependsOn("assembleDebug") // configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") -// source 'src' -// include '**/*.java' -// exclude '**/gen/**', '**/test/**', '**/androidTest/**' +// source = fileTree("src") +// include("**/*.java") +// exclude("**/gen/**", "**/test/**", "**/androidTest/**") // reports { // // xml.enabled false // // html.enabled true @@ -309,9 +309,14 @@ dependencies { // html.required.set(true) // } // classpath = files(file("${project.rootDir}/app/build/intermediates/classes")) -// configProperties = [ -// 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), -// ] +//// +//// configProperties = [ +//// +////// checkstyle.cache.file = rootProject.file("build/checstyle.cache") +//// ] +//// configProperties = [ +//// 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), +//// ] //} jacoco { From 1502279488a28305042fd95a4908df7cdaf24428 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 15 Sep 2022 13:52:53 -0400 Subject: [PATCH 05/10] commiting to restart --- app/build.gradle.kts | 58 ++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 80b2b19f..d89a6006 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -278,46 +278,24 @@ dependencies { androidTestImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") } -//tasks.named("pmd").configure { -// dependsOn("assembleDebug") -// ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") -// ruleSets = mutableListOf() -// // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... -// source = fileTree("src/main/java/") -// exclude("**/gen/**") -// reports { -// // html.enabled = true -// // xml.enabled = false -// xml.required.set(false) -// html.required.set(true) -// } -//} -// -// -//tasks.named("Checkstyle") { -// -////(type: Checkstyle, dependsOn: "assembleDebug") { -// dependsOn("assembleDebug") -// configFile = file("${project.rootDir}/config/checkstyle/checkstyle.xml") -// source = fileTree("src") -// include("**/*.java") -// exclude("**/gen/**", "**/test/**", "**/androidTest/**") -// reports { -// // xml.enabled false -// // html.enabled true -// xml.required.set(false) -// html.required.set(true) -// } -// classpath = files(file("${project.rootDir}/app/build/intermediates/classes")) -//// -//// configProperties = [ -//// -////// checkstyle.cache.file = rootProject.file("build/checstyle.cache") -//// ] -//// configProperties = [ -//// 'checkstyle.cache.file': rootProject.file('build/checkstyle.cache'), -//// ] -//} +tasks.register("pmd") { + +} + +tasks.named("pmd").configure { + dependsOn("assembleDebug") + ruleSetFiles = files("${project.rootDir}/config/pmd/pmd-ruleset.xml") + ruleSets = mutableListOf() + // See http://sourceforge.net/p/pmd/discussion/188193/thread/6e9c6017/ for why this is needed... + source = fileTree("src/main/java/") + exclude("**/gen/**") + reports { + // html.enabled = true + // xml.enabled = false + xml.required.set(false) + html.required.set(true) + } +} jacoco { toolVersion = Dependencies.jacocoVersion From 3a95bbfcbbb5eac34bc9272d81322463c0204eb1 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 15 Sep 2022 14:45:32 -0400 Subject: [PATCH 06/10] code cleanup --- app/build.gradle.kts | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d89a6006..7499883a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,7 +14,6 @@ plugins { id("kotlin-parcelize") id("com.google.firebase.crashlytics") id("pmd") - id("checkstyle") id("jacoco") id("com.google.gms.google-services") } @@ -138,35 +137,6 @@ android { } } - // App dependency versions - val appCompatVersion = "1.4.1" - val supportVersion = "1.0.0" - val playServicesVersion = "18.0.1" - val lifecycleVersion = "2.0.0" - val lifecycleRuntimeVersion = "2.4.1" - val koinVersion = "3.2.0" - val retrofitVersion = "2.9.0" - val okHttpVersion = "4.9.1" - val moshiVersion = "1.13.0" - val coreVersion = "1.7.0" - val constraintLayoutVersion = "2.1.3" - val recyclerViewVersion = "1.2.1" - val materialVersion = "1.6.0" - val rxJavaVersion = "2.2.21" - val rxAndroidVersion = "2.1.1" - val timberVersion = "5.0.1" - val leakCanaryVersion = "2.7" - - // Test dependency versions - val mockitoVersion = "4.4.0" - val mockitoKotlinVersion = "1.6.0" - val robolectricVersion = "4.7.3" - val androidTestSupportVersion = "1.4.0" - val espressoVersion = "3.4.0" - val junitVersion = "4.13.2" - val junitTestVersion = "1.1.3" - - dependencies { implementation(platform("com.google.firebase:firebase-bom:${Dependencies.firebaseBomVersion}")) implementation("com.google.firebase:firebase-analytics-ktx") @@ -264,7 +234,6 @@ dependencies { testImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") testImplementation("com.squareup.okhttp3:mockwebserver:${Dependencies.okHttpVersion}") - // Android JUnit Runner, JUnit Rules, and Espresso // Android JUnit Runner, JUnit Rules, and Espresso androidTestImplementation("androidx.test:runner:${Dependencies.androidTestSupportVersion}") @@ -278,9 +247,7 @@ dependencies { androidTestImplementation("com.nhaarman:mockito-kotlin-kt1.1:${Dependencies.mockitoKotlinVersion}") } -tasks.register("pmd") { - -} +tasks.register("pmd") {} tasks.named("pmd").configure { dependsOn("assembleDebug") From 177c67fbf6a5939688969edaab038a5df10d603e Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 15 Sep 2022 15:07:08 -0400 Subject: [PATCH 07/10] removed MaxPermSize(deprecated) so Daemon will build --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index db47ea6a..07588d89 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx8192m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.daemon=true org.gradle.configureondemand=false From 3c4d3301ee048417189ddb31ea8b2e2aeca76aad Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 22 Sep 2022 09:49:15 -0400 Subject: [PATCH 08/10] some fixes for failing unit tests, more on the way hopefully --- README.md | 5 +++ .../atomicrobot/carbon/CustomAppTestRunner.kt | 38 ------------------- app/src/debug/AndroidManifest.xml | 3 -- app/src/dev/AndroidManifest.xml | 12 ------ .../carbon/app/SSLDevelopmentHelper.kt | 2 +- app/src/main/AndroidManifest.xml | 1 - .../atomicrobot/carbon/app/MainApplication.kt | 2 +- .../carbon/ui/compose/MainNavigation.kt | 2 +- .../carbon/ui/main/MainViewModel.kt | 1 - .../drawable-v24/ic_launcher_foreground.xml | 34 ----------------- .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 --- app/src/main/res/values/strings.xml | 1 - app/src/prod/AndroidManifest.xml | 2 +- .../data/api/github/DeepLinkInteractorTest.kt | 5 ++- app/src/test/resources/robolectric.properties | 3 +- gradle.properties | 6 +-- 16 files changed, 15 insertions(+), 107 deletions(-) delete mode 100644 app/src/androidTest/java/com/atomicrobot/carbon/CustomAppTestRunner.kt delete mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml delete mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/README.md b/README.md index 23879972..082d42e7 100755 --- a/README.md +++ b/README.md @@ -68,6 +68,11 @@ app/build/reports/coverage/dev/debug/ => quality/coverage - "Unit Tests" with a start page of `quality/tests/index.html` - "Integration Tests" with a start page of `quality/integrationTests/index.html` +### Supported Android Versions +The Carbon app will only support those Android versions that Google Security continues to support: https://endoflife.date/android + +As of July 15, 2022, the latest Android version that's supported is Android 10. Therefore the minSDK is set to 29 + License ======= diff --git a/app/src/androidTest/java/com/atomicrobot/carbon/CustomAppTestRunner.kt b/app/src/androidTest/java/com/atomicrobot/carbon/CustomAppTestRunner.kt deleted file mode 100644 index d7769dce..00000000 --- a/app/src/androidTest/java/com/atomicrobot/carbon/CustomAppTestRunner.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.atomicrobot.carbon - -import android.app.Application -import android.app.KeyguardManager -import android.content.Context -import android.os.PowerManager -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.runner.AndroidJUnitRunner - -class CustomAppTestRunner : AndroidJUnitRunner() { - override fun onStart() { - runOnMainSync { - val context = InstrumentationRegistry.getInstrumentation().targetContext - unlockScreen(context, CustomAppTestRunner::class.java.name) - keepScreenAwake(context, CustomAppTestRunner::class.java.name) - } - - super.onStart() - } - - @Throws(InstantiationException::class, IllegalAccessException::class, ClassNotFoundException::class) - override fun newApplication(cl: ClassLoader, className: String, context: Context): Application { - return super.newApplication(cl, TestMainApplication::class.java.name, context) - } - - @Suppress("DEPRECATION") - private fun keepScreenAwake(app: Context, name: String) { - val power = app.getSystemService(Context.POWER_SERVICE) as PowerManager - power.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP or PowerManager.ON_AFTER_RELEASE, name) - .acquire(10 * 60 * 1000L /*10 minutes*/) - } - - @Suppress("DEPRECATION") - private fun unlockScreen(app: Context, name: String) { - val keyguard = app.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager - keyguard.newKeyguardLock(name).disableKeyguard() - } -} diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml index d3c38b6f..fb3d91e2 100644 --- a/app/src/debug/AndroidManifest.xml +++ b/app/src/debug/AndroidManifest.xml @@ -2,9 +2,6 @@ - - - diff --git a/app/src/dev/AndroidManifest.xml b/app/src/dev/AndroidManifest.xml index 038e01ff..e1693d9b 100644 --- a/app/src/dev/AndroidManifest.xml +++ b/app/src/dev/AndroidManifest.xml @@ -5,18 +5,6 @@ - - - - - - - diff --git a/app/src/dev/java/com/atomicrobot/carbon/app/SSLDevelopmentHelper.kt b/app/src/dev/java/com/atomicrobot/carbon/app/SSLDevelopmentHelper.kt index e3a5993f..83b573ee 100644 --- a/app/src/dev/java/com/atomicrobot/carbon/app/SSLDevelopmentHelper.kt +++ b/app/src/dev/java/com/atomicrobot/carbon/app/SSLDevelopmentHelper.kt @@ -34,7 +34,7 @@ object SSLDevelopmentHelper { try { val sc = SSLContext.getInstance("TLS") // NON-NLS - sc.init(null, trustAllCerts, java.security.SecureRandom()) + sc.init(null, trustAllCerts, SecureRandom()) return sc } catch (ex: Exception) { throw RuntimeException(ex) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9ec39820..e4976f2c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,6 @@ android:allowBackup="true" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" android:theme="@style/AppTheme"> - - - - - - - - - - diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index eca70cfe..00000000 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 235c63e6..9a90a63c 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,5 +18,4 @@ We encountered an unexpected error. Please try again. Could not find the requested commits ComposeStartActivity - DeleteMeActivity \ No newline at end of file diff --git a/app/src/prod/AndroidManifest.xml b/app/src/prod/AndroidManifest.xml index 047f89c3..cead005a 100644 --- a/app/src/prod/AndroidManifest.xml +++ b/app/src/prod/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt index bb0087e2..b0fca4b1 100644 --- a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt @@ -4,10 +4,13 @@ import android.graphics.Color import android.net.Uri import androidx.test.ext.junit.runners.AndroidJUnit4 import com.atomicrobot.carbon.deeplink.DeepLinkInteractor +import org.junit.After import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.koin.core.context.startKoin +import org.koin.core.context.stopKoin import org.mockito.MockitoAnnotations @RunWith(AndroidJUnit4::class) @@ -17,7 +20,7 @@ class DeepLinkInteractorTest { @Before fun setup() { - MockitoAnnotations.initMocks(this) + MockitoAnnotations.openMocks(this) interactor = DeepLinkInteractor() } diff --git a/app/src/test/resources/robolectric.properties b/app/src/test/resources/robolectric.properties index 61ee3e1b..aaf3f5c2 100644 --- a/app/src/test/resources/robolectric.properties +++ b/app/src/test/resources/robolectric.properties @@ -1,4 +1,3 @@ packageName=com.atomicrobot.carbon constants=com.atomicrobot.carbon.BuildConfig -application=com.atomicrobot.carbon.app.RobolectricApplication -sdk=21 \ No newline at end of file +sdk=31 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 07588d89..2a17315b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,8 +8,4 @@ org.gradle.caching=true org.gradle.warning.mode=summary android.useAndroidX=true -android.enableJetifier=true - -android.enableUnitTestBinaryResources=false - -android.jetifier.ignorelist=bcprov-jdk15on \ No newline at end of file +android.enableJetifier=true \ No newline at end of file From 27b8ab23e7229d48737b48ddcf42665ee7edf001 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 22 Sep 2022 14:22:04 -0400 Subject: [PATCH 09/10] fixes for 'Koin application already been started' --- app/src/test/java/com/atomicrobot/carbon/RxTests.kt | 7 +++++++ .../java/com/atomicrobot/carbon/SimpleRobolectricTest.kt | 7 +++++++ app/src/test/java/com/atomicrobot/carbon/SimpleTests.kt | 8 ++++++++ .../carbon/data/api/github/DeepLinkInteractorTest.kt | 5 +++++ .../carbon/data/api/github/GitHubApiServiceTest.kt | 4 +++- .../carbon/data/api/github/GitHubInteractorTest.kt | 9 ++++++++- .../com/atomicrobot/carbon/ui/main/MainViewModelTest.kt | 9 ++++++++- 7 files changed, 46 insertions(+), 3 deletions(-) diff --git a/app/src/test/java/com/atomicrobot/carbon/RxTests.kt b/app/src/test/java/com/atomicrobot/carbon/RxTests.kt index 0206b1cc..d86aba45 100644 --- a/app/src/test/java/com/atomicrobot/carbon/RxTests.kt +++ b/app/src/test/java/com/atomicrobot/carbon/RxTests.kt @@ -4,8 +4,10 @@ import io.reactivex.Completable import io.reactivex.Observable import io.reactivex.Single import io.reactivex.observers.TestObserver +import org.junit.After import org.junit.Before import org.junit.Test +import org.koin.core.context.stopKoin class RxTests { private lateinit var subscriber: TestObserver @@ -15,6 +17,11 @@ class RxTests { subscriber = TestObserver() } + @After + fun teardown() { + stopKoin() + } + @Test fun testObservableFactoryError() { Observable.error(IllegalStateException()) diff --git a/app/src/test/java/com/atomicrobot/carbon/SimpleRobolectricTest.kt b/app/src/test/java/com/atomicrobot/carbon/SimpleRobolectricTest.kt index 1f5e60bc..9f13e273 100644 --- a/app/src/test/java/com/atomicrobot/carbon/SimpleRobolectricTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/SimpleRobolectricTest.kt @@ -3,13 +3,20 @@ package com.atomicrobot.carbon import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith +import org.koin.core.context.stopKoin @RunWith(AndroidJUnit4::class) class SimpleRobolectricTest { + @After + fun teardown() { + stopKoin() + } + @Test fun testAppName() { val context = ApplicationProvider.getApplicationContext() diff --git a/app/src/test/java/com/atomicrobot/carbon/SimpleTests.kt b/app/src/test/java/com/atomicrobot/carbon/SimpleTests.kt index 9755123d..c2eb48e2 100644 --- a/app/src/test/java/com/atomicrobot/carbon/SimpleTests.kt +++ b/app/src/test/java/com/atomicrobot/carbon/SimpleTests.kt @@ -2,12 +2,20 @@ package com.atomicrobot.carbon import android.os.Bundle import com.nhaarman.mockito_kotlin.whenever +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test +import org.koin.core.context.stopKoin import org.mockito.Mockito.mock class SimpleTests { + + @After + fun teardown() { + stopKoin() + } + @Test fun testTrueIsTrue() { assertTrue(true) diff --git a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt index b0fca4b1..05def9f8 100644 --- a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt @@ -24,6 +24,11 @@ class DeepLinkInteractorTest { interactor = DeepLinkInteractor() } + @After + fun teardown() { + stopKoin() + } + @Test fun testDeepLinkPath() { interactor.setDeepLinkUri(Uri.parse("https://www.atomicrobot.com/carbon-android/path1")) diff --git a/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubApiServiceTest.kt b/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubApiServiceTest.kt index 8b13f7e2..aa02a077 100644 --- a/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubApiServiceTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubApiServiceTest.kt @@ -15,6 +15,7 @@ import okhttp3.mockwebserver.MockWebServer import org.junit.After import org.junit.Before import org.junit.Test +import org.koin.core.context.stopKoin import org.mockito.MockitoAnnotations import retrofit2.Converter import retrofit2.Response @@ -28,7 +29,7 @@ class GitHubApiServiceTest { @Before fun setup() { - MockitoAnnotations.initMocks(this) + MockitoAnnotations.openMocks(this) server = MockWebServer() } @@ -36,6 +37,7 @@ class GitHubApiServiceTest { @Throws(Exception::class) fun tearDown() { server.shutdown() + stopKoin() } @Test diff --git a/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubInteractorTest.kt b/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubInteractorTest.kt index 02856a80..08318c53 100644 --- a/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubInteractorTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/data/api/github/GitHubInteractorTest.kt @@ -9,10 +9,12 @@ import com.atomicrobot.carbon.data.api.github.model.CommitTestHelper.stubCommit import com.nhaarman.mockito_kotlin.whenever import io.reactivex.Single import io.reactivex.observers.TestObserver +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.koin.core.context.stopKoin import org.mockito.ArgumentMatchers.anyString import org.mockito.Mock import org.mockito.MockitoAnnotations @@ -29,12 +31,17 @@ class GitHubInteractorTest { @Before fun setup() { - MockitoAnnotations.initMocks(this) + MockitoAnnotations.openMocks(this) val context = ApplicationProvider.getApplicationContext() interactor = GitHubInteractor(context, api) } + @After + fun teardown() { + stopKoin() + } + @Test @Throws(Exception::class) fun testLoadCommits() { diff --git a/app/src/test/java/com/atomicrobot/carbon/ui/main/MainViewModelTest.kt b/app/src/test/java/com/atomicrobot/carbon/ui/main/MainViewModelTest.kt index 9090997c..a762fee3 100644 --- a/app/src/test/java/com/atomicrobot/carbon/ui/main/MainViewModelTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/ui/main/MainViewModelTest.kt @@ -9,11 +9,13 @@ import com.atomicrobot.carbon.data.api.github.model.Commit import com.nhaarman.mockito_kotlin.any import com.nhaarman.mockito_kotlin.whenever import io.reactivex.Observable +import org.junit.After import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.koin.core.context.stopKoin import org.mockito.Mock import org.mockito.Mockito.mock import org.mockito.MockitoAnnotations @@ -29,7 +31,7 @@ class MainViewModelTest { @Before fun setup() { - MockitoAnnotations.initMocks(this) + MockitoAnnotations.openMocks(this) val app = ApplicationProvider.getApplicationContext() viewModel = MainViewModel( @@ -39,6 +41,11 @@ class MainViewModelTest { ) } + @After + fun teardown() { + stopKoin() + } + @Test fun testFetchCommits() { val mockResult = mock(GitHubInteractor.LoadCommitsResponse::class.java) From b53ff0030a9191c907e057f436b6677f9a974a87 Mon Sep 17 00:00:00 2001 From: matthewdauterman Date: Thu, 22 Sep 2022 14:26:45 -0400 Subject: [PATCH 10/10] ktlint fix --- .../atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt index 05def9f8..09c6eebf 100644 --- a/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt +++ b/app/src/test/java/com/atomicrobot/carbon/data/api/github/DeepLinkInteractorTest.kt @@ -9,7 +9,6 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.koin.core.context.startKoin import org.koin.core.context.stopKoin import org.mockito.MockitoAnnotations