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
Copy
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:
  1. Configuration Parsing: reads the svgToCompose extension settings from your build script
  2. Icon Scanning: finds SVG and AVG files in the specified source directories
  3. Icon Processing: applies configured options such as optimization and minification
  4. Code Generation: generates Kotlin ImageVector code in the specified package
  5. 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
Copy

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
Copy

Configuration Options

Processor Configuration

These options are available at the processor level:
  • from(Directory): Source directory containing SVG/AVG icon files
  • destinationPackage(String): Target package for generated ImageVector objects
  • optimize(Boolean): Enable SVG optimization before conversion
  • recursive(): Recursively search for icons in subdirectories
  • maxDepth(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 annotations
  • minify(): Remove comments and extra whitespace from generated code
  • noPreview(): Disable generation of @Preview composable functions
  • makeInternal(): Add the internal visibility modifier to generated code
  • receiverType(String): Set a receiver type for the generated ImageVector extension property
  • addToMaterialIcons(): Use Material Icons as the receiver type for generated properties
  • mapIconNameTo((String) -> String): Transform function to customize generated icon names
  • exclude(vararg Regex): Exclude files matching the given filename patterns
  • persist(): 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
Copy
  • 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
Copy