在Maven构建过程中,如何调用ruby脚本? [英] How do I call a ruby script as part of the Maven build process?

查看:157
本文介绍了在Maven构建过程中,如何调用ruby脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了问题.快速的答案是新配置的执行缺少<id>引起了问题.我将在此留下问题,以防其他人遇到问题.

edit 2: I found the problem. The quick answer is that the lack of an <id> for my newly configured execution was causing the problem. I'll leave the question here in case it helps someone else.

我有一个ruby脚本,可以生成一些jUnit源文件.

I have a ruby script which generates some of my jUnit source files.

我正在尝试使用 exec-maven-插件默认生命周期.这是我为实现此目的而添加到POM中的内容:

I am trying to use the exec-maven-plugin to call this ruby script during the generate-sources phase of the default lifecycle. Here's what I've added to my POM to achieve this:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>ruby</executable>
            <workingDirectory>supporting_files/ruby</workingDirectory>
            <arguments>
                <argument>CreateUnitTests.rb</argument>
            </arguments>
        </configuration>
    </plugin>          

当我在netbeans(clean install)中执行清理并构建主项目"时,但是当我运行具有属性的项目(process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec)时,这似乎起作用:

This seems to be working when I'm doing a "Clean and Build Main Project" in netbeans (clean install), but when I run the project (process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec with the properties:)

exec.classpathScope=runtime
exec.args=-enableassertions -classpath %classpath org.example.MyProject.App
exec.executable=java

运行失败,因为试图将ruby用作exec.executable (正如我在POM中所讲的那样).

The run fails, because it tries to use ruby as the exec.executable (as I tell it to in the POM).

因此,如何临时使用ruby(在运行jUnit测试之前运行ruby supporting_files/ruby/CreateUnitTests.rb),但否则使用java? 正确"的调用方式是什么生成测试源阶段中的脚本?

So, how do I use ruby temporarily (to run ruby supporting_files/ruby/CreateUnitTests.rb before running jUnit tests), but use java otherwise? What's the "proper" way to call scripts during the generate-test-sources phase?

问题似乎不仅仅在于更改正在调用的可执行文件...

我编写了一个快速的Java程序,它仅调用ruby解释器,并将其(命令行文件名)作为命令行参数传递给它:

I wrote a quick java program which just calls the ruby interpreter, passing it (ruby filename) it received as a command line argument:

import java.io.IOException;

public class RunRuby {
    public static void main(String args[]) throws IOException {        
        Runtime run = Runtime.getRuntime();
        run.exec("ruby "+args[0]);
    }
}

这使我避免在POM中更改可执行文件:

which allowed me to avoid changing the executable in my POM:

    <plugin>
        <!-- use ruby to generate some jUnit tests -->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <phase>generate-test-sources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <executable>java</executable>
            <workingDirectory>supporting_files/ruby</workingDirectory>
            <arguments>
                <argument>RunRuby</argument>                    
                <argument>CreateUnitTests.rb</argument>
            </arguments>
        </configuration>
    </plugin>          

丑,我知道.但是无论如何,清理/构建仍然可以按预期工作,但是运行"仍然失败!这是错误消息:

Ugly, I know. But anyway, a clean/build still works as expected, but the "run" is still failing! Here's the error message:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec (default-cli) on project MyProject: Result of cmd.exe /X /C "java -enableassertions -classpath C:\Dropbox\dev\java\MyProject\target\classes;C:\Users\username\.m2\repository\LOTS\OF\JARS org.example.MyProject.App" execution is: '-1'. -> [Help 1]

因此,它又回到了运行java的状态,但仍然失败.我注意到的一件奇怪的事是它正在执行目标org.codehaus.mojo:exec-maven-plugin:1.1.1:exec,即使在POM中我告诉它使用版本1.2 ...

So, it's back to running java, but still failing. One odd thing I'm noticing is that it's executing the goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec even though in the POM I'm telling it to use version 1.2...

推荐答案

缺少<id>导致我的自定义执行成为默认执行.解决方法:

The lack of an <id> caused my customized execution to become the default. Here's the fix:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <!-- use ruby to generate some jUnit tests during generate-test-sources -->
                <id>generate-test-sources</id>
                <configuration>
                    <executable>ruby</executable>
                    <workingDirectory>supporting_files/ruby</workingDirectory>
                    <arguments>
                        <argument>CreateUnitTests.rb</argument>
                    </arguments>
                </configuration>                    
                <phase>generate-test-sources</phase>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
    </plugin>          

这篇关于在Maven构建过程中,如何调用ruby脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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