forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for JUnit tests with Hilt Plugin
Android transforms are not applied for JUnit tests which breaks when using the Hilt Plugin and its transform. This CL adds a new custom test transform task just for tests so that transformed classes are used in Android JUnit tests. The task does not transform test sources, therefore temporarily allow specifying a base class in @androidentrypoint that will be used even if the superclass validation option is given to the processor. This helps us still have test-only Android Entry Points. Closes #1811 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=309143731
- Loading branch information
Showing
44 changed files
with
1,123 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ gen-external-apklibs | |
/bazel-* | ||
|
||
*.pyc | ||
|
||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
java/dagger/hilt/android/example/gradle/simple/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
android.useAndroidX=true | ||
android.enableJetifier=true | ||
android.enableUnitTestBinaryResources=true |
2 changes: 1 addition & 1 deletion
2
java/dagger/hilt/android/example/gradle/simple/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
18 changes: 18 additions & 0 deletions
18
java/dagger/hilt/android/example/gradle/simpleKotlin/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2020 The Dagger Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Description: | ||
# A skeletal Kotlin application that demonstrates wiring for an injected Application and Activity. | ||
|
||
package(default_visibility = ["//:src"]) |
65 changes: 65 additions & 0 deletions
65
java/dagger/hilt/android/example/gradle/simpleKotlin/app/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'dagger.hilt.android.plugin' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
applicationId "dagger.hilt.android.example.gradle.simpleKotlin" | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
testOptions { | ||
unitTests.includeAndroidResources = true | ||
} | ||
} | ||
|
||
hilt { | ||
enableTransformForLocalTests = true | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
|
||
implementation 'com.google.dagger:dagger:LOCAL-SNAPSHOT' | ||
kapt 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT' | ||
kapt 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT' | ||
|
||
testImplementation 'com.google.truth:truth:1.0.1' | ||
testImplementation 'junit:junit:4.13' | ||
testImplementation 'org.robolectric:robolectric:4.3.1' | ||
testImplementation 'androidx.core:core:1.1.0' | ||
// TODO(bcorso): This multidex dep shouldn't be required -- it's a dep for the generated code. | ||
testImplementation 'androidx.multidex:multidex:2.0.0' | ||
testImplementation 'com.google.dagger:hilt-android-testing:LOCAL-SNAPSHOT' | ||
kaptTest 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
kaptTest 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT' | ||
} |
35 changes: 35 additions & 0 deletions
35
java/dagger/hilt/android/example/gradle/simpleKotlin/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2020 The Dagger Authors. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dagger.hilt.android.example.gradle.simpleKotlin"> | ||
|
||
<application | ||
android:name=".KotlinApplication" | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.AppCompat.Light"> | ||
<activity android:name=".MainActivity" android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
31 changes: 31 additions & 0 deletions
31
...otlin/app/src/main/java/dagger/hilt/android/example/gradle/simpleKotlin/ActivityModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dagger.hilt.android.example.gradle.simpleKotlin | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityComponent | ||
|
||
@Module | ||
@InstallIn(ActivityComponent::class) | ||
object ActivityModule { | ||
@UserName | ||
@Provides | ||
fun provideUserName(): String { | ||
return "Android User" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...in/app/src/main/java/dagger/hilt/android/example/gradle/simpleKotlin/ApplicationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2020 The Dagger Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dagger.hilt.android.example.gradle.simpleKotlin | ||
|
||
import android.os.Build | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ApplicationComponent | ||
|
||
@Module | ||
@InstallIn(ApplicationComponent::class) | ||
object ApplicationModule { | ||
@Provides | ||
@Model | ||
fun provideModel(): String { | ||
return Build.MODEL | ||
} | ||
} |
Oops, something went wrong.