Gradle can't execute an Ant target - ant

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)

Related

Gradle task to do Grals 3 schema-export

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?

Grails 3.0.9 gradle new task with custom environment

I'm trying to create a new task in build.gradle for running "check" with a custom environment called "integration".
I've tried several things and I've been able to run the check task from my custom task but I can't find the way to set the environment in int.
This is the task that I have right now in build.gradle. The comments are for things that I've tried but all fail because the property doesn't exist.
I've also tried setting the task as type:GrailsTask, but with no luck
task integrationCheck(){
dependsOn "check"
//env = "integration"
//grailsEnv = "integration"
//tasks.check.env = "integration"
//check.env = "integration"
//project.property("grailsEnv")
}
Edit: per #vinay-prajapati suggestion
Have tried with this:
task integrationCheck << {
systemProperty 'spring.profiles.active', 'integration'
}
And it gives this error:
Execution failed for task ':integrationCheck'.
> Could not find method systemProperty() for arguments [spring.profiles.active, integration] on root project 'my-project'

Jenkins Post Build Task does not work when job is aborted

I have an issue about Post Build Task after an job abort (manual or timeout): the abort generates a java.lang.InterruptedException which seems to be normal. But as Jenkins java machine is stucked how can you run a post task script? I can't.
here is the java exception:
#174 aborted
java.lang.InterruptedException
at java.lang.ProcessImpl.waitFor(Native Method)
at hudson.Proc$LocalProc.join(Proc.java:319)
at hudson.Launcher$ProcStarter.join(Launcher.java:345)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:82)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at
hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:710)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:480)
at hudson.model.Run.run(Run.java:1438)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)
Here is my jenkins output:
Build was aborted
Aborted by admin
Performing Post build task...
Match found for :. : True
Logical operation result is TRUE
Running script : dir
[workspace] $ cmd /c call C:\Users\xxxx\AppData\Local
\Temp\2hudson5872719646331136420.bat
Exception when executing the batch command : null
Build step 'Post build task' marked build as failure
Finished: ABORTED
I ran a bat script on the server that copied all hudson****.bat from the folder (which is cleaned after the job) during the job execution/aborting so I've been able to run cmd /c call C:\xxxx\hudson5872719646331136420.bat manually from the windows run, it worked fine.
thanks for your help

Call Ant jar target from Gradle build file

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.

How to adjust and execute Ant task from BeanShell 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"

Resources