admin管理员组文章数量:1391943
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
本文标签: javaUnable to set system properties from IntelliJ run configuration for a gradle taskStack Overflow
版权声明:本文标题:java - Unable to set system properties from IntelliJ run configuration for a gradle task - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744704835a2620780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论