如何在没有附加执行的情况下调用maven-antrun-plugin目标到maven阶段?

Ant*_*ine 4 maven maven-antrun-plugin

我为我的项目使用maven-antrun-plugin作为init配置文件.但我需要初始化配置文件一次,当我第一次启动我的开发环境,而不是每次我启动jetty:运行.

例如,如果我将阶段附加到进程资源,每次启动jetty时,我的配置文件都会被重置.

所以我配置了这样的antrun:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
        <goals>
            <goal>run</goal>
        </goals>
        <configuration>
            <target name="init_config_files">
                <!-- init files -->
            </target>
        </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果我启动mvn antrun:run,它只会返回给我这个错误:"[INFO]没有定义蚂蚁目标 - 跳过".如果我指定目标,那就是同样的事情:"mvn antrun:run -Dtarget = init_config_files".

Tit*_*ore 7

试试这个:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <configuration>
                        <target>
                            <property name="compile_classpath" refid="maven.compile.classpath" />
                            <echo message="compile classpath: ${compile_classpath}" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

并运行此:

 mvn antrun:run
Run Code Online (Sandbox Code Playgroud)


use*_*755 5

到目前为止,我发现的最佳解决方案:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>go-live</id>
                    <configuration>
                        <target>
                            <!-- go live! -->
                            <exec executable="${basedir}/deploy2server.sh" failonerror="true" dir="${basedir}">
                                <arg value="deploy" />
                                <arg value="${deploy.to.server}" />
                                <arg value="${jetty.port.live}" />
                            </exec>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

并运行此命令:

 mvn antrun:run@go-live
Run Code Online (Sandbox Code Playgroud)

该解决方案避免了目标意外运行,即 它不仅可以通过键入“ mvn antrun:run”来运行,而且在常规的maven运行期间也不会运行。在针对最终分发包完成的所有模块(包括集成)成功执行之后,我在jenkins实例中将其用于qa自动部署。