0

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?

as.beaulieu
  • 464
  • 1
  • 10
  • 26

2 Answers2

1

-D is for system properties in Gradle. Try with -P instead (https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties)

John Smart
  • 969
  • 1
  • 5
  • 5
0

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']
}