Skip to content

installing gems with jar dependencies like psych fails on recent ruby-maven/ruby-maven-libs #92

@jsvd

Description

@jsvd

I found that trying to install gems that require jars using modern ruby-maven and ruby-maven-libs wont work.
However JRuby will pull older versions by default:

/tmp/test# jruby -v
jruby 9.4.9.0 (3.1.4) 2024-11-04 547c6b150e OpenJDK 64-Bit Server VM 21.0.5+11-Ubuntu-1ubuntu124.04 on 21.0.5+11-Ubuntu-1ubuntu124.04 +jit [aarch64-linux]
/tmp/test# gem list | grep maven
/tmp/test#
/tmp/test# cat Gemfile
source "https://rubygems.org"

gem "jar-dependencies"
gem "ruby-maven", "= 3.9.3"
gem "ruby-maven-libs", "= 3.9.9"
/tmp/test# bundle install --path=vendor/bundle
[...]
/tmp/test# find . -name maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-libs-3.9.9/lib/maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-3.9.3/lib/maven/ruby/maven.rb
/tmp/test# cat Gemfile
source "https://rubygems.org"

gem "jar-dependencies"
gem "ruby-maven", "= 3.9.3"
gem "ruby-maven-libs", "= 3.9.9"
gem "psych"

/tmp/test# bundle install --path=vendor/bundle
Fetching gem metadata from https://rubygems.org/......
Resolving dependencies...
Using jar-dependencies 0.4.1
Using bundler 2.3.26
Using ruby-maven-libs 3.9.9
Using ruby-maven 3.9.3
Fetching date 3.4.1 (java)
Installing date 3.4.1 (java)
Fetching psych 5.2.3 (java)
Installing psych 5.2.3 (java)
  jar dependencies for psych-5.2.3-java.gemspec . . .
Installing gem 'ruby-maven' . . .

using maven for the first time results in maven
downloading all its default plugin and can take time.
as those plugins get cached on disk and further execution
of maven is much faster then the first time.

2025-01-20T15:33:43.479Z [main] WARN FilenoUtil : Native subprocess control requires open access to the JDK IO subsystem
Pass '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED' to enable.
      org.snakeyaml:snakeyaml-engine:2.9:compile
Bundle complete! 4 Gemfile dependencies, 6 gems now installed.
Bundled gems are installed into `./vendor/bundle`

/tmp/test# find . -name maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-libs-3.9.9/lib/maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-3.9.3/lib/maven/ruby/maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-3.3.13/lib/maven/ruby/maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-libs-3.3.9/lib/maven.rb

As we can see it works because older versions were still pulled even though I didn't ask for them:

However if I delete the older versions:

/tmp/test/vendor/bundle/jruby/3.1.0/gems# rm -rf psych-5.2.3-java/ ruby-maven-3.3.13 ruby-maven-libs-3.3.9/
/tmp/test/vendor/bundle/jruby/3.1.0/gems# cd /tmp/test/
/tmp/test# find . -name maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-libs-3.9.9/lib/maven.rb
./vendor/bundle/jruby/3.1.0/gems/ruby-maven-3.9.3/lib/maven/ruby/maven.rb

And try again, now we can see it fail:

/tmp/test# bundle install --path=vendor/bundle
[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path 'vendor/bundle'`, and stop using this flag
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/......
Resolving dependencies...
Using jar-dependencies 0.4.1
Using bundler 2.3.26
Using date 3.4.1 (java)
Using ruby-maven-libs 3.9.9
Using ruby-maven 3.9.3
Installing psych 5.2.3 (java)
  jar dependencies for psych-5.2.3-java.gemspec . . .
      org.snakeyaml:snakeyaml-engine:2.9:compile

ERROR TEMPLATE:

Errno::ENOENT: No such file or directory - /root/.m2/repository/org/snakeyaml/snakeyaml-engine/2.9/snakeyaml-engine-2.9.jar -- module org.snakeyaml.engine.v2
  org/jruby/RubyIO.java:1278:in `sysopen'
  org/jruby/RubyFile.java:366:in `initialize'
  org/jruby/RubyClass.java:949:in `new'
  org/jruby/RubyIO.java:1195:in `open'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:1394:in `copy_file'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:504:in `copy_file'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:423:in `block in cp'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:1577:in `block in fu_each_src_dest'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:1593:in `fu_each_src_dest0'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:1575:in `fu_each_src_dest'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:422:in `cp'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/installer.rb:92:in `vendor_file'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/installer.rb:151:in `block in vendor_jars'
  org/jruby/RubyArray.java:1981:in `each'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/installer.rb:150:in `vendor_jars'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/installer.rb:226:in `do_install'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/installer.rb:170:in `vendor_jars'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/jars/post_install_hook.rb:28:in `block in <main>'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/rubygems/installer.rb:381:in `block in run_post_install_hooks'
  org/jruby/RubyArray.java:1981:in `each'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/rubygems/installer.rb:380:in `run_post_install_hooks'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/rubygems_gem_installer.rb:43:in `install'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/source/rubygems.rb:207:in `install'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/installer/gem_installer.rb:54:in `install'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/worker.rb:62:in `apply_func'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/worker.rb:57:in `block in process_queue'
  org/jruby/RubyKernel.java:1725:in `loop'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/worker.rb:54:in `process_queue'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/bundler/worker.rb:91:in `block in create_threads'

Environment

Bundler       2.3.26
  Platforms   ruby, universal-java-21
Ruby          3.1.4p0 (2024-11-04 revision 547c6b150eb2c15799349ba727d036cbb62a4069) [universal-java-21]
  Full Path   /tmp/jruby-9.4.9.0/bin/jruby
  Config Dir  /tmp/jruby-9.4.9.0/etc
RubyGems      3.3.26
  Gem Home    /tmp/test/vendor/bundle/jruby/3.1.0
  Gem Path    /tmp/test/vendor/bundle/jruby/3.1.0
  User Home   /root
  User Path   /root/.local/share/gem/jruby/3.1.0
  Bin Dir     /tmp/test/vendor/bundle/jruby/3.1.0/bin
OpenSSL
  Compiled    JRuby-OpenSSL 0.15.0
  Loaded      JRuby-OpenSSL 0.15.0
  Cert File   /usr/lib/jvm/java-21-openjdk-arm64/lib/security/cacerts
  Cert Dir    /etc/ssl/certs
Tools
  Git         not installed
  RVM         not installed
  rbenv       not installed
  chruby      not installed
Gem.ruby      /tmp/jruby-9.4.9.0/bin/jruby
bundle #!     /usr/bin/env jruby

Bundler Build Metadata

Built At          2022-11-17
Git SHA           23ec5b8501
Released Version  true

Bundler settings

path
  Set for your local app (/tmp/test/.bundle/config): "vendor/bundle"

Gemfile

Gemfile

source "https://rubygems.org"


gem "jar-dependencies"
gem "ruby-maven", "= 3.9.3"
gem "ruby-maven-libs", "= 3.9.9"
gem "psych"

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    jar-dependencies (0.4.1)
    ruby-maven (3.9.3)
      ruby-maven-libs (~> 3.9.9)
    ruby-maven-libs (3.9.9)

PLATFORMS
  universal-java-21

DEPENDENCIES
  jar-dependencies
  ruby-maven (= 3.9.3)
  ruby-maven-libs (= 3.9.9)

BUNDLED WITH
   2.3.26

I believe the reason this fails is because the new mvn libs is outputting text the gems are not expecting. I got this from Logstash:

❯ MAVEN_HOME= ./vendor/bundle/jruby/3.1.0/gems/ruby-maven-libs-3.9.9/maven-home/bin/mvn -q dependency:copy-dependencies dependency:list -Dmaven.repo.local=/Users/joaoduarte/.m2/repository -f /Users/joaoduarte/elastic/logstash/vendor/jruby/lib/ruby/stdlib/jars/gemspec_pom.rb -Djars.0=org.snakeyaml:snakeyaml-engine:jar:2.7 -Djars.specfile=/Users/joaoduarte/elastic/logstash/vendor/bundle/jruby/3.1.0/specifications/psych-5.2.2-java.gemspec -DoutputAbsoluteArtifactFilename=true -DincludeTypes=jar -DuseRepositoryLayout=true -DoutputDirectory=/Users/joaoduarte/.m2/repository -DoutputFile=/Users/joaoduarte/elastic/logstash/vendor/bundle/jruby/3.1.0/gems/psych-5.2.2-java/deps.lst && cat /Users/joaoduarte/elastic/logstash/vendor/bundle/jruby/3.1.0/gems/psych-5.2.2-java/deps.lst
artifact 0: {:type=>"jar", :group_id=>"org.snakeyaml", :artifact_id=>"snakeyaml-engine", :version=>"2.7"}
      org.snakeyaml:snakeyaml-engine:2.7:compile

The following files have been resolved:
   org.snakeyaml:snakeyaml-engine:jar:2.7:compile:/Users/joaoduarte/.m2/repository/org/snakeyaml/snakeyaml-engine/2.7/snakeyaml-engine-2.7.jar -- module org.snakeyaml.engine.v2

mvn will output org.snakeyaml:snakeyaml-engine:jar:2.7:compile:/Users/joaoduarte/.m2/repository/org/snakeyaml/snakeyaml-engine/2.7/snakeyaml-engine-2.7.jar -- module org.snakeyaml.engine.v2, which then ends up being treated as the dependency's full name, so then FIleUtils.copy breaks:

Errno::ENOENT: No such file or directory - /root/.m2/repository/org/snakeyaml/snakeyaml-engine/2.9/snakeyaml-engine-2.9.jar -- module org.snakeyaml.engine.v2
  org/jruby/RubyIO.java:1278:in `sysopen'
  org/jruby/RubyFile.java:366:in `initialize'
  org/jruby/RubyClass.java:949:in `new'
  org/jruby/RubyIO.java:1195:in `open'
  /tmp/jruby-9.4.9.0/lib/ruby/stdlib/fileutils.rb:1394:in `copy_file'

Let me know if I should move this to one of the jruby maven gem repositories instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions