Skip to content

Commit 7c0dcfb

Browse files
Add option to disable compose resources generation (JetBrains#4526)
# Changes * Add `Never` to `enum class ResourceClassGeneration` to disable the generation of Res class in the gradle plugin # Motivation As the [comment in issue 4229](JetBrains#4229 (comment)) said, my team is not in the ecosystem of gradle, but organize the build steps in bazel. We want to follow the files layout but just disable the generation task of gradle and handle it by outself.
1 parent 5f67523 commit 7c0dcfb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesExtension.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ abstract class ResourcesExtension {
1717
*/
1818
var packageOfResClass: String = ""
1919

20-
enum class ResourceClassGeneration { Auto, Always }
20+
enum class ResourceClassGeneration { Auto, Always, Never }
2121

2222
//to support groovy DSL
2323
val auto = ResourceClassGeneration.Auto
2424
val always = ResourceClassGeneration.Always
25+
val never = ResourceClassGeneration.Never
2526

2627
/**
2728
* The mode of resource class generation.
2829
*
2930
* - `auto`: The Res class will be generated if the current project has an explicit "implementation" or "api" dependency on the resource's library.
3031
* - `always`: Unconditionally generate the Res class. This may be useful when the resources library is available transitively.
32+
* - `never`: Never generate the Res class.
3133
*/
3234
var generateResClass: ResourceClassGeneration = auto
3335
}

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ private fun Project.configureResourceGenerator(
323323
ResourcesExtension.ResourceClassGeneration.Always -> {
324324
true
325325
}
326+
ResourcesExtension.ResourceClassGeneration.Never -> {
327+
false
328+
}
326329
}
327330
}
328331

gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,20 @@ class ResourcesTest : GradlePluginTestBase() {
510510
.map { it.toPath().relativeTo(actualPath) }.sorted().joinToString("\n")
511511
assertEquals(expectedFilesCount, actualFilesCount)
512512
}
513+
514+
@Test
515+
fun testResourcesTaskDisabled() = with(testProject("misc/commonResources")) {
516+
file("build.gradle.kts").appendText(
517+
"""
518+
compose {
519+
resources {
520+
generateResClass = never
521+
}
522+
}
523+
""".trimIndent()
524+
)
525+
gradle("generateComposeResClass").checks {
526+
check.logContains("Generation Res class is disabled")
527+
}
528+
}
513529
}

0 commit comments

Comments
 (0)