xref: /aosp_15_r20/external/dagger2/javatests/artifacts/hilt-android/simple/app/build.gradle (revision f585d8a307d0621d6060bd7e80091fdcbf94fe27)
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.0"
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    compileOptions {
58        sourceCompatibility JavaVersion.VERSION_11
59        targetCompatibility JavaVersion.VERSION_11
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    flavorDimensions "tier"
76    productFlavors {
77        free {
78            dimension "tier"
79        }
80        pro {
81            dimension "tier"
82            matchingFallbacks = ["free"]
83        }
84    }
85}
86
87hilt {
88    enableTransformForLocalTests = true
89    enableAggregatingTask = true
90}
91
92configurations.all {
93    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
94        if ("$dagger_version" == 'LOCAL-SNAPSHOT'
95                && details.requested.group == 'com.google.dagger') {
96            details.useVersion 'LOCAL-SNAPSHOT'
97            details.because 'LOCAL-SNAPSHOT should act as latest version.'
98        }
99    }
100}
101
102dependencies {
103  implementation project(':feature')
104  implementation project(':lib')
105  implementation 'androidx.appcompat:appcompat:1.2.0'
106  implementation "com.google.dagger:hilt-android:$dagger_version"
107  annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
108
109  testImplementation 'com.google.truth:truth:1.0.1'
110  testImplementation 'junit:junit:4.13'
111  testImplementation 'org.robolectric:robolectric:4.5-alpha-3'
112  testImplementation 'androidx.core:core:1.3.2'
113  testImplementation 'androidx.test.ext:junit:1.1.3'
114  testImplementation 'androidx.test:runner:1.4.0'
115  testImplementation 'androidx.test.espresso:espresso-core:3.4.0'
116  testImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
117  testAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
118
119  androidTestImplementation 'com.google.truth:truth:1.0.1'
120  androidTestImplementation 'junit:junit:4.13'
121  androidTestImplementation 'androidx.test.ext:junit:1.1.3'
122  androidTestImplementation 'androidx.test:runner:1.4.0'
123  androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
124  androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
125  androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"
126
127  // To help us catch usages of Guava APIs for Java 8 in the '-jre' variant.
128  annotationProcessor'com.google.guava:guava:28.1-android'
129  testAnnotationProcessor'com.google.guava:guava:28.1-android'
130  androidTestAnnotationProcessor'com.google.guava:guava:28.1-android'
131
132  // To help us catch version skew related issues in hilt extensions.
133  // TODO(bcorso): Add examples testing the actual API.
134  implementation 'androidx.hilt:hilt-work:1.0.0'
135  annotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
136  testAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
137  androidTestAnnotationProcessor 'androidx.hilt:hilt-compiler:1.0.0'
138}
139