Running cucumber on jruby under ant.

121 views
Skip to first unread message

George Dinwiddie

unread,
Feb 9, 2012, 5:47:49 PM2/9/12
to Cukes
I've already left a message on the jruby list about this, but on
Twitter, Aslak suggested here.

I've been struggling here trying to run cucumber on jruby under ant. It
all works so well on the command line, but I'd like to integrate it into
a build script.

After a number of trials, I've come closest with the ant target shown as
'cuke4.xml' in https://gist.github.com/1782945 Unfortunately, that gives
me the Gem::LoadError shown in 'cuke4.output'

So, to investigate where jruby was looking for gems under ant, I wrote
the target in 'gempath.xml' and got the output shown as 'gempath.output'
That kinda stumped me.

Can anyone explain what's going on here? Or, more directly, can anyone
suggest how to run a ruby program using jruby under ant? I seem to be
missing an essential piece of information.

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

David Kowis

unread,
Feb 9, 2012, 5:59:39 PM2/9/12
to cu...@googlegroups.com
On 02/09/2012 04:47 PM, George Dinwiddie wrote:
> I've already left a message on the jruby list about this, but on
> Twitter, Aslak suggested here.
>
> I've been struggling here trying to run cucumber on jruby under ant. It
> all works so well on the command line, but I'd like to integrate it into
> a build script.
>
> After a number of trials, I've come closest with the ant target shown as
> 'cuke4.xml' in https://gist.github.com/1782945 Unfortunately, that gives
> me the Gem::LoadError shown in 'cuke4.output'
>
> So, to investigate where jruby was looking for gems under ant, I wrote
> the target in 'gempath.xml' and got the output shown as 'gempath.output'
> That kinda stumped me.
>
> Can anyone explain what's going on here? Or, more directly, can anyone
> suggest how to run a ruby program using jruby under ant? I seem to be
> missing an essential piece of information.

So you're trying to tell Jruby where to find the Gems that you've got
installed?

set the environment variable GEM_PATH, jruby will honor that to look for
gems in wherever that path is.

I know this isn't ant, but there are ant calls in this Maven project
that's referencing gems, perhaps it'll help you some:
https://github.com/dkowis/Cucumber-JVM-Ruby-Example


it uses ant to call jruby to install bundler, and then call bundle
install using a Gemfile in the root of the project.

I think it should cover the things you're wanting to do, unless I'm not
understanding.

David

signature.asc

George Dinwiddie

unread,
Feb 10, 2012, 11:42:30 AM2/10/12
to cu...@googlegroups.com
Thanks, David,

On 2/9/12 5:59 PM, David Kowis wrote:
> On 02/09/2012 04:47 PM, George Dinwiddie wrote:
>> I've already left a message on the jruby list about this, but on
>> Twitter, Aslak suggested here.
>>
>> I've been struggling here trying to run cucumber on jruby under ant. It
>> all works so well on the command line, but I'd like to integrate it into
>> a build script.
>>
>> After a number of trials, I've come closest with the ant target shown as
>> 'cuke4.xml' in https://gist.github.com/1782945 Unfortunately, that gives
>> me the Gem::LoadError shown in 'cuke4.output'
>>
>> So, to investigate where jruby was looking for gems under ant, I wrote
>> the target in 'gempath.xml' and got the output shown as 'gempath.output'
>> That kinda stumped me.
>>
>> Can anyone explain what's going on here? Or, more directly, can anyone
>> suggest how to run a ruby program using jruby under ant? I seem to be
>> missing an essential piece of information.
>
> So you're trying to tell Jruby where to find the Gems that you've got
> installed?
>
> set the environment variable GEM_PATH, jruby will honor that to look for
> gems in wherever that path is.

I never figured out how to set this from Ant such that jruby would find
it. And sanitizes the environment for processes it calls--perhaps a bit
too much.

> I know this isn't ant, but there are ant calls in this Maven project
> that's referencing gems, perhaps it'll help you some:
> https://github.com/dkowis/Cucumber-JVM-Ruby-Example
>
>
> it uses ant to call jruby to install bundler, and then call bundle
> install using a Gemfile in the root of the project.
>
> I think it should cover the things you're wanting to do, unless I'm not
> understanding.

