forked from square/dagger
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Hilt's aggregating task test environment flag when configuring th…
…e task for a com.android.test Gradle module. Fixes: #3478 RELNOTES=Fix an issue in Hilt's Gradle Plugin not configuring the aggregating task correctly on a com.android.test Gradle module. PiperOrigin-RevId: 463330712
- Loading branch information
1 parent
613e716
commit eb12898
Showing
7 changed files
with
171 additions
and
2 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
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
61 changes: 61 additions & 0 deletions
61
javatests/artifacts/hilt-android/simple/uitest/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,61 @@ | ||
/* | ||
* Copyright (C) 2022 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.test' | ||
apply plugin: 'com.google.dagger.hilt.android' | ||
|
||
android { | ||
compileSdkVersion 32 | ||
buildToolsVersion "32.0.0" | ||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 32 | ||
testInstrumentationRunner "dagger.hilt.android.simple.uitest.TestRunner" | ||
missingDimensionStrategy 'tier', 'free' | ||
} | ||
targetProjectPath ':app' | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_11 | ||
targetCompatibility JavaVersion.VERSION_11 | ||
} | ||
} | ||
|
||
hilt { | ||
enableAggregatingTask = true | ||
} | ||
|
||
dependencies { | ||
implementation project(':app') | ||
|
||
implementation 'junit:junit:4.13' | ||
implementation 'androidx.test.ext:junit:1.1.3' | ||
implementation 'androidx.test:runner:1.4.0' | ||
|
||
implementation "com.google.dagger:hilt-android:$dagger_version" | ||
implementation "com.google.dagger:hilt-android-testing:$dagger_version" | ||
annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version" | ||
} | ||
|
||
configurations.all { | ||
resolutionStrategy.eachDependency { DependencyResolveDetails details -> | ||
if ("$dagger_version" == 'LOCAL-SNAPSHOT' | ||
&& details.requested.group == 'com.google.dagger') { | ||
details.useVersion 'LOCAL-SNAPSHOT' | ||
details.because 'LOCAL-SNAPSHOT should act as latest version.' | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
javatests/artifacts/hilt-android/simple/uitest/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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2022 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.simple.uitest"> | ||
</manifest> |
30 changes: 30 additions & 0 deletions
30
...ilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/TestRunner.java
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,30 @@ | ||
/* | ||
* Copyright (C) 2022 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.simple.uitest; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import androidx.test.runner.AndroidJUnitRunner; | ||
import dagger.hilt.android.testing.HiltTestApplication; | ||
|
||
public final class TestRunner extends AndroidJUnitRunner { | ||
@Override | ||
public Application newApplication(ClassLoader cl, String className, Context context) | ||
throws ClassNotFoundException, IllegalAccessException, InstantiationException { | ||
return super.newApplication(cl, HiltTestApplication.class.getName(), context); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestOne.java
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,29 @@ | ||
/* | ||
* Copyright (C) 2022 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.simple.uitest; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import dagger.hilt.android.testing.HiltAndroidTest; | ||
import org.junit.runner.RunWith; | ||
|
||
// An empty test file that validates multiple test roots in an com.android.test Gradle module, | ||
// note that these test roots are in src/main, see: https://github.com/google/dagger/issues/3478. | ||
@HiltAndroidTest | ||
@RunWith(AndroidJUnit4.class) | ||
public final class UITestOne { | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...hilt-android/simple/uitest/src/main/java/dagger/hilt/android/simple/uitest/UITestTwo.java
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,27 @@ | ||
/* | ||
* Copyright (C) 2022 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.simple.uitest; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import dagger.hilt.android.testing.HiltAndroidTest; | ||
import org.junit.runner.RunWith; | ||
|
||
// An empty test file that validates multiple test roots in an com.android.test Gradle module, | ||
// note that these test roots are in src/main, see: https://github.com/google/dagger/issues/3478. | ||
@HiltAndroidTest | ||
@RunWith(AndroidJUnit4.class) | ||
public final class UITestTwo {} |