maven exec插件:可以将命令输出写入文件
我想使用maven exec插件来将命令输出写入文件, 我只能通过运行插件正在调用的shell命令来做到这一点。
这是shell脚本:
git rev-parse --abbrev-ref HEAD > branch.txt
这是我的pom.xml:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>5.3.21</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>gitbranch.sh</executable>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</plugin>
试图以命令而不使用脚本时,我无法写入文件:
<configuration>
<executable>git</executable>
<outputFile>branching.txt</outputFile>
<arguments>
<argument>rev-parse</argument>
<argument>--abbrev-ref</argument>
<argument>HEAD</argument>
</arguments>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
我还尝试运行 echo“ sosings”&gt; file.txt
使用此插件,但没有任何内容在文件中写入任何内容。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不会直接回答您的问题,但我使用做您想做的同样的事情。我有:
在我的
build/plugins
我的pom.xml
的部分。运行此操作时,我将获取名为git.properties
在我的target/class/class
目录中生成的:
文件 将有关GIT环境的信息作为启动字符串的一部分,或者对其做您想做的事情。再次
This may not directly answer your question but I use maven git commit id plugin to do the same thing you want to do. I have:
in my
build/plugins
section of mypom.xml
. When I run this I get the file namedgit.properties
generated in mytarget/classes
directory that contains:Then, in my code base I have:
This allows me to print out information about the git environment as part of a startup string or do what you want with it. Again