This script streamlines the creation of new features for Android projects by integrating Jetpack Compose with MVVM-I and Clean Architecture. It helps maintain a clean separation of layers (UI, Data, Domain), ensuring a consistent and maintainable codebase.
-
Create Script File:
- Create a new package and file scripts/createfeature.gradle.kts in your root package.
-
- Paste the code from this link into your createfeature.gradle.kts. (https://play.kotlinlang.org/embed?short=KkeGhEhCX&theme=darcula&readOnly=true)
- Paste the code from this link into your createfeature.gradle.kts.
-
Apply Script in Build Configuration:
- Add the following line to your build.gradle.kts module:
apply(from = "scripts/createfeature.gradle.kts")
- Sync Your Project.
- Add the following line to your build.gradle.kts module:
In your terminal, execute the following command:
./gradlew createfeature -PfeatureName=MyNewFeature -PapplicationId=welias.createscriptsfeatures
Replace MyNewFeature with your desired feature name, and welias.createscriptsfeatures with your application ID for your module.
Firstly, create a BaseScriptViewModel in the current package where you are using the MVVM-I (Model, View, ViewModel, Intent) architecture to manage interactions between Composables and ViewModel. If you want to change the BaseScriptViewModel to another name, ensure you update the filename accordingly in the script.
In just milliseconds, your files will be generated, following a consistent architecture and automating repetitive tasks.
If you attempt to create a new feature package with an existing name, an error will occur. Ensure your feature names are unique.