Repository: apollographql/apollo-kotlin
Pull request #4880 (2023-04-18 11:05:59)

GEGP: add retries for tests
Add support for Gradle enterprise [test retries](https://docs.gradle.com/enterprise/flaky-test-detection/#gradle)

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *apollo-android-docs* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 876f5ae9c1eb871d093582f42526d49c5dcdf1e2 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-android-docs/deploys/643e7999dea8d700086c0fe9 |

Patch:
diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml
index c164f01f4d..59466286e6 100644
--- a/.github/workflows/benchmarks.yml
+++ b/.github/workflows/benchmarks.yml
@@ -5,6 +5,8 @@ on:
   #    branches: [ '*' ]
   schedule:
     - cron: '0 3 * * *'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   benchmarks:
diff --git a/.github/workflows/docs-publish.yml b/.github/workflows/docs-publish.yml
index 2c07b02c58..ddca5cf1af 100644
--- a/.github/workflows/docs-publish.yml
+++ b/.github/workflows/docs-publish.yml
@@ -7,6 +7,8 @@ on:
       - release-2.x
     paths:
       - docs/**
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   publish:
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index eccf3b5d7d..25fe6cb0ec 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -5,6 +5,8 @@ on:
     paths-ignore:
       - 'docs/**'
       - '*.md'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 # Cancel any current or previous job from the same PR
 concurrency:
@@ -27,8 +29,6 @@ jobs:
       - name: Build with Gradle
         run: |
           ./gradlew ciTestsGradle
-        env:
-          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
       - name: Collect Diagnostics
         if: always()
         run: ./scripts/collect-diagnostics.main.kts
@@ -53,8 +53,6 @@ jobs:
       - name: Build with Gradle
         run: |
           ./gradlew ciTestsNoGradle --stacktrace
-        env:
-          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
       - name: Collect Diagnostics
         if: always()
         run: ./scripts/collect-diagnostics.main.kts
@@ -79,8 +77,6 @@ jobs:
       - name: Build with Gradle
         run: |
           ./gradlew -p tests ciBuild
-        env:
-          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
       - name: Collect Diagnostics
         if: always()
         run: ./scripts/collect-diagnostics.main.kts
@@ -139,8 +135,6 @@ jobs:
       # Run tests
       - name: Run Tests
         run: ./gradlew :intellij-plugin:check
-        env:
-          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
       # Collect Tests Result of failed tests
       - name: Collect Tests Result
diff --git a/.github/workflows/publish-ij-plugin-snapshot.yml b/.github/workflows/publish-ij-plugin-snapshot.yml
index 0d198cc83a..49f49d909f 100644
--- a/.github/workflows/publish-ij-plugin-snapshot.yml
+++ b/.github/workflows/publish-ij-plugin-snapshot.yml
@@ -5,6 +5,8 @@ on:
   #    branches: [ '*' ]
   schedule:
     - cron: '0 0 * * 0'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   publish-intellij-plugin:
diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml
index 2d19b13160..e6741d3d1c 100644
--- a/.github/workflows/push.yml
+++ b/.github/workflows/push.yml
@@ -6,6 +6,8 @@ on:
     paths-ignore:
       - 'docs/**'
       - '*.md'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   deploy:
diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml
index 955f401b2e..98995de964 100644
--- a/.github/workflows/tag.yml
+++ b/.github/workflows/tag.yml
@@ -4,6 +4,8 @@ on:
   push:
     tags:
       - '*'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   publish-libraries:
diff --git a/benchmark/microbenchmark/build.gradle.kts b/benchmark/microbenchmark/build.gradle.kts
index 2aa52cbd59..9651ebbb75 100644
--- a/benchmark/microbenchmark/build.gradle.kts
+++ b/benchmark/microbenchmark/build.gradle.kts
@@ -68,16 +68,26 @@ dependencies {
 
 configure<com.android.build.gradle.LibraryExtension> {
   namespace = "com.apollographql.apollo3.benchmark"
-  compileSdkVersion(golatac.version("android.sdkversion.compile").toInt())
+  compileSdk = golatac.version("android.sdkversion.compile").toInt()
 
   defaultConfig {
-    minSdkVersion(golatac.version("android.sdkversion.min"))
-    targetSdkVersion(golatac.version("android.sdkversion.target"))
+    minSdk = golatac.version("android.sdkversion.min").toInt()
     testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
   }
 
   @Suppress("UnstableApiUsage")
   useLibrary("android.test.base")
+
+  compileOptions {
+    sourceCompatibility = JavaVersion.VERSION_11
+    targetCompatibility = JavaVersion.VERSION_11
+  }
+}
+
+java {
+  toolchain {
+    languageVersion.set(JavaLanguageVersion.of(11))
+  }
 }
 
 configure<com.apollographql.apollo3.gradle.api.ApolloExtension> {
diff --git a/benchmark/settings.gradle.kts b/benchmark/settings.gradle.kts
index 0afacb68fe..2764dfe160 100644
--- a/benchmark/settings.gradle.kts
+++ b/benchmark/settings.gradle.kts
@@ -1,8 +1,11 @@
+plugins {
+  id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
+}
+
 include(":app", ":microbenchmark")
 
 includeBuild("build-logic")
 
-
 apply(from = "../gradle/repositories.gradle.kts")
 
 listOf(pluginManagement.repositories, dependencyResolutionManagement.repositories).forEach {
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts
index 5fa6e3f9a8..b8668d1e22 100644
--- a/build-logic/build.gradle.kts
+++ b/build-logic/build.gradle.kts
@@ -19,6 +19,7 @@ golatac.init(file("../gradle/libraries.toml"))
 
 dependencies {
   compileOnly(gradleApi())
+  compileOnly(golatac.lib("gegp"))
 
   implementation(golatac.lib("okhttp"))
 
diff --git a/gradle/libraries.toml b/gradle/libraries.toml
index b5cbf29ffb..6c1b285a76 100644
--- a/gradle/libraries.toml
+++ b/gradle/libraries.toml
@@ -1,7 +1,7 @@
 [versions]
 android-plugin = "7.4.0"
 android-plugin-min = "3.4.2"
-android-sdkversion-compile = "31"
+android-sdkversion-compile = "33"
 android-sdkversion-min = "15"
 android-sdkversion-compose-min = "21"
 android-sdkversion-target = "30"
@@ -75,6 +75,7 @@ clikt = { group = "com.github.ajalt.clikt", name = "clikt", version = "3.5.2" }
 compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version = "1.3.3" }
 dokka-base = { group = "org.jetbrains.dokka", name = "dokka-base", version.ref = "dokka" }
 dokka-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "dokka" }
+gegp = "com.gradle:gradle-enterprise-gradle-plugin:3.13" # // sync with settings.gradle.kts
 # Not updating because it fails in apollo-compiler Java tests with
 # annotation @org.jetbrains.annotations.Nullable not applicable in this type context
 google-testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version = "0.19" }
diff --git a/gradle/repositories.gradle.kts b/gradle/repositories.gradle.kts
index 8f91177fba..85b98cc752 100644
--- a/gradle/repositories.gradle.kts
+++ b/gradle/repositories.gradle.kts
@@ -21,6 +21,7 @@ listOf(pluginManagement.repositories, dependencyResolutionManagement.repositorie
         includeModule("me.champeau.gradle", "japicmp-gradle-plugin")
         includeModule("com.gradle.publish", "plugin-publish-plugin")
         includeModule("com.github.ben-manes", "gradle-versions-plugin")
+        includeModule("com.gradle", "gradle-enterprise-gradle-plugin")
 
         // For org.jetbrains.intellij
         includeModule("org.jetbrains.intellij", "org.jetbrains.intellij.gradle.plugin")
diff --git a/renovate.json b/renovate.json
index d00cb399fb..7170df8898 100644
--- a/renovate.json
+++ b/renovate.json
@@ -3,7 +3,8 @@
   "ignorePaths": [],
   "includePaths": [
     "settings.gradle.kts",
-    "tests/settings.gradle.kts"
+    "tests/settings.gradle.kts",
+    "build-logic/settings.gradle.kts"
   ],
   "timeout": 600,
   "extends": ["config:base"]
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 059f8b0722..a307b87b37 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -20,7 +20,7 @@ pluginManagement {
 }
 
 plugins {
-  id("com.gradle.enterprise") version "3.13"
+  id("com.gradle.enterprise") version "3.13" // sync with libraries.toml
   id("com.gradle.common-custom-user-data-gradle-plugin") version "1.10"
   id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
 }


Test patch:
diff --git a/.github/workflows/defer-with-router-tests.yml b/.github/workflows/defer-with-router-tests.yml
index 486ccc4f69..b872cb8fe5 100644
--- a/.github/workflows/defer-with-router-tests.yml
+++ b/.github/workflows/defer-with-router-tests.yml
@@ -3,6 +3,8 @@ name: defer-router-tests
 on:
   schedule:
     - cron: '0 3 * * *'
+env:
+  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
 
 jobs:
   defer-with-router-tests:
diff --git a/build-logic/src/main/kotlin/Testing.kt b/build-logic/src/main/kotlin/Testing.kt
index a6d5d51787..b105aa6939 100644
--- a/build-logic/src/main/kotlin/Testing.kt
+++ b/build-logic/src/main/kotlin/Testing.kt
@@ -1,3 +1,4 @@
+import com.gradle.enterprise.gradleplugin.testretry.retry
 import org.gradle.api.Project
 import org.gradle.api.tasks.testing.AbstractTestTask
 import org.gradle.api.tasks.testing.Test
@@ -9,6 +10,18 @@ fun Project.configureTesting() {
     systemProperty("updateTestFixtures", System.getProperty("updateTestFixtures"))
     systemProperty("testFilter", System.getProperty("testFilter"))
     systemProperty("codegenModels", System.getProperty("codegenModels"))
+
+  }
+  
+  pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
+    tasks.withType(Test::class.java) {
+      retry {
+        if (System.getenv().containsKey("CI")) {
+          maxRetries.set(3)
+          failOnPassedAfterRetry.set(true)
+        }
+      }
+    }
   }
 
   tasks.withType(AbstractTestTask::class.java) {
diff --git a/tests/settings.gradle.kts b/tests/settings.gradle.kts
index 7549028f2b..8c22996d4e 100644
--- a/tests/settings.gradle.kts
+++ b/tests/settings.gradle.kts
@@ -25,7 +25,7 @@ pluginManagement {
 }
 
 plugins {
-  id("com.gradle.enterprise") version "3.13"
+  id("com.gradle.enterprise") version "3.13" // sync with libraries.toml
   id("com.gradle.common-custom-user-data-gradle-plugin") version "1.10"
   id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0"
 }