[GH] Update gradle to 7.5-rc2, add transform workaround
This PR updates playground gradle to 7.5-rc2 (aosp is happening in parallel).
` ./gradlew wrapper --gradle-version=7.5-rc-2`
It also applies the workaround provided by the gradle team until we can update to 7.5.1 (or 7.6)
Bug: https://github.com/gradle/gradle/issues/20778
Test: CI
This is an imported pull request from https://github.com/androidx/androidx/pull/413.
Resolves #413
Github-Pr-Head-Sha: de11c88802c664c9a3d02ee8c82ef4e6e4297218
GitOrigin-RevId: acc6527bac663d451065f918a3603ee246fa097f
Change-Id: Id7f1dbbe6ee4d92388ce8eb3c43a678bd25065aa
diff --git a/buildSrc/private/src/main/kotlin/androidx/build/AndroidXPlaygroundRootImplPlugin.kt b/buildSrc/private/src/main/kotlin/androidx/build/AndroidXPlaygroundRootImplPlugin.kt
index c96386d..f4934f1 100644
--- a/buildSrc/private/src/main/kotlin/androidx/build/AndroidXPlaygroundRootImplPlugin.kt
+++ b/buildSrc/private/src/main/kotlin/androidx/build/AndroidXPlaygroundRootImplPlugin.kt
@@ -59,6 +59,7 @@
config = PlaygroundProperties.load(rootProject)
repos = PlaygroundRepositories(config)
rootProject.repositories.addPlaygroundRepositories()
+ GradleTransformWorkaround.maybeApply(rootProject)
rootProject.subprojects {
configureSubProject(it)
}
diff --git a/buildSrc/private/src/main/kotlin/androidx/build/GradleTransformWorkaround.kt b/buildSrc/private/src/main/kotlin/androidx/build/GradleTransformWorkaround.kt
new file mode 100644
index 0000000..421f0a7
--- /dev/null
+++ b/buildSrc/private/src/main/kotlin/androidx/build/GradleTransformWorkaround.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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 androidx.build
+
+import androidx.build.gradle.isRoot
+import org.gradle.api.Project
+
+/**
+ * Creates a dependency substitution rule to workaround
+ * [a Gradle bug](https://github.com/gradle/gradle/issues/20778).
+ *
+ * The root cause of the bug is a mix of external and project coordinates existing
+ * simultaneously in the dependency graph. A Gradle optimization attempts to simplify/minimize
+ * this graph to allow artifact transforms to being executing as soon as possible, but the
+ * optimization was too aggressive in the Androidx case.
+ *
+ * This workaround creates a no-op/unmatching rule which invalidates the above optimization and
+ * prevents transformations from executing too eagerly.
+ *
+ * This is necessary for Gradle 7.5-rc-1, but should be fixed in Gradle 7.5.1 or 7.6, at which
+ * point this class can be removed.
+ */
+object GradleTransformWorkaround {
+ /**
+ * This function applies the [GradleTransformWorkaround] to the given root project, if
+ * necessary (if it includes lifecycle-common).
+ *
+ * @param rootProject The root project whose sub-projects will be updated with the
+ * workaround.
+ */
+ fun maybeApply(rootProject: Project) {
+ check(rootProject.isRoot) {
+ """
+ GradleTransformWorkaround must be invoked with the root project
+ because it needs to be applied to all sub-projects.
+ """.trimIndent()
+ }
+ rootProject.subprojects { subProject ->
+ if (subProject.path == ":lifecycle:lifecycle-common") {
+ rootProject.subprojects {
+ it.applyArtifactTransformWorkaround()
+ }
+ }
+ }
+ }
+
+ private fun Project.applyArtifactTransformWorkaround() {
+ this.configurations.all { c ->
+ c.resolutionStrategy.dependencySubstitution { selector ->
+ selector.substitute(selector.module("unmatched:unmatched"))
+ .using(selector.project(":lifecycle:lifecycle-common"))
+ .because("workaround gradle/gradle#20778 with intentionally unmatching " +
+ "substitution rule")
+ }
+ }
+ }
+}
diff --git a/playground-common/gradle/wrapper/gradle-wrapper.jar b/playground-common/gradle/wrapper/gradle-wrapper.jar
index 7454180..249e583 100644
--- a/playground-common/gradle/wrapper/gradle-wrapper.jar
+++ b/playground-common/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/playground-common/gradle/wrapper/gradle-wrapper.properties b/playground-common/gradle/wrapper/gradle-wrapper.properties
index 626da35..26e62a1 100644
--- a/playground-common/gradle/wrapper/gradle-wrapper.properties
+++ b/playground-common/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-7.5-20220421031748+0000-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/playground-common/gradlew b/playground-common/gradlew
index 1b6c787..a69d9cb 100755
--- a/playground-common/gradlew
+++ b/playground-common/gradlew
@@ -205,6 +205,12 @@
org.gradle.wrapper.GradleWrapperMain \
"$@"
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
diff --git a/playground-common/gradlew.bat b/playground-common/gradlew.bat
index 107acd3..53a6b23 100644
--- a/playground-common/gradlew.bat
+++ b/playground-common/gradlew.bat
@@ -1,89 +1,91 @@
-@rem
-@rem Copyright 2015 the original author or authors.
-@rem
-@rem Licensed under the Apache License, Version 2.0 (the "License");
-@rem you may not use this file except in compliance with the License.
-@rem You may obtain a copy of the License at
-@rem
-@rem https://www.apache.org/licenses/LICENSE-2.0
-@rem
-@rem Unless required by applicable law or agreed to in writing, software
-@rem distributed under the License is distributed on an "AS IS" BASIS,
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@rem See the License for the specific language governing permissions and
-@rem limitations under the License.
-@rem
-
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Resolve any "." and ".." in APP_HOME to make it shorter.
-for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto execute
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega