Skip to content

Latest commit

 

History

History
226 lines (177 loc) · 7.64 KB

svg-transcoder-gradle-plugin.md

File metadata and controls

226 lines (177 loc) · 7.64 KB

Gradle plugin for transcoding SVG content

The goal of this project is to allow build-time transcoding of SVG content into Java / Kotlin classes by wrapping SVG transcoder APIs and making them available for Gradle builds.

Maven Central radiance-svg-transcoder-gradle-plugin for build instructions of the latest stable release.

Using the plugin in your Gradle script, Groovy DSL flavor

The instructions in this section apply to the build script written in Groovy, usually placed in the build.gradle file.

Add the plugin to the buildscript part of your Gradle build file and apply the plugin:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.pushing-pixels:radiance-svg-transcoder-gradle-plugin:X.Y.Z'
    }
}

apply plugin: 'org.pushing-pixels.radiance.tools.svgtranscoder.gradle'

In case you want to use the latest snapshot version of the plugin, use the Sonatype repository:

buildscript {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
    dependencies {
        classpath 'org.pushing-pixels:radiance-svg-transcoder-gradle-plugin:X.Y.Z-SNAPSHOT'
    }
}

Transcoding SVG files from a single folder

For a Java project, generate Java classes with the plugin (add multiple transcode lambdas if you have more than one SVG content folder):

compileJava.doFirst {
    transcode {
        inputDirectory = file('src/main/resources')
        outputDirectory = file('src/main/java/org/radiance/demo/svg')
        outputLanguage = 'java'
        outputPackageName = 'org.radiance.demo.svg'
        transcode()
    }
}

For a Kotlin project, generate Kotlin classes with the plugin (add multiple transcode lambdas if you have more than one SVG content folder):

compileKotlin.doFirst {
    transcode {
        inputDirectory = file('src/main/resources')
        outputDirectory = file('src/main/java/org/radiance/demo/svg')
        outputLanguage = 'kotlin'
        outputPackageName = 'org.radiance.demo.svg'
        transcode()
    }
}

Recursively transcoding SVG files under a folder

For a Java project, generate Java classes with the plugin (add multiple transcodeDeep lambdas if you have more than one SVG content root folder):

compileJava.doFirst {
    transcodeDeep {
        inputRootDirectory = file('src/main/resources')
        outputRootDirectory = file('src/main/java/org/radiance/demo/svg')
        outputLanguage = 'java'
        outputRootPackageName = 'org.radiance.demo.svg'
        transcode()
    }
}

For a Kotlin project, generate Kotlin classes with the plugin (add multiple transcodeDeep lambdas if you have more than one SVG content root folder):

compileKotlin.doFirst {
    transcodeDeep {
        inputRootDirectory = file('src/main/resources')
        outputRootDirectory = file('src/main/java/org/radiance/demo/svg')
        outputLanguage = 'kotlin'
        outputRootPackageName = 'org.radiance.demo.svg'
        transcode()
    }
}

Additional notes

Note that using either compileJava or compileKotlin 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 / transcodeDeep tasks in a different way (perhaps as a default task).

You also need to declare a dependency on the matching common version in order to compile the transcoded classes:

dependencies {
    implementation 'org.pushing-pixels:radiance-common:X.Y.Z'
}

Using the plugin in your Gradle script, Kotlin DSL flavor

The instructions in this section apply to the build script written in Kotlin, usually placed in the build.gradle.kts file.

Add the plugin to the buildscript part of your Gradle build file and apply the plugin:

import org.pushingpixels.radiance.tools.svgtranscoder.gradle.TranscodeTask
import org.pushingpixels.radiance.tools.svgtranscoder.gradle.TranscodeDeepTask

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.pushing-pixels:radiance-svg-transcoder-gradle-plugin:X.Y.Z")
    }
}

apply(plugin = "org.pushing-pixels.radiance.tools.svgtranscoder.gradle")

In case you want to use the latest snapshot version of the plugin, use the Sonatype repository:

buildscript {
    repositories {
        maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
    }
    dependencies {
        classpath("org.pushing-pixels:radiance-svg-transcoder-gradle-plugin:X.Y.Z-SNAPSHOT")
    }
}

Transcoding SVG files from a single folder

For a Java project, generate Java classes with the plugin (add multiple tasks.create<TranscodeTask> if you have more than one SVG content folder):

tasks.create<TranscodeTask>("transcodeMySingle") {
    inputDirectory = file("src/main/resources")
    outputDirectory = file("src/main/java/org/radiance/demo/svg")
    outputLanguage = "java"
    outputPackageName = "org.radiance.demo.svg"
    transcode()
}

tasks.compileJava {
    dependsOn("transcodeMySingle")
}

For a Kotlin project, generate Kotlin classes with the plugin (add multiple tasks.create<TranscodeTask> if you have more than one SVG content folder):

tasks.create<TranscodeTask>("transcodeMySingle") {
    inputDirectory = file("src/main/resources")
    outputDirectory = file("src/main/java/org/radiance/demo/svg")
    outputLanguage = "kotlin"
    outputPackageName = "org.radiance.demo.svg"
    transcode()
}

tasks.compileKotlin {
    dependsOn("transcodeMySingle")
}

Recursively transcoding SVG files under a folder

For a Java project, generate Java classes with the plugin (add multiple tasks.create<TranscodeDeepTask> if you have more than one SVG content root folder):

tasks.create<TranscodeDeepTask>("transcodeMyDeep") {
    inputRootDirectory = file("src/main/resources/scalable")
    outputRootDirectory = file("src/main/java/org/radiance/demo/svg")
    outputLanguage = "java"
    outputRootPackageName = "org.radiance.demo.svg"
    transcode()
}

tasks.compileJava {
    dependsOn("transcodeMyDeep")
}

For a Kotlin project, generate Kotlin classes with the plugin (add multiple tasks.create<TranscodeDeepTask> if you have more than one SVG content root folder):

tasks.create<TranscodeDeepTask>("transcodeMyDeep") {
    inputRootDirectory = file("src/main/resources/scalable")
    outputRootDirectory = file("src/main/java/org/radiance/demo/svg")
    outputLanguage = "kotlin"
    outputRootPackageName = "org.radiance.demo.svg"
    transcode()
}

tasks.compileJava {
    dependsOn("transcodeMyDeep")
}

Additional notes

Note that using either compileJava or compileKotlin 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 TranscodeTask / TranscodeDeepTask tasks in a different way (perhaps as a default task).

You also need to declare a dependency on the matching common version in order to compile the transcoded classes:

dependencies {
    implementation("org.pushing-pixels:radiance-common:X.Y.Z")
}