dataconnect: integrate codegen into the gradle build
This PR adds a custom gradle plugin to the "dataconnect" project to hook into the gradle build and generate the Data Connect source code automatically as part of the build. There is no longer a requirement to manually download and launch the Data Connect emulator just to build the project. This behaves very similarly to the protobuf gradle plugin (https://github.com/google/protobuf-gradle-plugin) and how it compiles the .proto files to java/kt files on-demand when the project is built. This also unblocks compiling the dataconnect module in GitHub CI.
The plugin first creates a node project directory (by creating an empty directory that contains an empty package.json) and installs the configured version of firebase-tools into it by running npm install. Then, it uses that firebase-tools to run the dataconnect:sdk:generate subcommand. In order to control where the generated code gets placed, a copy of the dataconnect.yaml et al files is made, and the connector.yaml files are modified to only produce kotlin connectors and to put them into the directory of the gradle plugin's choosing. All of this is done in the "build" directory, and, therefore, is wiped out by a "gradle clean".
As a nice side effect, the GitHub Actions CI can now compile dataconnect just fine. Therefore, this PR also removes the hacks that opted dataconnect out of the CI.
The following new tasks are now present in the :dataconnect:app module:
setupFirebaseToolsForDataConnect- Creates the directory
dataconnect/app/build/dataconnect/firebase-toolswith a single file in it, an emptypackage.json. - Runs
npm install [email protected]in that directory (the version is configured in build.gradle.kts).
- Creates the directory
generateDebugDataConnectSourcesandgenerateReleaseDataConnectSources- Depends on the
setupFirebaseToolsForDataConnecttask to set up thefirebasecommand - Copies the contents of
dataconnect/dataconnectintodataconnect/app/build/dataconnect/variants/{debug,release}/config - Edits the connector.yaml file(s) to remove all SDKs under the
generatesection, except forkotlinSdk. This is because since we're building the kotlin SDK, we don't want to generate code for other SDKs. - Modifies the
outputDirof thekotlinSdkto use the directory specified by the gradle plugin for placing the generated code. This is because gradle dictates where the generated code is to go and this directory can't be known in advance and hardcoded into the file. Moreover, the directories are different for the "debug" and "release" builds. - Runs
firebase dataconnect:sdk:generateto generate the code into the directory dictated by gradle.
- Depends on the
This plugin is configured by a new "extension" added to dataconnect/app/build.gradle.kts. It looks like this:
dataconnect {
// The version of https://www.npmjs.com/package/firebase-tools to use to perform the
// Data Connect code generation.
firebaseToolsVersion = "13.25.0"
// The directory that contains dataconnect.yaml to use as input when performing
// the Data Connect code generation.
dataConnectConfigDir = file("../dataconnect")
}
This gradle plugin is a proof-of-concept and isn't quite production ready. If it proves to be valuable, customers can at least copy/paste it into their own Android projects. Or, we could make it an "official" plugin. There is even a way to remove the need for node altogether, by just calling the data connect toolkit cli binary directly (without needing to install firebase-tools). This plugin was largely based on my experience writing a similar gradle plugin in the dataconnect android sdk itself: https://github.com/firebase/firebase-android-sdk/blob/866e6bd246fde0e54fdeb5f5d0c043632edf4161/firebase-dataconnect/gradleplugin/plugin/src/main/kotlin/com/google/firebase/dataconnect/gradle/plugin/DataConnectGradlePlugin.kt.
This PR is on hold for now. It was just taking me wayyyy to long and I needed to timebox it. Anything gradle related usually takes forever!