用 ant 或 maven 执行我的 groovy 脚本 [英] Execute my groovy script with ant or maven

查看:31
本文介绍了用 ant 或 maven 执行我的 groovy 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几点:

  • 1 个 Java 类
  • 1 个 bat 文件(启动 groovy 脚本)
  • 1 个常规文件

都在同一个文件夹中.

现在我想使用 Maven 或 Ant 来运行 groovy 文件,但我无法让它工作.有没有人可以告诉我如何编写这个 pom.xml 或 build.xml?不想再用bat文件了.

解决方案

使用 Maven,使用 gmaven 插件.来自其文档:

<块引用>

执行本地 Groovy 脚本

<groupId>org.codehaus.gmaven</groupId><artifactId>gmaven-plugin</artifactId><version>1.3</version><执行><执行><phase>生成资源</phase><目标><目标>执行</目标></目标><配置><source>${pom.basedir}/src/main/script/myscript.groovy</source></配置></执行></执行></插件>

并触发指定阶段.

或者,如果您不想将插件绑定到特定阶段,您可以这样配置:

<groupId>org.codehaus.gmaven</groupId><artifactId>gmaven-plugin</artifactId><version>1.3</version><配置><来源>打印嗨"</来源></配置></插件>

然后打电话

mvn groovy:execute

I have the following:

  • 1 java class
  • 1 bat file (starts the groovy script)
  • 1 groovy file

All in the same folder.

Now I want to use Maven or Ant to run the groovy file but I can't get it to work. Is there someone who can show me how to write this pom.xml or build.xml? I don't want to use the bat file anymore.

解决方案

With Maven, use the gmaven plugin. From its documentation:

Execute a Local Groovy Script

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>${pom.basedir}/src/main/script/myscript.groovy</source>
            </configuration>
        </execution>
    </executions>
</plugin>

And trigger the specified phase.

Or, if you don't want to bind the plugin to a particular phase, you could configure it like this:

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <source>
           println "Hi"
        </source>
    </configuration>
</plugin>

And call

mvn groovy:execute

这篇关于用 ant 或 maven 执行我的 groovy 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