Passing system properties from command line to my app via gradle
systemProperties
needs to go inside javaexec
:
task cucumber(type: JavaExec) {
dependsOn assemble, compileTestJava
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-f', 'pretty', '--glue', 'steps', 'src/test/resources']
systemProperties = System.getProperties()
}
PS: Unless you absolutely need to combine multiple concerns into a single task, always prefer task types (e.g. JavaExec
) over methods (e.g. javaexec
).
How to set system property using gradle?
The system property set in gradle.properties
will be available only in JVM where Gradle is running.
From gradle-appengine-plugin documentation:
appengineRun: Starts a local development server running your project
code.jvmFlags: The JVM flags to pass on to the local development server.
If you need your system properties to be available in app engine, which is separate JVM, you should use jvmFlags
property.
Explicitly:
appengine {
jvmFlags = ['-DfirstName=Marko', '-DlastName=Vuksanovic']
}
With gradle.properties:
appengine {
jvmFlags = ['-DfirstName=$firstName', '-DlastName=$lastName']
}
How can I add a Java system property during JUnit Test Execution
Sorry to answer my own question. Just stumbled upon the solution here:
test {
systemProperties = System.properties
}
Is it possible to configure system properties dynamically for a Gradle test task?
I have found a way to make this work. The trick is to set the system property on the test task sometime later, when the property is certain to be available. The simplest way to make that happen seems to be via a dummy dependency:
project.task("integrationtestconfig") << {
outputs.upToDateWhen { false }
project.tasks.integrationtest.systemProperty("integration.test.server.wait", project.gwt.getServerWait())
}
project.task("integrationtest", type: org.gradle.api.tasks.testing.Test,
dependsOn: project.tasks.buildApplication, project.tasks.integrationtestconfig)
...
It's not the elegant solution I was hoping for, but it does work and it's not too difficult to follow.
Gradle systemProperty in custom task not setting Spring Profile
@DisabledIfEnvironmentVariable
annotation requires environment variable to be set. Try to set environment variable instead of system property in Your task:
task unit(type: Test) {
useJUnitPlatform()
environment "SPRING_PROFILES_ACTIVE", "unit"
}
Related Topics
How to Represent a Range in Java
Printing Message on Console Without Using Main() Method
Pros and Cons of Package Private Classes in Java
How Are Constructors Called During Serialization and Deserialization
File Upload Using Selenium Webdriver and Java Robot Class
How to Check the Type of a Value from a JSONobject
The Value for the Usebean Class Attribute ... Is Invalid
Accessing a File Inside a .Jar File
Java String Concatenation with + Operator
How to Run All Tests Belonging to a Certain Category in Junit 4
Strange Behavior of Class.Getresource() and Classloader.Getresource() in Executable Jar
404 Error Redirect in Spring with Java Config
Making Spring-Data-Mongodb Multi-Tenant
Why Is Constructor of Super Class Invoked When We Declare the Object of Sub Class? (Java)