Skip to content

Commit

Permalink
Add a property 'compose.resources.generate.certainly' to generate res…
Browse files Browse the repository at this point in the history
…ources in the demo app
  • Loading branch information
terrakok committed Nov 22, 2023
1 parent cce4e94 commit dda0451
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions components/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ agp.version=8.1.2
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.macos.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true
compose.resources.generate.certainly=true
compose.desktop.verbose=true
compose.useMavenLocal=false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 GENERATE_RESOURCES_CERTAINLY = "compose.resources.generate.certainly"

fun isVerbose(providers: ProviderFactory): Provider<Boolean> =
providers.valueOrNull(VERBOSE).toBooleanProvider(false)
Expand Down Expand Up @@ -51,4 +52,7 @@ internal object ComposeProperties {

fun checkJdkVendor(providers: ProviderFactory): Provider<Boolean> =
providers.valueOrNull(CHECK_JDK_VENDOR).toBooleanProvider(true)

fun generateResourcesCertainly(providers: ProviderFactory): Provider<Boolean> =
providers.valueOrNull(GENERATE_RESOURCES_CERTAINLY).toBooleanProvider(false)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.jetbrains.compose.resources

import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.ComposePlugin
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import java.io.File

private const val COMPOSE_RESOURCES_DIR = "composeRes"
private const val RES_GEN_DIR = "generated/compose/resourceGenerator"

@OptIn(ExperimentalComposeLibrary::class)
internal fun Project.configureResourceGenerator() {
val kotlinExtension = project.extensions.getByType(KotlinProjectExtension::class.java)
val commonSourceSet = kotlinExtension.sourceSets.findByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME) ?: return
Expand All @@ -27,17 +33,17 @@ internal fun Project.configureResourceGenerator() {
val resDir = layout.dir(commonResourcesDir.map { it.resolve(COMPOSE_RESOURCES_DIR) })

//lazy check a dependency on the Resources library
val dependsOnResourcesLibrary = provider {
val composeResourcesLibraryNotations = setOf(
"org.jetbrains.compose.components:components-resources",
"components.resources:library" //for demo app only
)
configurations
.getByName(commonSourceSet.implementationConfigurationName)
.allDependencies.any { dep ->
val depStringNotation = dep.group + ":" + dep.name
depStringNotation in composeResourcesLibraryNotations
}
val dependsOnResourcesLibrary: Provider<Boolean> = provider {
if (ComposeProperties.generateResourcesCertainly(providers).get()) {
true
} else {
configurations
.getByName(commonSourceSet.implementationConfigurationName)
.allDependencies.any { dep ->
val depStringNotation = dep.let { "${it.group}:${it.name}:${it.version}" }
depStringNotation == ComposePlugin.CommonComponentsDependencies.resources
}
}
}

val genTask = tasks.register(
Expand Down

0 comments on commit dda0451

Please sign in to comment.