maven-release-plugin在提交之前自动运行一个脚本
我想知道是否有可能使maven-release-plugin
在提交新标签之前运行特定的脚本。
原因是,我有一个Dockerfile,我想用我的项目的新版本更新。
你可以使用release:perform
的completionGoals
选项release:perform
目标:
目标在完成准备步骤后运行,转换回下一个开发版本之后,但在提交之前。 空间分隔。
并让maven-exec-plugin
通过它的exec
目标来执行你的脚本。
一个简单的例子如下:
<build> <plugins> .... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.5.0</version> <configuration> <!-- example: executing an hello message on Windows console --> <executable>cmd</executable> <arguments> <argument>/C</argument> <argument>echo</argument> <argument>hello</argument> </arguments> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> <configuration> ... <completionGoals>exec:exec</completionGoals> </configuration> </plugin> </plugins> </build>
注意上面的completionGoals
的价值,我们实际上告诉Maven也执行exec
插件和它的exec
目标,然后它将接受我们的全局configuration。
在你的情况下,上面的execconfiguration会是这样的:
<configuration> <executable>your-script</executable> <!-- optional --> <workingDirectory>/tmp</workingDirectory> <arguments> <argument>-X</argument> <argument>myproject:dist</argument> </arguments> </configuration>
根据发布准备的确切点,您也可以考虑使用其他preparationGoals
configuration选项:
作为准备步骤的一部分,在转换之后但在提交之前运行。 空间分隔。
其中有一个默认值clean verify
,在这种情况下,然后是clean verify exec:exec
。
你可以像@dimatteo说的那样做,但我鼓励你不要这样做,因为docker工人和maven工具是两个不同目的的工具。
如果你想自动执行这两个动作,可以使用一些东西(shell,jenkins,…)来启动maven,然后docker。