简体   繁体   English

如何从Scala Play获取依赖版本! 框架构建文件

[英]How to get dependency version from Scala Play! framework build file

I'm using Play! 我正在使用Play! framework to build my application. 构建我的应用程序的框架。 I have such dependency: 我有这样的依赖:

"com.coolDependency" % "superLib" % "0.3.89"

Somewhere in the code, I'd like to get the version of the superLib. 在代码中的某处,我想获取superLib的版本。 But is it possible to do with Play! 但是玩Play可能吗! tools? 工具? My code is dependent from the version of superLib. 我的代码取决于superLib的版本。 For example: 例如:

val coolVal = "importantThingsHere - 0.3.89"

As the version of superLib is changing quite often, I don't like to change the version of it in the build file and in the code. 由于superLib的版本经常更改,因此我不希望在构建文件和代码中更改其版本。 I could put it in the configuration file and read it from there both in build file and in the code, as well as parse the build.scala file in the code and get the version by extracting it from the build file. 我可以将其放在配置文件中,然后从构建文件和代码中读取该文件,以及解析代码中的build.scala文件并通过从构建文件中提取它来获取版本。

Is there any prettier way of doing this? 有没有更漂亮的方法可以做到这一点? I was trying to play around with play.api.Play, but didn't succeeded. 我试图玩play.api.Play,但没有成功。

Currently, I decided to get maven property file from classloader. 目前,我决定从类加载器中获取maven属性文件。

Thanks in advance! 提前致谢!

如果有人尝试做类似的事情:

val properties = new Properties properties.load(Play.application.resourceAsStream("/META-INF/maven/com.coolDependency/superLib/pom.properties").get) properties.get("version")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM