如何通过Intellij Idea将环境变量传递到Gradle测试任务?
春季2.4.5。
Gradle 6.5.1。
application.properties
在测试文件夹下的PostgreSQL连接字符串中有占位符。
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://${PG_HOST}:${PG_PORT}/
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.max-size=5
为了使测试正常工作,我将以下行添加到build.gradle
文件:
test {
...
systemProperty "PG_HOST", System.getProperty("PG_HOST")
systemProperty "PG_PORT", System.getProperty("PG_PORT")
...
}
因此,我可以通过命令行进行测试:
./gradlew test -DPG_HOST=localhost -DPG_PORT=5432
然后,我决定运行Gradle Test通过Intellij Idea Gradle Pane进行任务。
我添加了
pg_host
& pg_port
作为环境变量。
,但是ENV变量未传递给Gradle Test Config,而测试失败。
对此有什么想法吗?
Spring 2.4.5.
Gradle 6.5.1.
There are placeholders in PostgreSQL connection string in application.properties
file under test folder.
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://${PG_HOST}:${PG_PORT}/
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.max-size=5
In order to make tests working, I've added the following lines to build.gradle
file:
test {
...
systemProperty "PG_HOST", System.getProperty("PG_HOST")
systemProperty "PG_PORT", System.getProperty("PG_PORT")
...
}
So, I'm able to tun test via command line as follows:
./gradlew test -DPG_HOST=localhost -DPG_PORT=5432
Then, I decided to run Gradle test task via IntelliJ Idea Gradle pane.
I've added PG_HOST
& PG_PORT
as environment variables.
But the env variables are not being passed to Gradle test config, and test fail.
Any ideas on this matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论