我想在我的Java代码中获得Gradle项目版本.
在Maven中,它可以这样做:
version.properties:
version=${project.version}
Run Code Online (Sandbox Code Playgroud)
解析为:
version=1.0-SNAPSHOT
Run Code Online (Sandbox Code Playgroud)
在jar/war中如果我们将它添加到pom.xml:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
有没有方便的方法在Gradle中实现类似的结果?或者我应该手动编写一个生成带有项目版本的属性文件的任务,然后在我的代码中读取它?