Farhazul Mullick
07/16/2025, 4:15 PMrnett
07/17/2025, 1:12 AMCliOption
in the plugin with repeated = true
and pass repeated options. Haven't tested it myself thoughFarhazul Mullick
07/17/2025, 5:34 AMclass CliOption(
override val optionName: String,
override val valueDescription: String,
override val description: String,
override val required: Boolean = true,
override val allowMultipleOccurrences: Boolean = false
) : AbstractCliOption
Farhazul Mullick
07/17/2025, 5:39 AMoverride fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val extension = project.extensions.findByType(SemanticsExtension::class.java) ?:
throw IllegalStateException("SemanticsExtension not found in project ${project.name}")
val arg = extension.whiteListedUiComponents.joinToString(", ") { it.trim() }
return project.provider {
listOf(
SubpluginOption(key = OPTION_ENABLED, value = extension.enabled.toString()),
SubpluginOption(key = OPTION_TEST_TAG_PREFIX, value = extension.testTagPrefix),
SubpluginOption(key = OPTION_PACKAGE_NAME, value = extension.packageName.toString()),
SubpluginOption(
key = OPTION_WHITELISTED_UI_COMPONENTS,
value = extension.whiteListedUiComponents.joinToString(", ") { it.trim() }
)
)
}
}
open class SemanticsExtension {
/**
* @property enabled Enables or disables the semantics plugin. Default is true.
*/
var enabled: Boolean = true
/**
* @property whiteListedUiComponents List of UI component to generate Ids.
* By default it is empty, meaning all components are whitelisted. Ids for all components will be generated.
* Example: listOf("Button", "Text", "Image")
*/
var whiteListedUiComponents: List<String> = emptyList()
}
In command line processor
override val pluginOptions: Collection<CliOption> = listOf(
CliOption(
optionName = OPTION_ENABLED,
valueDescription = "true|false",
description = "Enable semantics plugin"
),
CliOption(
optionName = OPTION_WHITELISTED_UI_COMPONENTS,
valueDescription = "string",
description = "Comma-separated list of UI components",
)
)
override fun processOption(
option: AbstractCliOption,
value: String,
configuration: CompilerConfiguration
) {
when (option.optionName) {
OPTION_ENABLED -> configuration.put(ARG_ENABLED, value.toBoolean())
OPTION_WHITELISTED_UI_COMPONENTS -> {
val components = value.split(", ").map { it.trim() }.filter { it.isNotEmpty() }
configuration.put(ARG_WHITELISTED_UI_COMPONENTS, components)
}
else -> throw IllegalArgumentException("Unknown option: ${option.optionName}")
}
}
This whiteListedUiComponents list is not workingFarhazul Mullick
07/17/2025, 5:42 AMFarhazul Mullick
07/17/2025, 6:10 AMSubpluginOption(
key = OPTION_WHITELISTED_UI_COMPONENTS,
value = "Text,Button"
)
Passing something like this is throwing same error
Wrong plugin option format: null, should be plugin:<pluginId>:<optionName>=<value>
rnett
07/17/2025, 5:57 PMallowMultipleOccurrences
at all, I would expect it to work. Is OPTION_WHITELISTED_UI_COMPONENTS
initialized and doesn't have any nulls or whitespace or :
, etc? And does your value have spaces? Your processOption
is attempting to split on ", "
when it should probably be ","
Farhazul Mullick
07/18/2025, 4:48 AMSubpluginOption
keeping the key name same. This worked for me.
list.map{ SubpluginOptions(key, it) },
kept key name same