Skip to content

Commit 41ad413

Browse files
authored
Upgrade robolectric and target api 29. (firebase#1469)
* Upgrade robolectric and target api 29. * Fix tests. * Fix * Fixes * Fix groovy issues for jdk11 * Add missed android sdk versions
1 parent 8908ccf commit 41ad413

File tree

24 files changed

+93
-47
lines changed

24 files changed

+93
-47
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ext {
5050
errorproneVersion = '2.3.2'
5151
errorproneJavacVersion = '9+181-r4173-1'
5252
googleTruthVersion = '0.45'
53-
robolectricVersion = '4.1'
53+
robolectricVersion = '4.3.1'
5454
}
5555

5656
apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.gradle.plugins;
16+
17+
import groovy.lang.Closure;
18+
import java.util.function.Consumer;
19+
20+
public final class ClosureUtil {
21+
22+
private static final Object FAKE_THIS = new Object();
23+
24+
private ClosureUtil() {}
25+
26+
/** Create a groovy closure backed by a lambda. */
27+
public static <T> Closure<T> closureOf(Consumer<T> action) {
28+
return new Closure<T>(FAKE_THIS) {
29+
void doCall(T t) {
30+
action.accept(t);
31+
}
32+
};
33+
}
34+
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.gradle.plugins;
1616

17+
import static com.google.firebase.gradle.plugins.ClosureUtil.closureOf;
18+
1719
import com.android.build.gradle.LibraryExtension;
1820
import com.android.build.gradle.api.AndroidSourceSet;
1921
import com.google.common.collect.ImmutableList;
@@ -51,6 +53,20 @@ public void apply(Project project) {
5153
.getByName("release")
5254
.setSigningConfig(types.getByName("debug").getSigningConfig()));
5355

56+
// see https://github.com/robolectric/robolectric/issues/5456
57+
android.testOptions(
58+
options ->
59+
options
60+
.getUnitTests()
61+
.all(
62+
closureOf(
63+
test -> {
64+
test.systemProperty("robolectric.dependency.repo.id", "central");
65+
test.systemProperty(
66+
"robolectric.dependency.repo.url", "https://repo1.maven.org/maven2");
67+
test.systemProperty("javax.net.ssl.trustStoreType", "JKS");
68+
})));
69+
5470
// skip debug tests in CI
5571
// TODO(vkryachko): provide ability for teams to control this if needed
5672
if (System.getenv().containsKey("FIREBASE_CI")) {

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/license/LicenseResolverPluginSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LicenseResolverPluginSpec extends Specification {
2929
@Rule TemporaryFolder testProjectDir = new TemporaryFolder()
3030
File buildFile
3131

32-
final String buildConfig = """
32+
String buildConfig = """
3333
buildscript {
3434
repositories {
3535
google()

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/publish/PublishingPluginSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PublishingPluginSpec extends Specification {
8989

9090
List<Project> subprojects = []
9191

92-
final String rootProject = """
92+
String rootProject = """
9393
buildscript {
9494
repositories {
9595
google()

firebase-abt/firebase-abt.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ dependencies {
9191
testImplementation 'com.google.truth:truth:0.44'
9292
testImplementation 'junit:junit:4.13-beta-2'
9393
testImplementation 'androidx.test:runner:1.2.0'
94-
testImplementation 'org.robolectric:robolectric:4.2'
94+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
9595
testImplementation 'io.grpc:grpc-testing:1.12.0'
9696
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
9797

firebase-config/bandwagoner/bandwagoner.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ apply plugin: 'com.android.application'
1818
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
1919

2020
android {
21-
compileSdkVersion 28
21+
compileSdkVersion project.targetSdkVersion
2222
lintOptions {
2323
abortOnError false
2424
}
@@ -27,7 +27,7 @@ android {
2727
defaultConfig {
2828
applicationId "com.googletest.firebase.remoteconfig.bandwagoner"
2929
minSdkVersion 16
30-
targetSdkVersion 28
30+
targetSdkVersion project.targetSdkVersion
3131
versionCode 1
3232
versionName "1.0"
3333
multiDexEnabled true

firebase-config/firebase-config.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dependencies {
9797
testImplementation 'org.mockito:mockito-core:2.25.0'
9898
testImplementation 'com.google.truth:truth:0.44'
9999
testImplementation 'junit:junit:4.12'
100-
testImplementation 'org.robolectric:robolectric:4.2'
100+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
101101
testImplementation "org.skyscreamer:jsonassert:1.5.0"
102102

103103
androidTestImplementation 'androidx.test:runner:1.2.0'

firebase-crashlytics-ndk/firebase-crashlytics-ndk.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ firebaseLibrary {
2121
publishJavadoc = false
2222
}
2323

24-
def androidVersion = 28
25-
2624
android {
2725
adbOptions {
2826
timeOutInMs 60 * 1000
2927
}
3028

31-
compileSdkVersion androidVersion
29+
compileSdkVersion project.targetSdkVersion
3230
defaultConfig {
3331
minSdkVersion 16
34-
targetSdkVersion androidVersion
32+
targetSdkVersion project.targetSdkVersion
3533
versionName version
3634

3735
consumerProguardFiles 'firebase-crashlytics-ndk-proguard.txt'
@@ -63,7 +61,7 @@ dependencies {
6361
implementation 'com.google.android.gms:play-services-basement:17.0.0'
6462

6563
testImplementation 'androidx.test:runner:1.2.0'
66-
testImplementation 'org.robolectric:robolectric:4.2'
64+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
6765
testImplementation 'junit:junit:4.12'
6866
testImplementation 'org.mockito:mockito-core:1.10.19'
6967

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ firebaseLibrary {
2020
testLab.enabled = true
2121
}
2222

23-
def androidVersion = 28
24-
2523
android {
2624
adbOptions {
2725
timeOutInMs 60 * 1000
2826
}
2927

30-
compileSdkVersion androidVersion
28+
compileSdkVersion project.targetSdkVersion
3129
defaultConfig {
3230
minSdkVersion 16
33-
targetSdkVersion androidVersion
31+
targetSdkVersion project.targetSdkVersion
3432
versionName version
3533

3634
multiDexEnabled true
@@ -72,7 +70,7 @@ dependencies {
7270
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
7371

7472
testImplementation 'androidx.test:runner:1.2.0'
75-
testImplementation 'org.robolectric:robolectric:4.2'
73+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
7674
testImplementation 'junit:junit:4.12'
7775
testImplementation 'org.mockito:mockito-core:1.10.19'
7876

0 commit comments

Comments
 (0)