• 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: 'dagger.hilt.android.plugin'
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 30
47    buildToolsVersion "30.0.2"
48
49    defaultConfig {
50        applicationId "dagger.hilt.android.simple"
51        minSdkVersion 15
52        targetSdkVersion 30
53        versionCode 1
54        versionName "1.0"
55        testInstrumentationRunner "dagger.hilt.android.simple.SimpleEmulatorTestRunner"
56    }
57    compileOptions {
58        sourceCompatibility 1.8
59        targetCompatibility 1.8
60    }
61    testOptions {
62        unitTests.includeAndroidResources = true
63    }
64    lintOptions {
65        checkReleaseBuilds = false
66    }
67    sourceSets {
68        test {
69            java.srcDirs += getAdditionalTestDirs("test")
70        }
71        androidTest {
72            java.srcDirs += getAdditionalTestDirs("androidTest")
73        }
74    }
75}
76
77hilt {
78    enableTransformForLocalTests = true
79    enableAggregatingTask = true
80}
81
82configurations.all {
83    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
84        if ("$dagger_version" == 'LOCAL-SNAPSHOT'
85                && details.requested.group == 'com.google.dagger') {
86            details.useVersion 'LOCAL-SNAPSHOT'
87            details.because 'LOCAL-SNAPSHOT should act as latest version.'
88        }
89    }
90}
91
92dependencies {
93  implementation project(':feature')
94  implementation project(':lib')
95  implementation 'androidx.appcompat:appcompat:1.2.0'
96  implementation "com.google.dagger:hilt-android:$dagger_version"
97  annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
98
99  testImplementation 'com.google.truth:truth:1.0.1'
100  testImplementation 'junit:junit:4.13'
101  testImplementation 'org.robolectric:robolectric:4.5-alpha-3'
102  testImplementation 'androidx.core:core:1.3.2'
103  testImplementation 'androidx.test.ext:junit:1.1.2'
104  testImplementation 'androidx.test:runner:1.3.0'
105  testImplementation 'androidx.test.espresso:espresso-core:3.3.0'
106  testImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
107  testAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
108
109  androidTestImplementation 'com.google.truth:truth:1.0.1'
110  androidTestImplementation 'junit:junit:4.13'
111  androidTestImplementation 'androidx.test.ext:junit:1.1.2'
112  androidTestImplementation 'androidx.test:runner:1.3.0'
113  androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
114  androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
115  androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
116
117  // To help us catch usages of Guava APIs for Java 8 in the '-jre' variant.
118  annotationProcessor'com.google.guava:guava:28.1-android'
119  testAnnotationProcessor'com.google.guava:guava:28.1-android'
120  androidTestAnnotationProcessor'com.google.guava:guava:28.1-android'
121
122  // To help us catch version skew related issues in hilt extensions.
123  // TODO(bcorso): Add examples testing the actual API.
124  implementation 'androidx.hilt:hilt-work:1.0.0'
125  annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
126  testAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
127  androidTestAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
128}
129