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.
Related
I’m trying to use a Java, Serenity-BDD project with gradle version 4.8+, but the application is not pulling the CLI arguments of -Denvironment and -Dservicebranches. I have these properties as blank values in my local.properties file, and they’re not getting assigned when my app runs.
./gradlew --build-cache build -Dwebdriver.remote.url=${SELENIUM_REMOTE_URL} -Denvironment=${ENVIRONMENT} -Dservicebranches=${SERVICE_BRANCHES} -Dtags=${TAGS}
I have a local.properties file with properties that are being successfully dependency injected into the project (through Serenity-Spring). I'm hoping that these CLI arguments will override these values:
servicebranches=
environment=local
But right now, anything specified in the CLI arguments are not being passed into the project. Either through DI, or through explicitly grabbing the environment variables in the build.gradle, which what I've tried hasn't been working.
Here's a few things which I have tried in the build.gradle:
//task integrationTests() {
// doFirst
// {
// def environment = System.getProperty('environment')
// def servicebranches = System.getProperty('servicebranches')
// }
// tasks.build.execute()
//}
//integrationTests.dependsOn(build)
//build.doFirst{
// systemProperties System.properties
// def environment = System.properties['environment']
// environment = environment //This actually flags with 'Silly assignment'
//}
build.doFirst{
def environment = System.getProperty('environment')
def servicebranches = System.getProperty('servicebranches')
}
The latest one seems to still be missing a step, because the program is still working, but the args are still not getting through. I've even tried -Denvironment=potato, and no errors have come up because I do not have a property or properties file named that.
I've also tried using the -P tag instead of -D tag, but that doesn't seem to be working either.
All I’m trying to do is use build.gradle to use System.getProperty(‘environment’) and System.getProperty(‘servicebranches’) before I use the already created ‘build’ task that comes with Serenity. How would I do this? Do I build a whole new task, where I use these getProperties, and then call the build task? Do I have to specify the assignment of these same named variables in the local.properties file?
-D is for system properties in Gradle. Try with -P instead (https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties)
I know this is a very old question but here's what I did to solve my problem, I got the idea from here: https://github.com/serenity-bdd/serenity-documentation/pull/120/files
Serenity was not pulling the environment from gradle to use EnvironmentSpecificProperties, it kept saying "undefined property for environment 'null" when I removed the default environment. I had to add this to my Gradle file:
test {
systemProperty 'environment', System.properties['environment']
}
I have a KotlinJs only project which I use official kotlin2js gradle to build, and no problems there.
How to setup the output folder, currently, the building of subproject will result in a build which locates inside the subproject folder, how to set it to somewhere else? I tried:
sourceSets {
main {
kotlin.outputDir = new File(‘./out/‘)
}
}
and
sourceSets {
main.kotlin.outputDir = new File(‘./out/’)
}
No luck.
What I want is to no matter how many subprojects are there, the output folder should be in some path like ./build/projectA and ./build/projectB, rather than all in their own folder. How to do this?
Currently, it's done through the task configuration, namely setting its kotlinOptions.outputFile:
compileKotlin2Js.kotlinOptions.outputFile = "out/output.js"
It's briefly mentioned in the tutorial: Getting Started with Kotlin and JavaScript with Gradle
I want to create a zip of my entire code base using a gradle task. I am facing one issue to get the parentDir . I have tried using project , project.rootDir, project.rootProject, projectDir, project, sourceSets*.allSource . I am not getting any correct output. I f I use project alone, it gives me a zip containing only the subproject files. Any pointers?
My task looks like this :
task srcZip(type:Zip){
from project
exclude('**/*//*.iml', '*//*build/', '*//*dist')
exclude('*.zip')
destinationDir file('dist')
}
I build my source code zip from the root with a list of projects like so:
from ('./') {
include ([':proja',':projb',...].collect {
relativePath(project(it).projectDir) + '/'
})
}
It lets me select a sub-set of projects to archive. Don't forget to filter out some temp dirs like build/ and .gradle/.
relativePath(project.rootDir) or relativePath(rootProject.projectDir) should give you access to the top of your multi-project repo.
If you put the task in your root project build.gradle, you can do the following:
task srcZip(type: Zip) {
subprojects.each { project ->
from project.sourceSets.main.allSource
}
exclude('**/*//*.iml', '*//*build/', '*//*dist')
exclude('*.zip')
destinationDir file("dist")
baseName = "sourcecode"
}
This code assumes a few things:
1) All of your subprojects have source sets. If this is not the case, you will have to add a check.
2) There is no source code in the root project. If there is, and you wish to add it, you can add the following line:
from project.sourceSets.main.allSource
project.parent.projectDir worked for me . Initially when I used it, the task wouldn't stop and keep executing without giving any results but I tried in another system, it worked. Thanks for all the reponses but I think this is the perfect solution for me.
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,
I have task which generates picture, so I want to write test for it that compares this picture binary with picture previously generated in the resource folder.
def setupSpec() {
project = ProjectBuilder.builder().build()
generatePicTask = project.tasks.create(SomePlugin.GENERATE_PIC_TASK_NAME, GeneratePicTask)
}
def 'create Picture test'() {
when:
File fileName = new File("Info")
then:
generatePicTask.createPicture(fileName)
expect:
fileName.exists()==true
}
But there is error that
C:\Users\User\AppData\Local\Temp\gradle1393280218367058727projectDir\build\Info.PNG
(The system cannot find the path specified)
The picture is generated in the the action closure in the task generatePicTask.
The project object is dummy project so I don't know even it was executed. How I can fix this?
I see 3 problems with your current approach:
Your test shouldn't rely on the current working directory. Therefore instead of creating a file like this:
File fileName = new File("Info")
use a junit TemporaryFolder rule for example. have a look at
with using e.g. http://garygregory.wordpress.com/2010/01/20/junit-tip-use-rules-to-manage-temporary-files-and-folders/ for more details
It seems GeneratePicTask task not generate the 'build' directory
Ensure that the output directory (the parent folder of the created image exists). You can use gradle annotations e.g. #OuputDirectory to let gradle take care of that. otherwise before generating your image do something like 'fileName.parentfile.mkdirs'
In general the way to go is to split the configuration of your task and task execution:
generatePicTask.setPicture(fileName)
generatePicTask.create() // your #TaskAction annotated method
cheers,
René