Forum: JRuby Re: Maven dependency management

B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-01-23 11:30
(Received via mailing list)
so finally I got around and did my first gem with native-extension which
basically installs the declared jar dependencies. see

https://github.com/mkristian/ruby-maven-demo/tree/...

the simple gem has jar dependencies but does not vendor them. on install
of
the gem those jars will be installed in the local repository and then
required by the jar-dependencies gem (which just keeps track of version
conflicts)

the Rakefile setup task does that installing and it need ruby-maven
which
comes with jbundler already. ruby-maven is not a runtime dependency
since
is has nothing to do during runtime. it is only needed on install time
;)

the jar-dependencies is not on rubygems.org yet and I want to wait for
some
more feedbaclk on all this.

- christian
790f4b24adb7b0124fe901413945c36e?d=identicon&s=25 Michael Guymon (Guest)
on 2014-01-23 17:43
(Received via mailing list)
Thought I would poke my head in on this, this is how the Naether[1] gem
(a Ruby wrapper for Aether) has been running for a long time. When the
Gem is installed it bootstraps itself by downloading the jar
dependencies for Maven's Aether, starts up Aether,  installs the jars
into the local maven repo. Then when the naether starts, it
automatically loads the Aether jars into the classpath.

[1] https://github.com/mguymon/naether
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-01-23 17:48
(Received via mailing list)
thanx Michael. indeed I used solr-sail as blueprint today ;)

-regards,
christian
86f94d4973859c66e26f410c7ccaa7f1?d=identicon&s=25 Patrick Ritchie (Guest)
on 2014-01-23 17:54
(Received via mailing list)
There's also:

https://github.com/homeaway/pom-loader

It reads from your pom.xml directly and puts all the jars it finds on
the class path.

From: christian <m.kristian@web.de<mailto:m.kristian@web.de>>
Reply-To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Date: Thursday, January 23, 2014 10:46 AM
To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Cc: Tortonesi Mauro
<mauro.tortonesi@unife.it<mailto:mauro.tortonesi@unife.it>>
Subject: Re: [jruby-user] Maven dependency management

thanx Michael. indeed I used solr-sail as blueprint today ;)

-regards,
christian


On Thu, Jan 23, 2014 at 4:41 PM, Michael Guymon
<michael.guymon@gmail.com<mailto:michael.guymon@gmail.com>> wrote:
Thought I would poke my head in on this, this is how the Naether[1] gem
(a Ruby wrapper for Aether) has been running for a long time. When the
Gem is installed it bootstraps itself by downloading the jar
dependencies for Maven's Aether, starts up Aether,  installs the jars
into the local maven repo. Then when the naether starts, it
automatically loads the Aether jars into the classpath.

[1] https://github.com/mguymon/naether


On 1/23/14, 5:28 AM, christian wrote:
so finally I got around and did my first gem with native-extension which
basically installs the declared jar dependencies. see

https://github.com/mkristian/ruby-maven-demo/tree/...

the simple gem has jar dependencies but does not vendor them. on install
of the gem those jars will be installed in the local repository and then
required by the jar-dependencies gem (which just keeps track of version
conflicts)

the Rakefile setup task does that installing and it need ruby-maven
which comes with jbundler already. ruby-maven is not a runtime
dependency since is has nothing to do during runtime. it is only needed
on install time ;)

the jar-dependencies is not on rubygems.org<http://rubygems.org> yet and
I want to wait for some more feedbaclk on all this.

- christian
790f4b24adb7b0124fe901413945c36e?d=identicon&s=25 Michael Guymon (Guest)
on 2014-01-23 21:33
(Received via mailing list)
*oogles your code* You may find it useful to use Naether for pom-loader.
That way you can resolve the jar dependencies of a pom without having
Maven installed, then the gem will work out of the can. Naether uses the
same Aether lib as Maven, so it will (should?) get the same jar results.
86f94d4973859c66e26f410c7ccaa7f1?d=identicon&s=25 Patrick Ritchie (Guest)
on 2014-01-23 22:11
(Received via mailing list)
Indeed, that would be much cleaner! (and probably faster)

From: Michael Guymon
<michael.guymon@gmail.com<mailto:michael.guymon@gmail.com>>
Reply-To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Date: Thursday, January 23, 2014 2:30 PM
To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Cc: Tortonesi Mauro
<mauro.tortonesi@unife.it<mailto:mauro.tortonesi@unife.it>>
Subject: Re: [jruby-user] Maven dependency management


*oogles your code* You may find it useful to use Naether for pom-loader.
That way you can resolve the jar dependencies of a pom without having
Maven installed, then the gem will work out of the can. Naether uses the
same Aether lib as Maven, so it will (should?) get the same jar results.

On 1/23/14, 11:52 AM, Patrick Ritchie wrote:
There's also:

https://github.com/homeaway/pom-loader

It reads from your pom.xml directly and puts all the jars it finds on
the class path.

