The repository contains utilities for Jetpack Compose, including Kotlin compiler plugins, IDEA plugin, and a Detekt rule.
Plugin Version | Kotlin version |
---|---|
0.6.1 | 1.8.10 - 1.9.23 |
0.6-k2 | 2.0 |
0.6.1-k2 | 2.0.20 |
Currently, the following compiler plugins are available:
- Functions skippability checker: Determines function skippability based on checking function parameters stability.
- Recomposed function highlighter: Highlights recomposed functions with a colored border which increases the width when the recompositions count becomes larger. See here
- Recomposed function reasons logger: Logs reasons for recomposed functions when arguments of that function has been changed. It's like a Rebugger, but automated. You don’t need to register the logger/rebugger in suspected problem areas every time
- Test tag generator for Composable functions: Adds generated test tag for composable function if there is a default Modifier that does not have an applied testTag.
- Test tag remover: Removes all test tags by replacing them with an empty string.
- Test tag drawer: Draws test tags in a dialog for long tap. (It`s very experimental. I am looking for a better solution)
- SourceInformation function calls remover: Yes, you can use sourceInformation option for Compose Compiler "-Pplugin:androidx.compose.compiler.plugins.kotlin:sourceInformation=false", but AGP enables that by default for debug builds. For AGP 8.4.0 see use Compose Compiler option. You can see fix here
How to use?
- Apply Gradle plugin
plugins {
id("com.vk.vkompose") version "0.6.1"
}
- Enable and configure your desired features. For example:
vkompose {
skippabilityCheck = true
// or
skippabilityCheck {
// For more see
// https://android-review.googlesource.com/c/platform/frameworks/support/+/2668595
// https://issuetracker.google.com/issues/309765121
stabilityConfigurationPath = "/path/file.config"
// since 0.6.1 if strong skipping feature of Compose Compiler is enabled
strongSkippingEnabled = true
// or
strongSkipping {
// Fail compilation if there is any problem with strong skipping mode
strongSkippingFailFastEnabled = false // false by default
}
}
recompose {
isHighlighterEnabled = true
isLoggerEnabled = true
// or
logger {
// true by default since 0.5
// log modifier arguments changes
logModifierChanges = true
// true by default since 0.5
// log when function arguments (like lambdas or function references) of composable function are changed
logFunctionChanges = true
}
}
testTag {
isApplierEnabled = true
isDrawerEnabled = false
isCleanerEnabled = false
}
sourceInformationClean = true
}
- Enable some plugins in your application code
import com.vk.compose.test.tag.drawer.TestTagDrawConfig
import com.vk.recompose.highlighter.RecomposeHighlighterConfig
import com.vk.recompose.logger.RecomposeLoggerConfig
RecomposeLoggerConfig.isEnabled = true
RecomposeHighlighterConfig.isEnabled = true
TestTagDrawConfig.isEnabled = true
Besides these plugins are published separately. So if you want to use only one, you can do.
plugins {
id("com.vk.recompose-highlighter") version "0.6.1"
id("com.vk.recompose-logger") version "0.6.1"
id("com.vk.compose-test-tag-applier") version "0.6.1"
id("com.vk.compose-test-tag-cleaner") version "0.6.1"
id("com.vk.compose-test-tag-drawer") version "0.6.1"
id("com.vk.compose-source-information-cleaner") version "0.6.1"
id("com.vk.composable-skippability-checker") version "0.6.1"
}
recomposeHighlighter {
isEnabled = false // true by default
}
recomposeLogger {
isEnabled = false // true by default
logModifierChanges = true // true by default since 0.5
logFunctionChanges = true // true by default since 0.5
}
composeTestTagApplier {
isEnabled = false // true by default
}
composeTestTagCleaner {
isEnabled = false // true by default
}
composeTestTagDrawer {
isEnabled = false // true by default
}
composeSourceInformationCleaner {
isEnabled = false // true by default
}
composableSkippabilityChecker {
isEnabled = false // true by default
stabilityConfigurationPath = "/path/file.config"
}
Also if you enable recompose logger, you can add logger manually function that track changes of arguments. For example:
import com.vk.recompose.logger.RecomposeLogger
RecomposeLogger(
name = "Some Function Name",
arguments = mapOf("param1" to param1, "param2" to param2),
)
And check logs with tag "RecomposeLogger". This already looks like the Rebugger is working.
The IDEA plugin currently offers two features:
-
Skippability checks
Both features can be disabled in preferences: You can download and install it from the jar file for Iguana, Jellyfish, Koala or Ladybug versions of AS.
Detekt Rule
Current version is 0.6
.
There is one rule available that checks the skippability of functions or stability of parameters. To use it, apply the dependency via the detektPlugin configuration in the dependencies block.
dependencies {
detektPlugins("com.vk.vkompose:detekt:0.6")
}
Also you can disable checking some classes in detekt config file
vkompose:
NonSkippableComposable:
active: true
ignoredClasses: [ 'kotlin.*', 'my.clazz.Data' ]
# since 0.6
# It's usually the same thing as NonSkippableComposable, but the name is more correct for strong skip mode
ParamsComparedByRef:
active: true
ignoredClasses: [ 'kotlin.*', 'my.clazz.Data' ]
In the compiler plugin, detector rules and plugin functions, ideas can be suppressed by either of the suppressions: NonSkippableComposable or ParamsComparedByRef. The NonSkippableComposable suppression will be removed in the future. For now, if strong skip is enabled, the idea plugin will mark NonSkippableComposable as unused and you can easily switch to ParamsComparedByRef
- Idea plugin cannot draw a test tag marker for functions from other libraries if they have a default Modifier value and Modifier is not explicitly passes as an argument. For more see KTIJ-27688