Maintaining multiple multi-module Android project often requires copying project configuration across different projects.
Even when project reaches more advanced stage it is still required to put non-minimal effort to maintain its configuration.
Starting a new project, from the scratch, takes more than a day to configure every tool you usually want to use.
Sometimes people create template project or another way of keeping your project configuration in a good shape is using buildSrc
plugins.
Less code written, ease of sharing between projects but still some part of the code needed to be copied.
This project goes further and addresses that issue by exposing set of plugins useful when approaching multi-module setup with Gradle build system.
Repository consists of several plugins that makes initial project configuration effortless and easily extensible. Each module consists of configuration code most commonly used in Android project configuration.
Plugin configures code style tasks, hooks for common tasks, sets coverage reports generation and manages versioning of the artifact
Apply plugin to project level build.gradle
plugins {
id("com.starter.library.kotlin") version("x.y.z")
}
// optional config with default values
projectConfig {
javaFilesAllowed false
}
javaFilesAllowed
- defines if the project can contain java files, fails the build otherwise
For kotlin multiplatform libraries apply plugin to project level build.gradle
plugins {
id("com.starter.library.multiplatform") version("x.y.z")
}
In addition to customizations made to Kotlin Library Plugin Android plugins
tweaks default Android Gradle Plugin setup by disabling BuildConfig file generation
or recognizing src/main/kotlin
(and similar) path as a valid source set.
Android Library plugin requires adding to project level build.gradle
:
plugins {
id("com.starter.library.android") version("x.y.z")
// or id("com.starter.application.android") version("x.y.z")
}
// optional config with default values
projectConfig {
javaFilesAllowed false
coverageExclusions [""]
}
// overridden settings for single project
android {
defaultConfig {
minSdkVersion 21
}
}
javaFilesAllowed
- defines if the project can contain java files, fails the build otherwise.
(Useful in large projects where you want to enforce new code written in new modules to be written in Java.)coverageExclusions
- defines jacoco coverage exclusions for specific module
After applying Library/Application plugin following tasks become available:
./gradlew projectTest
Runs tests for all modules using either predefined tasks (i.e.test
for kotlin modules ortestDebugUnitTest
for android libraries) or use customized values../gradlew projectLint
Runs Android lint checks against all modules (if custom lint checks are applied then for Kotlin modules too)./gradlew projectCodeStyle
Verifies if code style matches modern standards using tools such asktlint
,Detekt
with predefined config../gradlew projectCoverage
Automatically generates test coverage reports for all modules usingJacoco
Those tasks allows you to run tests efficiently for all modules by typing just a single task.
To only configure codestyle tools apply plugin to project level build.gradle
plugins {
id("com.starter.quality") version("x.y.z")
}
which applies and configures code style tasks for the project automatically.
Tasks available:
./gradlew projectCodeStyle
- checks codestyle using all tools./gradlew issueLinksReport
- finds and check state of all issuetracker links linked in code comments
Quality Plugin gets applied automatically when using any of module Application/Library plugins above.
Uses simple tag-based versioning, in a Configuration Cache compatible way.
To enable it as a standalone plugin, apply plugin to root project build.gradle
apply plugin: 'com.starter.versioning'
Versioning plugin gets applied automatically when using any of module Application/Library plugins above and can be disabled using Global Configuration
See Advanced usage
Sample Github Browser project - a customized, buildSrc
based plugin application.
The library is available under MIT License and highly benefits from binary dependencies: