Skip to content

Commit

Permalink
Update SVG transcoder Gradle plugin docs
Browse files Browse the repository at this point in the history
With the recommendation to use a separate source folder
  • Loading branch information
kirill-grouchnikov committed Feb 13, 2022
1 parent 95078cc commit d72d047
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions docs/tools/svg-transcoder/svg-transcoder-gradle-plugin.md
Expand Up @@ -40,14 +40,41 @@ buildscript {
}
```

### Configuring a source directory for transcoded files

Your SVG content is the source of truth for the transcoded icons, and should be a part of your versioned codebase. The transcoded files themselves, on the other hand, are a generated artifact and should be treated as such.

Start by choosing where to place them as a separate "source" folder which will be added to your `.gitignore`, let's say `src/gen`.

Configure your Kotlin source set to include that folder, as well as mark it for IDEA as a generated source:

```groovy
kotlin {
sourceSets {
kotlin {
sourceSets["desktopMain"].apply {
kotlin.srcDir("$rootDir/src/desktopMain/kotlin")
kotlin.srcDir("$rootDir/src/gen/kotlin")
}
}
}
}
idea {
module {
generatedSourceDirs.add(file("$rootDir/src/gen/kotlin"))
}
}
```

### Transcoding SVG files from a single folder

Register a separate task for generating Kotlin classes and add a `dependsOn` clause for your `KotlinCompile` tasks. Add multiple tasks if you have more than one SVG content folder.

```kotlin
tasks.register<org.pushingpixels.aurora.tools.svgtranscoder.gradle.TranscodeTask>("transcodeSingle") {
inputDirectory = file("src/desktopMain/resources")
outputDirectory = file("src/desktopMain/kotlin/org/aurora/demo/svg")
outputDirectory = file("src/gen/kotlin/org/aurora/demo/svg")
outputPackageName = "org.aurora.demo.svg"
transcode()
}
Expand All @@ -64,22 +91,24 @@ tasks.withType<KotlinCompile> {
doFirst {
task<org.pushingpixels.aurora.tools.svgtranscoder.gradle.TranscodeTask>("transcodeSingle") {
inputDirectory = file("src/desktopMain/resources")
outputDirectory = file("src/desktopMain/kotlin/org/aurora/demo/svg2")
outputDirectory = file("src/gen/kotlin/org/aurora/demo/svg2")
outputPackageName = "org.aurora.demo.svg2"
transcode()
}
}
}
```

Note that we're using our separate `src/gen` folder as the `outputDirectory`

### Recursively transcoding SVG files under a folder

Register a separate task for generating Kotlin classes and add a dependsOn clause for your KotlinCompile tasks. Add multiple tasks if you have more than one SVG content folder.

```kotlin
tasks.register<org.pushingpixels.aurora.tools.svgtranscoder.gradle.TranscodeDeepTask>("transcodeFolder") {
inputRootDirectory = file("src/desktopMain/resources/scalable")
outputRootDirectory = file("src/desktopMain/kotlin/org/aurora/demo/scalable/svg")
outputRootDirectory = file("src/gen/kotlin/org/aurora/demo/scalable/svg")
outputRootPackageName = "org.aurora.demo.scalable.svg"
transcode()
}
Expand All @@ -96,14 +125,16 @@ tasks.withType<KotlinCompile> {
doFirst {
task<org.pushingpixels.aurora.tools.svgtranscoder.gradle.TranscodeDeepTask>("transcodeFolder") {
inputRootDirectory = file("src/desktopMain/resources")
outputRootDirectory = file("src/desktopMain/kotlin/org/aurora/demo/scalable/svg2")
outputRootDirectory = file("src/gen/kotlin/org/aurora/demo/scalable/svg2")
outputRootPackageName = "org.aurora.demo.scalable.svg2"
transcode()
}
}
}
```

Note that we're using our separate `src/gen` folder as the `outputDirectory`

### Additional notes

Note that using `tasks.withType<KotlinCompile>` assumes that you have at least one "real" source file in your project so that these tasks are executed by Gradle. If you are planning to use the plugin in a module that will have only SVG content and the transcoded classes, you will need to use the transcode tasks in a different way (perhaps as a default task).
Expand Down

0 comments on commit d72d047

Please sign in to comment.