Table of Contents
Gradle Plugin
Overview
The SVG/XML to Compose Gradle Plugin simplifies the process of converting SVG and Android Vector Drawable (AVG/XML) files into Jetpack Compose ImageVector properties. It automates the conversion process during your build, ensuring consistency and saving development time.Key features:
- Automatic conversion during Kotlin compilation
- Smart caching for incremental builds
- Configurable processing options per icon set
- Parallel processing support via Gradle Worker API
- Common configuration for shared settings across processors
Platform Support
The Gradle plugin supports Android and Kotlin Multiplatform projects.
Installation
build.gradle.kts
Make sure Maven Central is included in your plugin repositories
settings.gradle.kts.
How It Works
The plugin integrates into your Gradle build lifecycle with the following processing flow:
- Configuration Parsing: reads the svgToCompose extension settings from your build script
- Icon Scanning: finds SVG and AVG files in the specified source directories
- Icon Processing: applies configured options such as optimization and minification
- Code Generation: generates Kotlin ImageVector code in the specified package
- Build Integration: generated code is included in the Kotlin compilation classpath
The plugin checks for changes and uses a built-in cache. When configuration changes, the cache is invalidated to regenerate icons.
Basic Configuration
Configure the plugin using the svgToCompose extension in your build script:
build.gradle.kts
Common Configuration
Use the common block to define shared settings that apply to all processors. Individual processor configurations can override common settings.
build.gradle.kts
Configuration Options
Processor Configuration
These options are available at the processor level:
from(Directory): Source directory containing SVG/AVG icon filesdestinationPackage(String): Target package for generated ImageVector objectsoptimize(Boolean): Enable SVG optimization before conversionrecursive(): Recursively search for icons in subdirectoriesmaxDepth(Int): Maximum depth for recursive directory search
Icon Parser Configuration
These options are available inside the icons { } block:
theme(String): Fully qualified theme class name used for preview annotationsminify(): Remove comments and extra whitespace from generated codenoPreview(): Disable generation of @Preview composable functionsmakeInternal(): Add the internal visibility modifier to generated codereceiverType(String): Set a receiver type for the generated ImageVector extension propertyaddToMaterialIcons(): Use Material Icons as the receiver type for generated propertiesmapIconNameTo((String) -> String): Transform function to customize generated icon namesexclude(vararg Regex): Exclude files matching the given filename patternspersist(): Persist generated files to the source directory (delicate API)
Parallel Processing
Enable parallel processing to speed up conversion of large icon sets:
build.gradle.kts
- Parallelism is bounded by Gradle's
--max-workers setting - Default value (0 or 1) runs processing sequentially
- Caching is preserved: unchanged icons are skipped regardless of parallelism
Persistent Generation
The
persist() function is a delicate API. When enabled, generated files are written directly to your source directory instead of the build directory. Use this only when you need to commit generated code to version control.
build.gradle.kts