From: christian <m.kristian@web.de<mailto:m.kristian@web.de>>
Reply-To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Date: Thursday, January 23, 2014 10:46 AM
To: "user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>"
<user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>>
Cc: Tortonesi Mauro
<mauro.tortonesi@unife.it<mailto:mauro.tortonesi@unife.it>>
Subject: Re: [jruby-user] Maven dependency management

thanx Michael. indeed I used solr-sail as blueprint today ;)

-regards,
christian


On Thu, Jan 23, 2014 at 4:41 PM, Michael Guymon
<michael.guymon@gmail.com<mailto:michael.guymon@gmail.com>> wrote:
Thought I would poke my head in on this, this is how the Naether[1] gem
(a Ruby wrapper for Aether) has been running for a long time. When the
Gem is installed it bootstraps itself by downloading the jar
dependencies for Maven's Aether, starts up Aether,  installs the jars
into the local maven repo. Then when the naether starts, it
automatically loads the Aether jars into the classpath.

[1] https://github.com/mguymon/naether


On 1/23/14, 5:28 AM, christian wrote:
so finally I got around and did my first gem with native-extension which
basically installs the declared jar dependencies. see

https://github.com/mkristian/ruby-maven-demo/tree/...

the simple gem has jar dependencies but does not vendor them. on install
of the gem those jars will be installed in the local repository and then
required by the jar-dependencies gem (which just keeps track of version
conflicts)

the Rakefile setup task does that installing and it need ruby-maven
which comes with jbundler already. ruby-maven is not a runtime
dependency since is has nothing to do during runtime. it is only needed
on install time ;)

the jar-dependencies is not on rubygems.org<http://rubygems.org> yet and
I want to wait for some more feedbaclk on all this.

- christian
54147c1a1223b425d4f4f7947c9bba46?d=identicon&s=25 Ariel Valentin (Guest)
on 2014-01-24 03:10
(Received via mailing list)
Do these options include allowing on to use plugins such as
copy-dependencies?

Thanks,
Ariel
---
Sent from my mobile device. Please excuse any errors.
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-01-24 10:20
(Received via mailing list)
Ariel, you can use dependency copy in the Mavenfile which is a full ruby
DSL for maven:
https://github.com/jruby/jruby/blob/master/lib/pom.rb#L43
and execute it within the Rakefile with maven.package - if you add it to
the package phase.

- christian
790f4b24adb7b0124fe901413945c36e?d=identicon&s=25 Michael Guymon (Guest)
on 2014-01-24 18:14
(Received via mailing list)
The LockJar[1] gem is built on top of Naether to provide easy access of
jars to ruby. To download and get the paths of a jar and all its
dependencies, you can do the following:

    paths = LockJar.list( :resolve => true, :local_paths => true ) do
       jar
'org.eclipse.jetty:example-jetty-embedded:jar:8.1.2.v20120308'
    end


1 https://github.com/mguymon/lock_jar
54147c1a1223b425d4f4f7947c9bba46?d=identicon&s=25 Ariel Valentin (Guest)
on 2014-01-25 06:05
(Received via mailing list)
Patrick and Michael,

pom-loader and LockJar both look interesting, thanks for sharing it. I
have
questions for both or you...

When I add gems that also require gems does it make sense to also
declare
those dependencies in the project pom?

If I want to bundle jars in a local directory for my application, how
difficult is it to use copy-dependencies?

What do either projects do in cases where there are conflicts? e.g.
nokogiri including bundled xerces jar



Ariel Valentin
e-mail: ariel@arielvalentin.com
website: http://blog.arielvalentin.com
skype: ariel.s.valentin
twitter: arielvalentin
linkedin: http://www.linkedin.com/profile/view?id=8996534
---------------------------------------
*simplicity *communication
*feedback *courage *respect


On Fri, Jan 24, 2014 at 12:12 PM, Michael Guymon
790f4b24adb7b0124fe901413945c36e?d=identicon&s=25 Michael Guymon (Guest)
on 2014-01-25 07:35
(Received via mailing list)
Comments below . . .

On 1/25/14, 12:02 AM, Ariel Valentin wrote:
> Patrick and Michael,
>
> pom-loader and LockJar both look interesting, thanks for sharing it. I
> have questions for both or you...
>
> When I add gems that also require gems does it make sense to also
> declare those dependencies in the project pom?
>
I have never used gem deps in a Pom, Christian would know.
> If I want to bundle jars in a local directory for my application, how
> difficult is it to use copy-dependencies?
>
LockJar only uses the Aether framework for jar dependency graphing. It
does not have access to other parts of Maven, such compile, package,
etc. So you couldn't trigger a copy-dependencies task from a pom with
LockJar. Spinning the concept around a little: from a pom, LockJar can
give you access to all the Jar dependencies and you can copy them where
you want.

    paths = LockJar.list( :resolve => true, :local_paths => true ) do
       pom 'path/to/pom.xml'
    end

As to local jars, if they are defined as system scope in the pom,
LockJar will pick them up. From the previous example, the local jars
path would be included in paths.

