A simple plugin to run an XSLT transform
Requires Java 11 or newer.
plugins {
id("io.github.edgsousa.gradle.xslt").version("0.1")
}
The XSLT transform will be executed once for each file in models. The output file name will be the same as the original model name, but changing the file extension to the provided suffix.
tasks.register<XSLT>("taskname") {
xsl = project.file("src/main/resources/stylesheet.xsl")
models = project.fileTree("src/main/resources") {
include("*.xml")
}
outputDirectory = project.buildDir.resolve("generated/taskname/")
outputFileSuffix = "java"
}.also { task ->
// if to run automatically the transform task
tasks.withType<JavaCompile>().configureEach { dependsOn(task) }
}
If generating Java code e.g.
sourceSets {
main {
java {
srcDir(project.buildDir.resolve("generated/taskname/"))
}
}
}