I had converted my maven build project to gradle and now one of the plugins that we use in maven is SQLj plugin. The sqlj plugin has additional configuration that takes the source (.sqlj) files from specific folder path and then compiles them to .java and .ser specific target directory.
I am not sure on configuring this in the gradle build. Can you please help me how to write this configurations in build.gradle file .
I just included the dependency line equivalent to gradle that i got from mvncentral.
// https://mvnrepository.com/artifact/org.codehaus.mojo/sqlj-maven-plugin compile group: 'org.codehaus.mojo', name: 'sqlj-maven-plugin', version: '1.3'
but it just not compiling the new .sqlj from specific file location. I had included the lines like applyplugin: java and maven.
Let me know if any additional thing need to be done.
You could use the source code from the maven plugin as a guide to develop a Gradle task. Here's a simple starting point
class SqljTask extends DefaultTask {
@Input
String encoding
@Input
List<String> additionalArgs = []
@InputDirectory
File sqljDir
@OutputDirectory
File generatedJava
@OutputDirectory
File generatedResources
@TaskAction
void generate() {
project.mkdir generatedJava
project.mkdir generatedResources
project.fileTree(sqljDir).visit { FileVisitDetails fvd ->
if (!fvd.directory) {
List<String> sqljArgs = []
sqljArgs << "-dir=$generatedJava"
sqljArgs << "-d=$generatedResources"
sqljArgs << "-encoding=$encoding"
sqljArgs << "-compile=false"
sqljArgs << fvd.file.absolutePath
sqljArgs.addAll(additionalArgs)
int result = sqlj.tools.Sql.statusMain(sqljArgs as String[])
if (result != 0) throw new RuntimeException("Can't translate $fvd.file ($returnCode)"
}
}
}
}
Usage in a build.gradle
apply plugin: 'java'
task sqlj(type: SqljTask) {
encoding = 'UTF-8'
additionalArgs = ['-status']
sqljDir = file('src/main/sqlj')
generatedJava = file("$buildDir/sqlj/java")
generatedResources = file("$buildDir/sqlj/resources")
}
compileJava.dependsOn sqlj
sourceSets {
main {
java {
srcDir sqlj.generatedJava
}
resources {
srcDir sqlj.generatedResources
}
}
}
Note: This task will only run if a task input / output has changed since the last successful run. So it will be considered UP-TO-DATE
if nothing has changed since the last build
Unfortunately I can't see an officially supported sqlj ant task, someone posted source for an ant task here so one option is to wrap that using Gradle's ant integration
Having a look at the source code for the Maven plugin it seems like most of the logic is in the translate method which calls sqlj.tools.Sqlj.statusMain()
. I notice there's logic in the Maven task which only updates the files which have changed, this could be done in Gradle via an incremental task
Hope this helps you to get started
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.