Skip to content

Commit

Permalink
Merge pull request #4 from GradleUp/fix-plugin-apply-in-subprojects
Browse files Browse the repository at this point in the history
Fix plugin apply in subprojects
  • Loading branch information
tasomaniac authored Nov 13, 2020
2 parents fb3b8db + 1c09afe commit ac32af1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ autoManifest {

Ta-da 🎉 Now just put your Java/Kotlin files and don't worry about the rest.

Nested Modules
--------------

To make it easy for you `applyRecursively` is enabled by default. This will automatically generate
`AndroidManifest.xml` for you in all modules recursively. You have 2 options to override:

- If you need more info like permissions, Activity definitions, you can continue to have your
`AndroidManifest.xml` and recursive generation will be skipped for that module.
- If you need to override, you can apply the plugin again in a nested Gradle module and provide a
custom packageName

Performance
-----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ internal class AutoManifestConfigurator(
}
rootProject.afterEvaluate {
if (extension.applyRecursively.getOrElse(true)) {
subprojects.forEach { project ->
project.configure()
}
subprojects.configureSubjects()
}
}
}

private fun Set<Project>.configureSubjects() = forEach {
it.afterEvaluate {
if (pluginManager.hasPlugin("com.gradleup.auto.manifest").not()) {
configure()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ class AutoManifestPluginTest {
assertThat(libraryManifest.readText()).contains("<manifest package=\"test.library.dash\" />")
}

@Test
fun `should override packageName in when applied in leaf module`() {
val leafModule = "library1/data"
val leafDir = File(testProject.projectDir, leafModule)
val packageNameToOverride = "com.test.override"
createNestedModules(listOf(leafModule))

File(leafDir, "build.gradle").appendText("""
apply plugin: 'com.gradleup.auto.manifest'
autoManifest { packageName = '$packageNameToOverride' }
""".trimIndent())

testProject.build("assembleDebug", "autoManifest { packageName = 'test' }")

val libraryManifest = File(leafDir, "build/generated/auto-manifest/AndroidManifest.xml")
assertThat(libraryManifest.readText()).contains("<manifest package=\"$packageNameToOverride\" />")
}

private fun createNestedModules(moduleNames: List<String>) {
val commaSeparatedModules = moduleNames.joinToString(separator = ",") {
"'${it.replace('/', ':')}'"
Expand All @@ -128,7 +148,9 @@ class AutoManifestPluginTest {
plugins {
id 'com.android.library'
}
android { compileSdkVersion 28 }
android {
compileSdkVersion 28
}
""".trimIndent()
)
}
Expand Down

0 comments on commit ac32af1

Please sign in to comment.