[英]how can i set property in build.gradle file to access that property in Java
I am using "sourcemuse/GradleMongoPlugin" gradle plugin.我正在使用“sourcemuse/GradleMongoPlugin”gradle 插件。 It is just for managed instance of Mongo from our gradle build.它仅适用于我们的 gradle 版本中的 Mongo 托管实例。 port 'RANDOM' running on random port.端口“随机”在随机端口上运行。 As per the documentation this port will be available in project.mongo.port.根据文档,此端口将在 project.mongo.port 中可用。 how can I access this "project.mongo.port " in Java classes?如何在 Java 类中访问这个“project.mongo.port”?
build.gradle build.gradle
plugins {
id 'com.sourcemuse.mongo' version '1.0.7'
}
mongo {
port 'RANDOM'
logging 'console'
}
Ref: https://github.com/sourcemuse/GradleMongoPlugin参考: https://github.com/sourcemuse/GradleMongoPlugin
It looks like this may help you: https://stackoverflow.com/a/40869506/12833948看起来这可能会对您有所帮助: https://stackoverflow.com/a/40869506/12833948
As @riccardo.cardin stated, you can autowire IMongodConfig
and it will provide you the port number - mongoConfig.net().getPort()
正如@riccardo.cardin 所说,您可以自动IMongodConfig
,它会为您提供端口号 - mongoConfig.net().getPort()
If that doesn't work, try: System.getProperty("project.mongo.port")
如果这不起作用,请尝试: System.getProperty("project.mongo.port")
If this property is not set, you can try to set it yourself.如果没有设置这个属性,可以尝试自己设置。
In build.gradle
, something like:在build.gradle
中,类似于:
System.setProperty("project.mongo.port", project.mongo.port)
In Java在 Java
System.getProperty("project.mongo.port")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.