英文:
how can i set property in build.gradle file to access that property in Java
问题
I am using "sourcemuse/GradleMongoPlugin" gradle plugin. It is just for managed instance of Mongo from our gradle build.
port 'RANDOM' running on random port. As per the documentation this port will be available in project.mongo.port.
how can I access this "project.mongo.port" in Java classes?
build.gradle
plugins {
id 'com.sourcemuse.mongo' version '1.0.7'
}
mongo {
port 'RANDOM'
logging 'console'
}
Ref: https://github.com/sourcemuse/GradleMongoPlugin
英文:
I am using "sourcemuse/GradleMongoPlugin" gradle plugin. It is just for managed instance of Mongo from our gradle build.
port 'RANDOM' running on random port. As per the documentation this port will be available in project.mongo.port.
how can I access this "project.mongo.port " in Java classes ?
build.gradle
plugins {
id 'com.sourcemuse.mongo' version '1.0.7'
}
mongo {
port 'RANDOM'
logging 'console'
}
答案1
得分: 1
"It looks like this may help you: 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()
If that doesn't work, try: System.getProperty("project.mongo.port")
If this property is not set, you can try to set it yourself.
In build.gradle
, something like:
System.setProperty("project.mongo.port", project.mongo.port)
In Java
System.getProperty("project.mongo.port")
英文:
It looks like this may help you: 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()
If that doesn't work, try: System.getProperty("project.mongo.port")
If this property is not set, you can try to set it yourself.
In build.gradle
, something like:
System.setProperty("project.mongo.port", project.mongo.port)
In Java
System.getProperty("project.mongo.port")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论