I want to run multiple SOAPUI project xmls in Gradle script - gradle

I want to run multiple soapui projects in Gradle script. The SOAPUI project files are kept is following location:
d:/soapui/projects/path/a.xml, b.xml etc
Will be there any Gradle script that it will enter into the above mentioned location and execute the each project one by one using testrunner.bat

As #RaGe comments you can use the gradle SOAPUI plugin. However if you're looking for a more custom way you can proceed as follows.
You can generate a task on Gradle to execute testrunner to run your SOAPUI projects. Then you can create dynamically one task for each project you've in a directory path, and using .depends you can make that all these dynamic generated tasks are called when you call the specific task.
Your build.gradle could be something like:
// task to execute testrunner
class SoapUITask extends Exec {
String soapUIExecutable = '/SOAPUI_HOME/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// empty task wich has depends to execute the
// ohter tasks
task executeSOAPUI(){
}
// get the path where are your projects
def projectsDir = new File(project.properties['soapuiProjectsPath'])
// create tasks dynamically for each project file
projectsDir.eachFile{ file ->
if(file.name.contains('.xml')){
// create the tasks
task "executeSOAPUI${file.name}"(type: SoapUITask){
println "execute project ${file.name}"
soapUIArgs = ' "' + file.getAbsolutePath() +'"'
}
// make the depends to avoid invoke each task one by one
executeSOAPUI.dependsOn "executeSOAPUI${file.name}"
}
}
To invoke this you can do it using the follow command:
gradle executeSOAPUI -PsoapuiProjectsPath=d:/soapui/projects/path/
Note that -P is used to pass the parameter for projects dir.
Recently I wrote an answer on how to write gradle task to run SOAPUI which can be also util, if you want check more details here.
Hope this helps,

Related

createStartScripts change script name

In an attempt to follow the doc, I added a task like this to my build.gradle file:
task createStartScripts(type: CreateStartScripts) {
applicationName = 'dc-coverage-calculator'
}
I then executed
./gradlew clean installDist
at which point I expected to find a file at build/install/dc-coverage-calculator/bin/dc-coverage-calculator, but no files with dc-coverage-calculator were created anywhere the build folder. Instead, gradle continued to use the default application name, based on the mainClassName.
I also tried removing the hyphens from the app name.
Unfortunately it doesn't work this way. You've added a new task whereas yo need to modify the existing one, which will be done this way:
startScripts {
applicationName = 'dc-coverage-calculator'
}
Grab a demo here.

Wrong order of task execution in gradle 3.3

I want to define methods inside my script file, and use them to define build tasks for each project individual (custom library).
ext.buildDockerImage = { imageName ->
def distDir = "${getProject().getBuildDir()}/docker"
copy {
from "${project.getProjectDir()}/src/docker/"
into distDir
}
println 'Build docker image'
}
In my project build.gradle I have created a task:
apply plugin: "war"
apply plugin: "jacoco"
dependency {
// all dependencies
}
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
buildDockerImage("admin")
}
The problem is that whenever I am running gradle build, this tasks executes also:
$ gradle build -xtest
Build docker image
# rest of build
As you can see , all I want is to create a custom library that will hold methods, used to create tasks for each project. But currently I cannot import those methods without breaking the build. Method buildDockerImage will work only after war file is added to build directory, so this task must be executed on demand only, I don't want to be included in the process all the time.
My questions:
how make my task to only run when I execute task manually
why, when I execute my build, script executes as first?
Your task buildDocker() defines everything in configuration phase. So when you run your gradle build this will always run.
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
buildDockerImage("admin")
}
If you want to run this task as a standalone task, define your stuff in execution phase of the task. something like below
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
doLast{
buildDockerImage("admin")
}
}
Read This article
This might help

I want to run many SOAPUI project xmls using Gradle script, in Linux

I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.
Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,

Reading Gradle build parameters

I have a Gradle project with subprojects that I can issue separate build commands if I don't want to build all the subprojects at once. For example,
parent
subprojectA
subprojectB
subprojectC
I can then issue commands like ./gradlew :subprojectA:assemble :subprojectC:assemble. What I like to do is construct a meaning git tag from each subproject group and version values for those subprojects that are being built, i.e., group and version for only subprojectA and subprojectC in this case. I am thinking of writing a standalone plugin to do this but unsure where / how to get this information at build time. Any suggestions would be much appreciated.
Both group and version (as well as any other project property) is available globally in your build script.
task myTask << {
println group + "-" + version
}
If you are writing a binary plugin you can also access properties off the Project object itself via the property() method.
def group = project.property('group')
Edit
If you want to determine if a particular project is being built you can inspect the TaskExecutionGraph.
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(':subprojectA:assemble')) {
println 'Will build subprojectA'
}
}

How to run gradle script from gradle

How can I run another gradle script from gradle. I have multiple gradle scripts to run tests under <root_project>/test directory. The <root_project>/build.gradle is invoked with the name of the test gradle file to be run. For example
gradle run_test -PtestFile=foobar
This should run <root_project>/test/foobar.gradle (default tasks of it)
What I'm currently doing is invoking project.exec in the run_test task. This works but now I need to pass the project properties from the gradle process running run_test to the one which runs foobar.gradle
How can I do this ? Is there a more gradle-integrated way to run a gradle script from another, passing all the required info to the child gradle script ?
I do something similar where a "construct" task in one gradle hands off to a "perform" task in another gradle file in a dir it has created (called the artefact), and it passes through all the project properties through too.
Here's the relevant code for the handoff:
def gradleTask = "yourTaskToEventuallyRun"
def artefactBuild = project.tasks.create([name: "artefactBuild_$gradleTask", type: GradleBuild])
artefactBuild.buildFile = project.file("${artefactDir}/build.gradle")
artefactBuild.tasks = [gradleTask]
// inject all parameters passed to this build through to artefact build
def artefactProjectProperties = artefactBuild.startParameter.projectProperties
def currentProjectProperties = project.gradle.startParameter.projectProperties
artefactProjectProperties << currentProjectProperties
// you can add more here
// artefactProjectProperties << [someKey: someValue]
artefactBuild.execute()
If you want to specify another gradle script, you can use:
gradle --build-file anotherBuild.gradle taskName
or
gradle -b anotherBuild.gradle taskName

Resources