Skip to content

Commit

Permalink
Set Hilt's aggregating task test environment flag when configuring th…
Browse files Browse the repository at this point in the history
…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
danysantiago authored and Dagger Team committed Aug 10, 2022
1 parent 613e716 commit eb12898
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 2 deletions.
Expand Up @@ -350,7 +350,8 @@ class HiltGradlePlugin @Inject constructor(
@Suppress("DEPRECATION") // Older variant API is deprecated
it.testEnvironment.set(
variant is com.android.build.gradle.api.TestVariant ||
variant is com.android.build.gradle.api.UnitTestVariant
variant is com.android.build.gradle.api.UnitTestVariant ||
androidExtension is com.android.build.gradle.TestExtension
)
it.crossCompilationRootValidationDisabled.set(
hiltExtension.disableCrossCompilationRootValidation
Expand Down
3 changes: 2 additions & 1 deletion javatests/artifacts/hilt-android/simple/settings.gradle
Expand Up @@ -5,4 +5,5 @@ include ':feature'
include ':lib'
include ':deep-android-lib'
include ':deep-lib'
include ':earlyentrypoint'
include ':earlyentrypoint'
include ':uitest'
61 changes: 61 additions & 0 deletions javatests/artifacts/hilt-android/simple/uitest/build.gradle
@@ -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.'
}
}
}
@@ -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>
@@ -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);
}
}
@@ -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 {

}
@@ -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 {}

0 comments on commit eb12898

Please sign in to comment.