使用maven将版本号输出到文本文件

编程入门 行业动态 更新时间:2024-10-11 19:16:48
本文介绍了使用maven将版本号输出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想生成一个zip文件,用maven更新应用程序。 zip将托管在服务器上,我使用程序集插件生成zip。但是,我希望maven能够自动生成一个文本文件,该文件存储zip之外的当前版本号。这可能吗?

I want to generate an zip file that will update an application with maven. The zip will be hosted on a server and I am using the assembly plugin to generate the zip. However I would like maven to automatically generate a text file that stores the current version number outside the zip. Is this possible?

编辑:我成功地使用maven Assembly Plugin和两个描述符创建了两个自定义程序集。一个目录单一目标,它只是根据过滤创建一个包含更新版本.txt的文件夹。然后另一个具有单个目标的实际打包zip文件。这似乎非常不优雅,我想它不会正确地与整个更新的文件夹更新maven repo。如果有更好的方法,请告诉我。

I successfully did it using the maven Assembly Plugin and two descriptor to create two custom assemblies. One has a directory-single goal and it just creates a folder with the updated version.txt based on filtering. Then another one with a single goal actually packages the zip file. This seems to be very inelegant and I guess it will not properly up date the maven repo with the whole updated folder. If there is a better way to do this please let me know.

推荐答案

当然。在src / main / resources中的某处创建一个文本文件,将其命名为 version.txt (或其他)

Sure. Create a text file somewhere in src/main/resources, call it version.txt (or whatever)

文件内容:

${project.version}

现在在您的pom.xml中,在构建元素内,放置此块:

now in your pom.xml, inside the build element, put this block:

<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/version.txt</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <excludes> <exclude>**/version.txt</exclude> </excludes> </resource> ... </resources> </build>

每次构建后,文件(你可以在目标/类中找到)将包含当前版本。

after every build, the file (which you can find in target/classes) will contain the current version.

现在,如果你想自动将文件移到其他地方,你可能需要通过 maven-antrun-plugin 。

Now if you want to move the file somewhere else automatically, you are probably going to need to execute an ant task via the maven-antrun-plugin.

Something像这样:

Something like this:

<build> ... <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.4</version> <executions> <execution> <phase>process-resources</phase> <configuration> <tasks> <copy file="${project.build.outputDirectory}/version.txt" toFile="..." overwrite="true" /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

更多推荐

使用maven将版本号输出到文本文件

本文发布于:2023-11-24 05:59:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   版本号   maven

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!