This is one of the areas Naether's setup is different than standard
Maven. It allows system scopes dependencies to join in the resolution
from transitive dependencies. Naether checks relative to the current
work space if the system dep exist, if it finds it, it adds it to the
dependency resolution. If it does not find it, the dependency is ignored
(which is what Maven does). Basically, if you deploy a pom with system
scopes, LockJar will translate that to local paths as well.

I actually started working on local workspace resolution for Naether, so
that a local jar could override transitive dependencies. Was useful when
a dev copy of a jar should be used instead of the installed version. It
never made it out to LockJar tho, there is a placeholder in the dsl for
it.  Here is an example of what I have in mind for loading the classpath
with jars:

    LockJar.load( :resolve => true) do
       pom 'path/to/pom.xml'
       local "org.apache.mina:mina-core:2.0.4",
"lib/mina-core-2.0.4.jar"
    end

> What do either projects do in cases where there are conflicts? e.g.
> nokogiri including bundled xerces jar
>
Ah, the problem of a polluted classpath. Christian and I pondering this
for a little while, I never figured out a solution for it. The issues
are being able to know all the jar requirements of all gems at (before?)
runtime and being able to have a valid resolution for all those jar
requirements. If all gems with jars has some sort of spec (I only need
this jar at >= 1.0) a pre processor could run a generate a Jarfile.lock
with the runtime jars. A plugin for Bundler would be perfect . . . just
need Bundler to support plugin -
https://github.com/bundler/bundler-features/issues/8

Hope these rambling answers help!
--Michael
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-01-25 11:31
(Received via mailing list)
hi Michael and Patrick,

every of those projects have their own little pros and cons. but we all
agree that if every gem in the end just required their jars conflicts
are
bound to come.

for that the idea of https://github.com/mkristian/jar-dependencies it
just
tracks the requiring of jars and I am pretty sure LockJar and PomLoader
can
use that require_jarfile. the second aspect about adding jars to gem is
secondary (though it is just couple of lines code to do it).

it has one purpose to NOT load jars with different version into the
jruby-classloader (require jarfile) and warns the user. i.e. you can
find a
way on how to solve the version conflict or maybe it is just OK to
ignore
it.

so please remark on jar-dependencies and whether you want to support it.
I
will try to get the jruby team using it for the defaults gems (with
jars)
coming through jruby itself and I will contact torquebox about this as
well
and add the support to jruby-maven-plugins torquebox uses to build (some
of) their gems. and finally will try to get it into rake-compiler gem
(somehow since it will get some refactoring soon/already)

if you think of any improvements just let me know, i.e. something like a
finer switch than turn off ALL jar loading or allow ALL.

- christian
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-01-25 11:40
(Received via mailing list)
On Sat, Jan 25, 2014 at 6:34 AM, Michael Guymon
<michael.guymon@gmail.com>wrote:

>
>  When I add gems that also require gems does it make sense to also
> declare those dependencies in the project pom?
>
>    I have never used gem deps in a Pom, Christian would know.
>


managing gems with maven (or ruby-maven) deals that maven will resolve
those gems and its transitive dependencies. it will also resolve
declared
jars (via the requirements fields of the gemspec) they will be all
resovled
even from jars which are declared inside a gem of a gem. but for this
you
need to add gem-maven-extension (part of the
https://github.com/torquebox/jruby-maven-plugins set of plugins).
actually
torquebox itself uses it to create some of their gems and it also can
include jar dependencies.

actually jbundler and ruby-maven just declare some POM using the ruby
DSL
from ruby-maven and execute that POM (a phase or goal). most of the code
is
rather brief since it reuses the big set of existing maven plugins, i.e.
jbundler uses the maven-dependency-plugin to lockdown the jar
dependencies
;)

- christian
54147c1a1223b425d4f4f7947c9bba46?d=identicon&s=25 Ariel Valentin (Guest)
on 2014-01-25 16:23
(Received via mailing list)
Thanks for all of your help.

After reading your responses I realize there was a typo in my original
question. My intention was to ask about gems that require jars using
maven.
E.g. foo.gem requires guava.jar but bar.gem requires foo.gem and also
makes use of guava.
Should I require guava in foo.gem?

Also re: system scope; I like being able to have maven resolve and
download the dependencies for me at install time. I believe that system
scope would require that I include the jars in my source code
repository, which is what I am trying to avoid.

Perhaps what I should do is lay out my use case and get some feedback
from you guys at what should be a sensible approach.

My application is delivered using RPMs. When we assemble our project we
use bundler in standalone to install gems in vendor/gems. All of our
application logic is written in gems and many of them make use of other
java libraries, which usually includes jars in their lib directory.

I want to move away from that model and use maven just as I have on
other java projects.

I wonder if I should treat these dependencies the same way that some
YARV gems do; make all dependencies "provided" scope when authoring gems
and then require the applications that use my gems and then install the
jars in the vendor/jars directory?

After typing that, it reads awful.

Curse you dependency management!

Thanks,
Ariel
---
Sent from my mobile device. Please excuse any errors.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.