Add minimal gradle.properties to playground buidls
Latest AGP reads certain properties at configuration time which prevents
us from setting them via the settings file.
This CL adds a common shared properties file to playground projects that
only includes a subset of properties set in the AndroidX
gradle.properties file.
As that file is not allowed to include anything that is not defined in
androidX, the itegrity is checked in ValidatePlaygroundGradleProperties
task which is now included in the buildOnServer task dependencies for
the main AndroidX build.
Test: cd room && ./gradlew bOS
Change-Id: Ieb5e8a646872119b348718eaef3ab4729b4c8bbb
diff --git a/playground-common/README.md b/playground-common/README.md
index 59bd21f..99fb098 100644
--- a/playground-common/README.md
+++ b/playground-common/README.md
@@ -41,6 +41,21 @@
method or filter projects from the main AndroidX settings gradle file using the
`selectProjectsFromAndroidX` method.
+### Properties
+When a `gradle.properties` file shows up under a sub project, main AndroidX build ends up
+reading it. For this reason, we can only keep a minimal `gradle.properties` file in these
+sub modules that also support playground setup.
+
+We cannot avoid creating `gradle.properties` as certain properties (e.g. `useAndroidX`) are
+read at configuration time and we cannot set it dynamically.
+
+Properties that will be set dynamically are kept in `playground.properties` file while
+shared properties are kept in `androidx-shared.properties` file.
+The dynamic properties are read in the `playground-include-settings.gradle` file and set
+on each project.
+
+There is a `VerifyPlaygroundGradlePropertiesTask` task that validates the contents of
+`androidx-shared.properties` file as part of the main AndroidX build.
### Optional Dependencies
Even though sub-projects usually declare exact coordinates for their dependencies,
for tests, it is a common practice to declare `project` dependencies. To avoid needing
diff --git a/playground-common/androidx-shared.properties b/playground-common/androidx-shared.properties
new file mode 100644
index 0000000..606adab
--- /dev/null
+++ b/playground-common/androidx-shared.properties
@@ -0,0 +1,33 @@
+#
+# Copyright 2020 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.
+#
+
+# Properties that are copied from main properties file
+# We set playground properties in two steps:
+# * This file is linked into gradle.properties under the project and limited to
+# just copying properties from the androidx properties file without any change.
+# Its integrity is validated as part of the buildOnServer task in AndroidX.
+# (validatePlaygroundGradleProperties task)
+# * Additional settings are in playground.properties which are loaded dynamically
+# This separation is necessary to ensure gradle can read certain properties
+# at configuration time.
+
+android.useAndroidX=true
+# Disable features we do not use
+android.defaults.buildfeatures.aidl=false
+android.defaults.buildfeatures.buildconfig=false
+android.defaults.buildfeatures.renderscript=false
+android.defaults.buildfeatures.resvalues=false
+android.defaults.buildfeatures.shaders=false
diff --git a/playground-common/playground.properties b/playground-common/playground.properties
index 86cffc9..d02bbef 100644
--- a/playground-common/playground.properties
+++ b/playground-common/playground.properties
@@ -14,15 +14,6 @@
# limitations under the License.
#
-# Project-wide Gradle settings.
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
@@ -30,10 +21,8 @@
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
-android.useAndroidX=true
-# Automatically convert third-party libraries to use AndroidX
-android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
+org.gradle.jvmargs=-Xmx2048m
kotlin.code.style=official
# Disable docs
androidx.enableDocumentation=false
@@ -43,10 +32,3 @@
androidx.playground.metalavaBuildId=6604778
androidx.playground.dokkaBuildId=6656073
androidx.studio.type=playground
-
-# Disable features we do not use
-android.defaults.buildfeatures.aidl=false
-android.defaults.buildfeatures.buildconfig=false
-android.defaults.buildfeatures.renderscript=false
-android.defaults.buildfeatures.resvalues=false
-android.defaults.buildfeatures.shaders=false
diff --git a/playground-common/setup-playground.sh b/playground-common/setup-playground.sh
index 650ae3d..ee41940 100755
--- a/playground-common/setup-playground.sh
+++ b/playground-common/setup-playground.sh
@@ -17,6 +17,8 @@
ln -s "${PLAYGROUND_REL_PATH}/gradlew" gradlew
rm -rf gradlew.bat
ln -s "${PLAYGROUND_REL_PATH}/gradlew.bat" gradlew.bat
+rm -rf gradle.properties
+ln -s "${PLAYGROUND_REL_PATH}/androidx-shared.properties" gradle.properties
ANDROIDX_IDEA_DIR="${PLAYGROUND_REL_PATH}/../.idea"