That seems complicated for my needs. I don't really want the complexity
of bundler and re-installing gems in the build file just to run some
cucumber tests on a java project.

I went back to my simple beginnings, though, and after stumbling across
the way to read the OS environment values within ant (I had thought they
were automatically available, but either I misremembered or that changed
at some point.), I ended up with the following:

<target name="cucumber" description="Run the cucumber tests">
<property environment="env" />
<exec executable="cucumber" >
<env key="PATH" path="${env.PATH}:${jruby.home}/bin" />
<env key="CLASSPATH" file="${jruby.home}/lib/jruby.jar" />
</exec>
</target>

which works fine. I like it; it's fairly simple and tidy.

George Dinwiddie

unread,
Feb 10, 2012, 12:08:55 PM2/10/12
to cu...@googlegroups.com

Except it doesn't work under Eclipse, which also messes with the PATH. I
modified it to the following:

<target name="cucumber" description="Run the cucumber tests">
<property environment="env" />

<exec executable="${jruby.home}/bin/cucumber" >
<env key="PATH" path="${jruby.home}/bin:${env.PATH}" />


<env key="CLASSPATH" file="${jruby.home}/lib/jruby.jar" />
</exec>
</target>

-- George

David Kowis

unread,
Feb 10, 2012, 12:09:43 PM2/10/12
to cu...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/10/2012 10:42 AM, George Dinwiddie wrote:
> Thanks, David,
>

>> set the environment variable GEM_PATH, jruby will honor that to
>> look for gems in wherever that path is.
>
> I never figured out how to set this from Ant such that jruby would
> find it. And sanitizes the environment for processes it
> calls--perhaps a bit too much.
>

> That seems complicated for my needs. I don't really want the
> complexity of bundler and re-installing gems in the build file just
> to run some cucumber tests on a java project.

Yeah, I didn't intend for you to use bundler and all that, just as an
example that works :)

>
> I went back to my simple beginnings, though, and after stumbling
> across the way to read the OS environment values within ant (I had
> thought they were automatically available, but either I
> misremembered or that changed at some point.), I ended up with the
> following:
>
> <target name="cucumber" description="Run the cucumber tests">
> <property environment="env" /> <exec executable="cucumber" > <env
> key="PATH" path="${env.PATH}:${jruby.home}/bin" /> <env
> key="CLASSPATH" file="${jruby.home}/lib/jruby.jar" /> </exec>
> </target>
>
> which works fine. I like it; it's fairly simple and tidy.

Works for me :)

David
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQGcBAEBAgAGBQJPNU9WAAoJEMnf+vRw63Ob404MAJWMf0M+EChown+dmPRuuUm9
cQnqMFRCupmYJ6YCyBi6onIb75GHKLdiHBjWZE7lIK0n6vpkaGNVaRDjpcZIyHpq
iE/4u/Pl/JVSfVqvrSxEKTPf4EwRjTCtadh1eLOD1LLi63ME1gvhqr58af7k//n5
lkMzPfrEoTQkT3a4cDsXLqOpCahshNvaoks/EMvYbZ0xqNzuuSgbF6aZvbhvj+5Y
mmYTypQBeQZJEAxPmXTuTjo7wlgtSR4hQ058X3VEQ5dG+jXn/ybzzy7NWHkMwsQN
oo1tLDDn2td+Jx1QwueYM0sjtNlIFMUWOWrx9aVBswk8VKTTNDUNlAxA2AGF+auw
ca9FsjnTOkZDoWapfaDpoYYuSsk0JB75ahmqJS7ILt3YJQCFCqoSa2tzkVX3sqST
ud8fD5daFrdWU7Ph5fYW9Q6oPqMowQZFAl0ke6C0c+Vk4cef1NQZ+Bc24pBlRj/G
jwfSYXJJojw7/kx6/l/hVFWIz4KZcTsYUrFekoYBPw==
=dQol
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages