RJ Garcia
09/11/2024, 10:03 PMcreateXSD) that invokes the org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd class.
And i'm looking the ability to wrap this task/class so that I can call it via the cli like: ./gradlew createXSD --file {path-to-xml}
Where --file is a custom input parameter for my custom registered task which passes that down the corresponding args to Inst2Xsd.RJ Garcia
09/11/2024, 10:05 PM-P flag to set a property configuration value and use that in my custom task which could work, but I was wondering if there was a better way to do this or if i'm thinking about gradle incorrectly in generalVampire
09/11/2024, 10:16 PM@Option, then you can do exactly the ./gradlew createXSD --file {path-to-xml} you are after. Using -P is just a cheap work-around and bad as they are global and not targeted at a task.RJ Garcia
09/11/2024, 10:21 PMVampire
09/11/2024, 10:22 PMRJ Garcia
09/11/2024, 10:22 PMRJ Garcia
09/11/2024, 10:22 PMabstract class CreateXSD : DefaultTask() {
@TaskAction
fun run() {
println("wow")
val test = object : JavaExec() {}
// exec.classpath(xmlbeans)
// exec.mainClass = "org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd"
// exec.args = listOf("-h")
// exec.exec()
}
}
I tried something like thisVampire
09/11/2024, 10:22 PMRJ Garcia
09/11/2024, 10:23 PMRJ Garcia
09/11/2024, 10:24 PMVampire
09/11/2024, 10:24 PMCreateXSD a subclass of JavaExec or use ExecOperations.javaExec { ... } in your task action, but do not create an anonymous subclass of JavaExec or any other task like thatVampire
09/11/2024, 10:24 PMRJ Garcia
09/11/2024, 10:25 PMRJ Garcia
09/11/2024, 10:28 PMRJ Garcia
09/11/2024, 11:26 PMabstract class CreateXSD
@Inject
constructor(
private val execOps: ExecOperations,
) : DefaultTask() {
@Input
@Option(option = "file-name", description = "XML file to generate xsd from")
lateinit var fileName: String
@TaskAction
fun run() {
execOps.javaexec {
classpath(project.configurations.named("xmlbeans"))
mainClass = "org.apache.xmlbeans.impl.inst2xsd.Inst2Xsd"
args = listOf(
"-design",
"ss",
"-simple-content-types",
"smart",
"-outDir",
"src/main/resources/xml",
"-enumerations",
"never",
xmlPath(fileName),
)
}
val src = project.file(xmlPath("schema0.xsd"))
val dst = project.file(xmlPath(fileName.replace(".xml", ".xsd")))
src.renameTo(dst)
}
private fun xmlPath(name: String) = "src/main/resources/xml/$name"
}
tasks.register<CreateXSD>("createXSD")
Amazing! this code works: ./gradlew createXSD --file-name=example.xml
Thanks for the help!Vampire
09/12/2024, 12:48 AMVampire
09/12/2024, 12:49 AMProperty<String> and never "primitive" types.Vampire
09/12/2024, 12:50 AM