I'm using IntelliJ 2024.3.3 Ultimate edition; more precisely I'm doing remote development. I have an application where the test execution for local environment requires a custom system property to be set. The project is using gradle and the gradle.file cannot be changed!
I tried literally everything for IntelliJ to set me a system property from JAVA_OPTS to JAVA_OPTIONS till VM options, System.getProperty("...") returns null every single time.
I tried adding JAVA_OPTS="-Dmy.awesome.property=plswork" to the environment variables in the run configuration for the integrationTest gradle task, to no avail.
I tried the same with JAVA_OPTIONS but the outcome was the same. I tried adding "-Dmy.awesome.property=plswork" to VM options just to come back to the same conclusion.
var systemProperties = System.getProperties();
if (!systemProperties.containsKey(OVERRIDE)) {
// always the case...
} else {
// I actually want this!
}
Override is:
private static final String OVERRIDE = "my.awesome.property";
Running the Gradle task outside IntelliJ works perfectly fine and obviously without the override it also works just fine. How on earth one can configure a system property for a single very specific Gradle task (I only need this property for this very specific integrationTest task, none else!) while using IntelliJ?
What am I missing? I already went through some similar questions and tested all applicable solutions, to no avail. Modifying the integration.gradle file might work, but I cannot do that as that comes from a different repo through submodules and an update will affect loads of other projects (not to mention it's not my team who manages that).
I'm using IntelliJ 2024.3.3 Ultimate edition; more precisely I'm doing remote development. I have an application where the test execution for local environment requires a custom system property to be set. The project is using gradle and the gradle.file cannot be changed!
I tried literally everything for IntelliJ to set me a system property from JAVA_OPTS to JAVA_OPTIONS till VM options, System.getProperty("...") returns null every single time.
I tried adding JAVA_OPTS="-Dmy.awesome.property=plswork" to the environment variables in the run configuration for the integrationTest gradle task, to no avail.
I tried the same with JAVA_OPTIONS but the outcome was the same. I tried adding "-Dmy.awesome.property=plswork" to VM options just to come back to the same conclusion.
var systemProperties = System.getProperties();
if (!systemProperties.containsKey(OVERRIDE)) {
// always the case...
} else {
// I actually want this!
}
Override is:
private static final String OVERRIDE = "my.awesome.property";
Running the Gradle task outside IntelliJ works perfectly fine and obviously without the override it also works just fine. How on earth one can configure a system property for a single very specific Gradle task (I only need this property for this very specific integrationTest task, none else!) while using IntelliJ?
What am I missing? I already went through some similar questions and tested all applicable solutions, to no avail. Modifying the integration.gradle file might work, but I cannot do that as that comes from a different repo through submodules and an update will affect loads of other projects (not to mention it's not my team who manages that).
Share Improve this question edited Mar 27 at 23:50 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 13 at 11:12 Display nameDisplay name 6901 gold badge7 silver badges19 bronze badges1 Answer
Reset to default 0If you can write a file somewhere you can configure the test using an init script.
Write an init script to configure your test task using a hook:
// /somewhere/over/the/rainbow/init.gradle
afterProject { project ->
if (rootProject.name != "buildSrc") // Init scripts don't work with buildSrc
project.tasks.withType(Test).configureEach {
systemProperty("OVERRIDE", "my.awesome.init.script")
}
}
Then pass it at the command line:
$ ./gradlew test --init-script /somewhere/over/the/rainbow/init.gradle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744704836a4588994.html
评论列表(0条)