• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2020 The Dagger Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import org.gradle.util.VersionNumber
17
18apply plugin: 'com.android.application'
19apply plugin: 'com.google.dagger.hilt.android'
20
21// Gets additional test directories to be added to test and androidTest source
22// sets. If the directory name is appended with '-agp-x.x.x' then the directory
23// is conditionally added based on the AGP version of the project.
24def getAdditionalTestDirs(String variant) {
25    def testDirs = [
26        'androidTest': [],
27        'sharedTest': ['src/sharedTest/java'],
28        'test': []
29    ]
30    def suffix = '-agp-'
31    def agpVersion = VersionNumber.parse(agp_version)
32    file("${getProjectDir().absolutePath}/src").eachFile { file ->
33        int indexOf = file.name.indexOf(suffix)
34        if (file.isDirectory() && indexOf != -1) {
35            def dirAgpVersion =
36                VersionNumber.parse(file.name.substring(indexOf + suffix.length()))
37            if (agpVersion >= dirAgpVersion) {
38                testDirs[file.name.substring(0, indexOf)].add("src/${file.name}/java")
39            }
40        }
41    }
42    return testDirs[variant] + testDirs['sharedTest']
43}
44
45android {
46    compileSdkVersion 33
47    buildToolsVersion "33.0.1"
48
49    defaultConfig {
50        applicationId "dagger.hilt.android.simple"
51        minSdkVersion 16
52        targetSdkVersion 33
53        versionCode 1
54        versionName "1.0"
55        testInstrumentationRunner "dagger.hilt.android.simple.SimpleEmulatorTestRunner"
56    }
57    namespace "dagger.hilt.android.simple"
58    compileOptions {
59        sourceCompatibility JavaVersion.VERSION_11
60        targetCompatibility JavaVersion.VERSION_11
61    }
62    testOptions {
63        unitTests.includeAndroidResources = true
64    }
65    lintOptions {
66        checkReleaseBuilds = false
67    }
68    sourceSets {
69        test {
70            java.srcDirs += getAdditionalTestDirs("test")
71        }
72        androidTest {
73            java.srcDirs += getAdditionalTestDirs("androidTest")
74        }
75    }
76    flavorDimensions "tier"
77    productFlavors {
78        free {
79            dimension "tier"
80        }
81        pro {
82            dimension "tier"
83            matchingFallbacks = ["free"]
84        }
85    }
86}
87
88hilt {
89    enableTransformForLocalTests = true
90    enableAggregatingTask = true
91}
92
93configurations.all {
94    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
95        if ("$dagger_version" == 'LOCAL-SNAPSHOT'
96                && details.requested.group == 'com.google.dagger') {
97            details.useVersion 'LOCAL-SNAPSHOT'
98            details.because 'LOCAL-SNAPSHOT should act as latest version.'
99        }
100    }
101}
102
103dependencies {
104  implementation project(':feature')
105  implementation project(':lib')
106  implementation 'androidx.appcompat:appcompat:1.2.0'
107  implementation "com.google.dagger:hilt-android:$dagger_version"
108  annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
109
110  testImplementation 'com.google.truth:truth:1.0.1'
111  testImplementation 'junit:junit:4.13'
112  testImplementation 'org.robolectric:robolectric:4.11.1'
113  testImplementation 'androidx.core:core:1.3.2'
114  testImplementation 'androidx.test.ext:junit:1.1.3'
115  testImplementation 'androidx.test:runner:1.4.0'
116  testImplementation 'androidx.test.espresso:espresso-core:3.5.1'
117  testImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
118  testAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
119
120  androidTestImplementation 'com.google.truth:truth:1.0.1'
121  androidTestImplementation 'junit:junit:4.13'
122  androidTestImplementation 'androidx.test.ext:junit:1.1.3'
123  androidTestImplementation 'androidx.test:runner:1.4.0'
124  androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
125  androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
126  androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
127
128  // To help us catch usages of Guava APIs for Java 8 in the '-jre' variant.
129  annotationProcessor'com.google.guava:guava:28.1-android'
130  testAnnotationProcessor'com.google.guava:guava:28.1-android'
131  androidTestAnnotationProcessor'com.google.guava:guava:28.1-android'
132
133  // To help us catch version skew related issues in hilt extensions.
134  // TODO(bcorso): Add examples testing the actual API.
135  implementation 'androidx.hilt:hilt-work:1.0.0'
136  annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
137  testAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
138  androidTestAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
139}
140