Skip to content

Instantly share code, notes, and snippets.

@ubiratansoares
Last active May 15, 2020 00:20
Show Gist options
  • Save ubiratansoares/e2db55ccc1cc670b9802fb3952f65de4 to your computer and use it in GitHub Desktop.
Save ubiratansoares/e2db55ccc1cc670b9802fb3952f65de4 to your computer and use it in GitHub Desktop.
Magic Modules Blog Post
object GradleModules {
const val LOGIN = ":features:login"
const val SIGNUP = ":features:signup"
const val CATALOG_LIST = ":features:catalog:list"
const val CATALOG_DETAILS = ":features:catalog:details"
// ....
}
// Generated by MagicModules plugin. Mind your Linters!
import kotlin.String
import kotlin.collections.List
object Libraries {
const val FEATURES_HOME: String = ":features:home"
const val FEATURES_LOGIN: String = ":features:login"
const val COMMON_CORE: String = ":common:core"
const val COMMON_UTILS: String = ":common:utils"
val allAvailable: List<String> =
listOf(
FEATURES_HOME,
FEATURES_LOGIN,
COMMON_CORE,
COMMON_UTILS
)
}
rotProject.name='awesome-project'
apply plugin: "io.labs.dotanuki.magicmodules"
magicModules {
includeApps = false
}
include ':app'
// Note that both the app name and the control flag
// might be dynamically defined in our your build
// (eg, env vars)
class MagicModulesPlugin : Plugin<Settings> {
override fun apply(target: Settings) {
target.computeModulesAndPatchSettings()
}
private fun Settings.computeModulesAndPatchSettings() {
val parsedStructure = ProjectStructureParser().parse(settingsDir)
val processedScripts = BuildScriptsProcessor.process(parsedStructure)
gradle.settingsEvaluated {
processedScripts.forEach { processed ->
GradleSettingsPatcher.patch(this, processed)
ModuleNamesWriter.write(
folder = ResolveOutputFilesDir.using(settingsDir),
filename = processed.moduleType.conventionedFileName(),
coordinates = processed.coordinates
)
}
}
}
}
rootProject.name = 'my-superb-project'
include ':features:login'
include ':features:signup'
include ':features:catalog:list'
include ':features:catalog:details'
include ':features:catalog:recommendations'
// ...
include 'core:notifications'
include 'core::translations'
include 'core::security'
include 'core::networking'
// .......
include ':dagger-utils'
include ':extensions'
include ':legacy'
import org.gradle.api.Plugin
import org.gradle.api.Project
class SomeGradlePlugin : Plugin<Project> {
override fun apply(target: Project) {
// Plugin logic here
}
}
import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings
class SomeSettingsPlugin : Plugin<Settings> {
override fun apply(target: Settings) {
// Plugin logic here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment