diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/ComposeProjectProperties.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/ComposeProjectProperties.kt index 065d258221..abe936f0b2 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/ComposeProjectProperties.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/ComposeProjectProperties.kt @@ -22,7 +22,7 @@ internal object ComposeProperties { internal const val MAC_NOTARIZATION_PASSWORD = "compose.desktop.mac.notarization.password" internal const val MAC_NOTARIZATION_TEAM_ID_PROVIDER = "compose.desktop.mac.notarization.teamID" internal const val CHECK_JDK_VENDOR = "compose.desktop.packaging.checkJdkVendor" - internal const val ALWAYS_GENERATE_RESOURCE_ACCESSORS = "compose.resources.always.generate.accessors" + internal const val DISABLE_MULTIMODULE_RESOURCES = "org.jetbrains.compose.resources.multimodule.disable" internal const val SYNC_RESOURCES_PROPERTY = "compose.ios.resources.sync" fun isVerbose(providers: ProviderFactory): Provider = @@ -55,6 +55,9 @@ internal object ComposeProperties { fun checkJdkVendor(providers: ProviderFactory): Provider = providers.valueOrNull(CHECK_JDK_VENDOR).toBooleanProvider(true) + fun disableMultimoduleResources(providers: ProviderFactory): Provider = + providers.valueOrNull(DISABLE_MULTIMODULE_RESOURCES).toBooleanProvider(false) + //providers.valueOrNull works only with root gradle.properties fun dontSyncResources(project: Project): Provider = project.provider { project.findProperty(SYNC_RESOURCES_PROPERTY)?.toString().equals("false", true) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ComposeResources.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ComposeResources.kt index 12f8486fb5..3c973879a5 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ComposeResources.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ComposeResources.kt @@ -9,6 +9,7 @@ import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskProvider import org.gradle.util.GradleVersion import org.jetbrains.compose.ComposePlugin +import org.jetbrains.compose.desktop.application.internal.ComposeProperties import org.jetbrains.compose.internal.KOTLIN_JVM_PLUGIN_ID import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension @@ -41,23 +42,26 @@ private fun Project.onKgpApplied(config: Provider, kgp: Kotl val hasKmpResources = extraProperties.has(KMP_RES_EXT) val currentGradleVersion = GradleVersion.current() val minGradleVersion = GradleVersion.version(MIN_GRADLE_VERSION_FOR_KMP_RESOURCES) - val kmpResourcesAreAvailable = hasKmpResources && currentGradleVersion >= minGradleVersion + val disableMultimoduleResources = ComposeProperties.disableMultimoduleResources(providers).get() + val kmpResourcesAreAvailable = !disableMultimoduleResources && hasKmpResources && currentGradleVersion >= minGradleVersion if (kmpResourcesAreAvailable) { configureKmpResources(kotlinExtension, extraProperties.get(KMP_RES_EXT)!!, config) } else { - if (!hasKmpResources) logger.info( - """ - Compose resources publication requires Kotlin Gradle Plugin >= 2.0 - Current Kotlin Gradle Plugin is ${kgp.pluginVersion} - """.trimIndent() - ) - if (currentGradleVersion < minGradleVersion) logger.info( - """ - Compose resources publication requires Gradle >= $MIN_GRADLE_VERSION_FOR_KMP_RESOURCES - Current Gradle is ${currentGradleVersion.version} - """.trimIndent() - ) + if (!disableMultimoduleResources) { + if (!hasKmpResources) logger.info( + """ + Compose resources publication requires Kotlin Gradle Plugin >= 2.0 + Current Kotlin Gradle Plugin is ${kgp.pluginVersion} + """.trimIndent() + ) + if (currentGradleVersion < minGradleVersion) logger.info( + """ + Compose resources publication requires Gradle >= $MIN_GRADLE_VERSION_FOR_KMP_RESOURCES + Current Gradle is ${currentGradleVersion.version} + """.trimIndent() + ) + } val commonMain = KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME configureComposeResources(kotlinExtension, commonMain, config) diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt index 8dfbd0c527..07346a051c 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt @@ -1,6 +1,7 @@ package org.jetbrains.compose.test.tests.integration import org.gradle.util.GradleVersion +import org.jetbrains.compose.desktop.application.internal.ComposeProperties import org.jetbrains.compose.internal.utils.* import org.jetbrains.compose.resources.XmlValuesConverterTask import org.jetbrains.compose.test.utils.* @@ -158,42 +159,50 @@ class ResourcesTest : GradlePluginTestBase() { check.logContains("${testXml.name} is not valid. Check the file content.") } - testXml.writeText(""" + testXml.writeText( + """ aaa - """.trimIndent()) + """.trimIndent() + ) gradleFailure("prepareKotlinIdeaImport").checks { check.logContains("${testXml.name} is not valid. Unknown resource type: 'aaa'.") } - testXml.writeText(""" + testXml.writeText( + """ aaa - """.trimIndent()) + """.trimIndent() + ) gradleFailure("prepareKotlinIdeaImport").checks { check.logContains("${testXml.name} is not valid. Unknown string resource type: 'drawable'.") } - testXml.writeText(""" + testXml.writeText( + """ aaa aaa aaa aaa - """.trimIndent()) + """.trimIndent() + ) gradleFailure("prepareKotlinIdeaImport").checks { check.logContains("${testXml.name} is not valid. Duplicated key 'v1'.") } - testXml.writeText(""" + testXml.writeText( + """ aaa aaa - """.trimIndent()) + """.trimIndent() + ) gradleFailure("prepareKotlinIdeaImport").checks { check.logContains("${testXml.name} is not valid. Attribute 'name' not found.") } @@ -219,7 +228,7 @@ class ResourcesTest : GradlePluginTestBase() { @Test fun testMultiModuleResources() { val environment = defaultTestEnvironment.copy( - kotlinVersion = "2.0.0-Beta5" + kotlinVersion = "2.0.0-RC2" ) with( testProject("misc/kmpResourcePublication", environment) @@ -232,6 +241,8 @@ class ResourcesTest : GradlePluginTestBase() { } gradle(":cmplib:publishAllPublicationsToMavenRepository").checks { + check.logContains("Configure KMP resources") + val resDir = file("cmplib/src/commonMain/composeResources") val resourcesFiles = resDir.walkTopDown() .filter { !it.isDirectory && !it.isHidden } @@ -317,6 +328,22 @@ class ResourcesTest : GradlePluginTestBase() { } } + @Test + fun testDisableMultimoduleResourcesWithNewKotlin() { + val environment = defaultTestEnvironment.copy( + kotlinVersion = "2.0.0-RC2" + ) + + with(testProject("misc/kmpResourcePublication", environment)) { + file("gradle.properties").modify { content -> + content + "\n" + ComposeProperties.DISABLE_MULTIMODULE_RESOURCES + "=true" + } + gradle(":cmplib:build").checks { + check.logContains("Configure compose resources") + } + } + } + private fun checkResourcesZip(zipFile: File, resourcesFiles: Sequence, subdir: String) { assertTrue(zipFile.exists(), "File not found: " + zipFile.path) ZipFile(zipFile).use { zip -> diff --git a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/appModule/build.gradle.kts b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/appModule/build.gradle.kts index 284ef60aba..aac9ee2149 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/appModule/build.gradle.kts +++ b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/appModule/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.compose.ExperimentalComposeLibrary plugins { id("org.jetbrains.compose") kotlin("multiplatform") + kotlin("plugin.compose") id("com.android.application") } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/build.gradle.kts b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/build.gradle.kts index 48a6134174..7dddc27d0a 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/build.gradle.kts +++ b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("org.jetbrains.compose").apply(false) kotlin("multiplatform").apply(false) + kotlin("plugin.compose").apply(false) id("com.android.library").apply(false) id("com.android.application").apply(false) } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/cmplib/build.gradle.kts b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/cmplib/build.gradle.kts index 2688ae111d..ed9522a57c 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/cmplib/build.gradle.kts +++ b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/cmplib/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("org.jetbrains.compose") kotlin("multiplatform") + kotlin("plugin.compose") id("maven-publish") id("com.android.library") } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/featureModule/build.gradle.kts b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/featureModule/build.gradle.kts index 923d35fd92..3d239458d8 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/featureModule/build.gradle.kts +++ b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/featureModule/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("org.jetbrains.compose") kotlin("multiplatform") + kotlin("plugin.compose") id("com.android.library") } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/settings.gradle.kts b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/settings.gradle.kts index 5b229446ba..703dc4e967 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/settings.gradle.kts +++ b/gradle-plugins/compose/src/test/test-projects/misc/kmpResourcePublication/settings.gradle.kts @@ -15,6 +15,7 @@ pluginManagement { } plugins { id("org.jetbrains.kotlin.multiplatform").version("KOTLIN_VERSION_PLACEHOLDER") + id("org.jetbrains.kotlin.plugin.compose").version("KOTLIN_VERSION_PLACEHOLDER") id("org.jetbrains.compose").version("COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER") id("com.android.library").version("AGP_VERSION_PLACEHOLDER") id("com.android.application").version("AGP_VERSION_PLACEHOLDER")