In Grails 2 I had a gradle task that would do a schema-export.
task extractGrailsDDL(type: org.grails.gradle.plugin.tasks.GrailsTask) {
command "schema-export"
args ddlFileName("Temp") + " --datasouce=operator"
}
org.grails.gradle.plugin.tasks.GrailsTask doesn't exist in the grails.gradle.plugin for Grails 3.
How can I write a Gradle task to run a schema-export and pass parameters?
Related
I have this jenkins stage where I am trying to pass a paramter to a gradle task. It seems like the gradle task does not recieve it
Jenkins
stage('Version Bump') {
steps {
script {
version = (new Date().format('YYYY.ww.')) + env.BUILD_NUMBER
sh './gradlew bumpVersion --no-daemon -Pversion=${version}'
}
}
}
Gradle task
task bumpVersion() {
doFirst {
println version
}
}
The version isnt printed. I have confirmed the value is correct by echo-ing in the jenkins file.
It should work if you use double quotes on the following line:
sh "./gradlew bumpVersion --no-daemon -Pversion=${version}"
Otherwise Groovy doesn’t replace ${version} and then the run shell finds the unset version shell variable and expands it to an empty string (which is then printed by Gradle – making it appear as if nothing was printed at all).
I want to execute a Grails command (grails doc) in the BuildConfig.groovy to do some stuff before the war is packaged:
grails.war.resources = { stagingDir, args ->
// call some ant tasks
}
How can I execute a Grails command in this closure?
I have a gradle task that has a dependsOn and then needs to execute an Ant task called runcukes. Gradle won't call the ant task, however:
ant.importBuild 'build.xml'
task runCukes(dependsOn: restoreSchema) {
runcukes
}
Running gradle with -d shows that gradle doesn't recognize the Ant target runcukes:
Finished executing task ':restoreSchema'
17:28:37.506 [LIFECYCLE] [org.gradle.TaskExecutionLogger] :runCukes
17:28:37.506 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter ]
Starting to execute task ':runCukes'
17:28:37.507 [INFO] [org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter ]
Skipping task ':runCukes' as it has no actions.
17:28:37.507 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
Gradle doesn't recognize that it has to execute the ant target runcukes.
The gradle docs don't show anything as complicated as a task that has a dependsOn that then executes an ant task. (They only show "Hello World" examples as dependencies.)
What do I have to do to get Gradle to execute an Ant task after executing a dependsOn?
Thanks.
Just putting the Ant task name into the configuration block of a task won't execute it. This should do what you want if I understood your requirements correctly:
ant.importBuild 'build.xml'
runcukes.dependsOn restoreSchema
task runCukes(dependsOn: runcukes)
How can I call the Ant target 'jar' from the Gradle build file? I've tried a number of things to no avail. Renaming the 'jar' target in the Ant build file is not an option. I'm in the process of converting an Ant based build system to Gradle and the first required step is to call all the Ant targets from Gradle.
The 'jar' task is a default Gradle task so I'm overwriting/overriding it but I need to call my similarly named Ant target.
Gradle build.gradle file:
// Prevents error "Cannot add task {taskname} as a task with that name already exists"
ant.project.addTarget('clean', new org.apache.tools.ant.Target())
ant.project.addTarget('jar', new org.apache.tools.ant.Target())
ant.project.addTarget('test', new org.apache.tools.ant.Target())
ant.project.addTarget('javadoc', new org.apache.tools.ant.Target())
ant.importBuild 'build.xml'
task jar(overwrite: true) {
println 'jar'
}
task clean(overwrite: true) {
println 'clean'
}
task test(overwrite: true) {
println 'test'
}
and my Ant build.xml:
<target name='jar' description='jar'>
<echo>Called jar task in ant build</echo>
</target>
Running Gradle v1.2
------------------------------------------------------------
Gradle 1.2
------------------------------------------------------------
Gradle build time: Wednesday, September 12, 2012 10:46:02 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_25 (Sun Microsystems Inc. 20.0-b11)
OS: Linux 2.6.37.6 amd64
Gradle only adds a jar task when you apply the Java plugin, which you shouldn't do for the project into which you import the Ant build. I don't think you should ever call ant.project.addTarget from a Gradle build script.
I have large jar task in my ant build file. But I don't want to execute it immediately. I want to add some filesets to the task and only than execute it. I don't want to define the jar task completely in the script. How to do that?
I've tried following approach from the script:
project.addBuildListener(new BuildListener() {
...
void taskStarted(BuildEvent event){
Jar j1 = (Jar)event.getTask();
...//adjustments here
}
});
But it gives: "java.lang.ClassCastException: Cannot cast org.apache.tools.ant.UnknownElement to org.apache.tools.ant.taskdefs.Jar"