Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 1 | # Playground Setup for AndroidX Projects |
| 2 | |
| 3 | AndroidX is a fairly large project with 300+ modules which makes it a |
| 4 | very resource heavy project for local development. |
| 5 | |
| 6 | Playground setup allows sub projects to have an additional settings.gradle |
| 7 | file that can be run independent of the main project. |
| 8 | It also allows using external resources for artifacts such that just checking |
| 9 | out the AndroidX git repository is enough without the prebuilt repositories |
| 10 | that are needed by the main AndroidX project. |
| 11 | |
| 12 | These project setups are only meant to be used for local development and |
| 13 | all CI tasks run using the root AndroidX project. |
| 14 | |
| 15 | ## How it works? |
| 16 | A playground project needs a `settings.gradle` file that applies |
| 17 | `playground-common/playground-settings.gradle` which provides functionality |
| 18 | to pull select projects from AndroidX. |
| 19 | |
| 20 | To share as much common configuration as possible, it is also recommended |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 21 | to symlink some common files like `gradle` and `.idea` configuration. |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 22 | |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 23 | To do that, execute "setup-playground.sh" comamnd in your playground directory. |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 24 | ``` |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 25 | cd room; |
| 26 | ../playground-common/setup-playground.sh |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 27 | ``` |
Yigit Boyar | ab52dda | 2020-07-16 14:54:56 -0700 | [diff] [blame] | 28 | This script will create symbolic links for `gradle` and `.idea` files that are committed |
| 29 | to the git repository. It also force adds the `.idea` files to the git repository because |
| 30 | by default any nested .idea folder is ignored from git. |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 31 | |
| 32 | The `playground-settings.gradle` file sets a pre-defined build file (`playground-build.gradle`) |
| 33 | for the root project and also provides `includeProject` and `selectProjectsFromAndroidX` |
| 34 | methods. |
| 35 | |
| 36 | The custom `settings.gradle` file should first call `setupPlayground(this, "..")` to |
| 37 | run the main configuration. Here, the first argument is the `script` object itself and |
| 38 | the second argument is the relative path to the main AndroidX project. |
| 39 | |
| 40 | After running `setupPlayground`, it can either include projects via `includeProject` |
| 41 | method or filter projects from the main AndroidX settings gradle file using the |
| 42 | `selectProjectsFromAndroidX` method. |
| 43 | |
Yigit Boyar | a4abb18 | 2020-07-31 21:44:05 -0700 | [diff] [blame] | 44 | ### Properties |
| 45 | When a `gradle.properties` file shows up under a sub project, main AndroidX build ends up |
| 46 | reading it. For this reason, we can only keep a minimal `gradle.properties` file in these |
| 47 | sub modules that also support playground setup. |
| 48 | |
| 49 | We cannot avoid creating `gradle.properties` as certain properties (e.g. `useAndroidX`) are |
| 50 | read at configuration time and we cannot set it dynamically. |
| 51 | |
| 52 | Properties that will be set dynamically are kept in `playground.properties` file while |
| 53 | shared properties are kept in `androidx-shared.properties` file. |
| 54 | The dynamic properties are read in the `playground-include-settings.gradle` file and set |
| 55 | on each project. |
| 56 | |
| 57 | There is a `VerifyPlaygroundGradlePropertiesTask` task that validates the contents of |
| 58 | `androidx-shared.properties` file as part of the main AndroidX build. |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 59 | ### Optional Dependencies |
| 60 | Even though sub-projects usually declare exact coordinates for their dependencies, |
| 61 | for tests, it is a common practice to declare `project` dependencies. To avoid needing |
| 62 | to include all of those projects to make the build file work, `AndroidXPlaygroundRootPlugin` |
| 63 | adds a `projectOrArtifact` method to each sub project. This function can be used instead of |
| 64 | `project` to declare optional project dependencies. This function will return the |
| 65 | `project` if it exists or default to its latest artifact if it doesn't. |
| 66 | |
| 67 | Note that range artifacts are not allowed in the main AndroidX build so when the sub |
| 68 | project is opened as part of the main AndroidX build, `projectOrArtifact` always resolves |
| 69 | to the `project`. In playground projects, it always resolves to the latest `SNAPSHOT` |
| 70 | artifact that is included in the playground build. |