我想从 gradle 设置 vm 参数:
例如,要启动 Java 应用程序,我会这样做:
-Dspring.profiles.active=dev
我想做同样的事情,但不是来自命令行,而是来自 gradle
我尝试了不同的变体,但它不起作用:
System.properties['spring.profiles.active'] = "dev"
System.setProperty('spring.profiles.active',"dev")
如何从 Gradle 设置 System.properties
?我需要在 tomcat 上作为 .war
文件运行 spring 应用程序,我不能将它作为系统变量传递
69.6 Set the active Spring profiles
The Spring Environment has an API for this, but normally you would set a System property (spring.profiles.active) or an OS environment variable (SPRING_PROFILES_ACTIVE). E.g. launch your application with a -D argument (remember to put it before the main class or jar archive):
$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
In Spring Boot you can also set the active profile in application.properties, e.g.
spring.profiles.active=production
A value set this way is replaced by the System property or environment variable setting, but not by the SpringApplicationBuilder.profiles() method. Thus the latter Java API can be used to augment the profiles without changing the defaults.
最佳答案
这个有效:
bootRun {
systemProperty 'spring.profiles.active', 'dev'
}
我在这里找到了答案: https://github.com/spring-projects/spring-boot/pull/592
关于java - 如何将 groovy (gradle) 内部的 vm 参数设置为 Tomcat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41610100/