lock_jar icon indicating copy to clipboard operation
lock_jar copied to clipboard

NoMethodError trying to install lock_jar under JRuby 10.0.2.0

Open mrckzgl opened this issue 4 months ago • 11 comments

As title, see following console output:

[redacted@redacted janusgraph_memory_leak]$ ruby --version
jruby 10.0.2.0 (3.4.2) 2025-08-07 cba6031bd0 OpenJDK 64-Bit Server VM 21.0.8+9 on 21.0.8+9 +indy +jit [x86_64-linux]
[redacted@redacted janusgraph_memory_leak]$ gem install lock_jar
Fetching lock_jar-0.15.2.gem
Fetching thor-1.4.0.gem
Fetching naether-0.15.10-java.gem
Fetching httpclient-2.9.0.gem
Successfully installed thor-1.4.0
Successfully installed httpclient-2.9.0
Building native extensions. This could take a while...
ERROR:  Error installing lock_jar:
        ERROR: Failed to build gem native extension.

    current directory: /home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java
/home/redacted/.rvm/rubies/jruby-10.0.2.0/bin/jruby -rrubygems /home/redacted/.rvm/rubies/jruby-10.0.2.0/lib/ruby/gems/shared/gems/rake-13.3.0/exe/rake RUBYARCHDIR\=/home/redacted/.rvm/gems/jruby-10.0.2.0/extensions/universal-java-21/3.4.0/naether-0.15.10-java RUBYLIBDIR\=/home/redacted/.rvm/gems/jruby-10.0.2.0/extensions/universal-java-21/3.4.0/naether-0.15.10-java
rake aborted!
NoMethodError: undefined method 'exists?' for class File
Did you mean?  exist?
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/lib/naether/configuration.rb:14:in 'initialize'
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/lib/naether/configuration.rb:68:in '<module:Naether>'
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/lib/naether/configuration.rb:2:in '<main>'
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/lib/naether.rb:23:in '<main>'
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/lib/naether/bootstrap.rb:1:in '<main>'
/home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java/Rakefile:5:in 'block in <main>'
org/jruby/ext/monitor/Monitor.java:85:in 'synchronize'
org/jruby/ext/monitor/Monitor.java:85:in 'synchronize'
Tasks: TOP => default => prepare
(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in /home/redacted/.rvm/gems/jruby-10.0.2.0/gems/naether-0.15.10-java for inspection.
Results logged to /home/redacted/.rvm/gems/jruby-10.0.2.0/extensions/universal-java-21/3.4.0/naether-0.15.10-java/gem_make.out

Did I miss something or is lock_jar /naether-0.15.10 not compatible with Jruby 10 / Ruby 3.4 ?

mrckzgl avatar Sep 30 '25 13:09 mrckzgl

Culprit is naether. Is it possible to set the dependency version to a git commit? https://github.com/mguymon/naether/commit/c2c127993bbc4f3f1ac7cfe617cead4605a83cb4 will fix this.

mrckzgl avatar Sep 30 '25 13:09 mrckzgl

@mguymon You still out there? I'd like to collab to merge the functionality of your lock_jar with the actively-maintained jar-dependencies we ship with JRuby...

https://github.com/jruby/jar-dependencies

headius avatar Oct 01 '25 18:10 headius

@headius I exist, but am not currently using naether / lock_jar so it has fallen a bit to the wayside.

Happy to make updates and improvements if it is still in use in the wild.

mguymon avatar Oct 05 '25 16:10 mguymon

@mrckzgl I released an update to Naether but had to bump RJB which appears to break the class loading in lock_jar. Will require more work to get it work unfortunately.

mguymon avatar Oct 05 '25 17:10 mguymon

Its used in the wild by us :-) If you could make a release with the upgraded naether dependency that would be awesome

mrckzgl avatar Oct 05 '25 17:10 mrckzgl

@mrckzgl Do you need just the jruby side or MRI? i can try and make a quick fix for a single runtime while I try and get everything back online.

mguymon avatar Oct 05 '25 17:10 mguymon

We just need / use JRuby. Thatd be super awesome, but if its too much work dont worry.

mrckzgl avatar Oct 05 '25 17:10 mrckzgl

@mrckzgl I pushed 0.15.11-java - it passes all the tests for naether and lock_jar. Give that a whirl.

mguymon avatar Oct 05 '25 18:10 mguymon

@mguymon Thanks for helping out here! It's probably still a good idea for us to either merge efforts or direct JRuby users toward jar_dependencies, but I could be convinced that your approach is better. Should I open a separate issue or would you be able to chat over chat or email or matrix?

headius avatar Oct 08 '25 18:10 headius

@headius lets take this chat else where (any of the options are fine), im happy to support whatever makes JRuby's life easier. Hit me up at [email protected] and we can go from there.

mguymon avatar Oct 08 '25 18:10 mguymon

I pushed 0.15.11-java - it passes all the tests for naether and lock_jar. Give that a whirl.

@mguymon I was pleased to note that this gem (and by extension also the "naether") are reactivated! Though, I couldn't find an associated Git commit for 0.15.11 release. Could you add it?

Meanwhile for anyone wandering what are the changes, here's the patch diff between 0.15.2 and 0.15.11

Patch
Left base folder: local_path/lock_jar-0.15.2
Right base folder: local_path/lock_jar-0.15.11-java
--- lib/lock_jar/class_loader.rb	2025-11-14 22:10:46.000000000 
+++ lib/lock_jar/class_loader.rb	2025-11-16 18:49:23.000000000 
@@ -28,13 +28,13 @@
     # @param [String] lockfile path
     def initialize(lockfile)
       # XXX: ensure Naether has been loaded, this should be handled less
       #     clumsily
       LockJar::Runtime.instance.resolver(nil)
       @class_loader = com.tobedevoured.naether.PathClassLoader.new(
-        JRuby.runtime.jruby_class_loader)
+        java.lang.Thread.currentThread.getContextClassLoader())
 
       jars = LockJar.list(lockfile, local_paths: true)
       jars.each do |jar|
         add_path(jar)
       end
     end
--- Gemfile	2025-11-14 22:10:46.000000000 
+++ Gemfile	2025-11-16 18:49:23.000000000 
@@ -1,14 +1,13 @@
 source 'https://rubygems.org'
 
 # Specify your gem's dependencies in lock_jar.gemspec
 gemspec
 
 group :test do
-  gem 'codeclimate-test-reporter', require: nil
   gem 'jarfile_gem', path: 'spec/fixtures/jarfile_gem'
 end
 
 group :development do
   gem 'pry'
   gem 'yard'
 end
--- lock_jar.gemspec	2025-11-14 22:10:46.000000000 
+++ lock_jar.gemspec	2025-11-16 18:49:23.000000000 
@@ -1,11 +1,15 @@
 # coding: utf-8
 lib = File.expand_path('../lib', __FILE__)
 $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
 
 require 'lock_jar/version'
 
+unless RUBY_PLATFORM == 'java'
+  raise "lock_jar requires JRuby. Current platform: #{RUBY_PLATFORM}. Please install and use JRuby to run this gem."
+end
 Gem::Specification.new do |s|
   s.name = 'lock_jar'
   s.version = LockJar::VERSION
   s.authors = ['Michael Guymon']
   s.date = '2014-03-06'
@@ -19,13 +23,14 @@
   s.test_files    = s.files.grep(%r{^(test|spec|features)/})
   s.extra_rdoc_files = %w(LICENSE README.md)
   s.homepage = 'http://github.com/mguymon/lock_jar'
   s.licenses = %w(Apache)
   s.require_paths = %w(lib)
   s.summary = 'Manage Jar files for Ruby'
+  s.platform = 'java'
 
-  s.add_dependency('naether', ['~> 0.15.0'])
+  s.add_dependency('naether', ['~> 0.15.11'])
   s.add_dependency('thor', ['>= 0.18.1'])
-  s.add_development_dependency('rspec', '~> 2.14.1')
+  s.add_development_dependency('rspec', '~> 3.0')
   s.add_development_dependency('rubocop', '~> 0.35.0')
   s.add_development_dependency('rake')
 end
--- spec/lock_jar_spec.rb	2025-11-14 22:10:46.000000000 
+++ spec/lock_jar_spec.rb	2025-11-16 18:49:23.000000000 
@@ -41,13 +41,13 @@
 
       context 'from Jarfile' do
         let(:lockjar_source) { 'spec/fixtures/Jarfile' }
         let(:expected_version) { LockJar::VERSION }
         let(:expected_local_repository) { '~/.m2/repository' }
         let(:expected_excludes) { %w(commons-logging logkit) }
-        let(:expected_remote_repositories) { %w(http://repo1.maven.org/maven2/) }
+        let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/) }
         let(:expected_groups) do
           {
             'default' => {
               'locals' => ['spec/fixtures/naether-0.13.0.jar'],
               'dependencies' => %w(
                 ch.qos.logback:logback-classic:jar:0.9.24
@@ -132,13 +132,13 @@
               jar 'org.testng:testng:jar:6.9.10'
             end
           end
 
           let(:expected_version) { LockJar::VERSION }
           let(:expected_maps) { { 'org.testng:testng:jar:6.9.10' => ['path/to/jar'] } }
-          let(:expected_remote_repositories) { ['http://repo1.maven.org/maven2/'] }
+          let(:expected_remote_repositories) { ['https://repo1.maven.org/maven2/'] }
           let(:expected_groups) do
             {
               'default' => {
                 'dependencies' => test_dependencies,
                 'artifacts' => test_artifacts
               }
@@ -156,13 +156,13 @@
               jar 'opensymphony:oscache:jar:2.4.1'
             end
           end
 
           let(:expected_version) { LockJar::VERSION }
           let(:expected_excludes) { %w(commons-logging logkit) }
-          let(:expected_remote_repositories) { %w(http://repo1.maven.org/maven2/ https://repository.jboss.org/nexus/content/groups/public) }
+          let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/ https://repository.jboss.org/nexus/content/groups/public) }
           let(:expected_groups) do
             {
               'default' => {
                 'dependencies' => %w(
                   avalon-framework:avalon-framework:jar:4.1.3 javax.jms:jms:jar:1.1
                   javax.servlet:servlet-api:jar:2.3 log4j:log4j:jar:1.2.12
@@ -194,19 +194,19 @@
       context 'from a block' do
         let(:lockfile) do
           LockJar.lock(local_repo: local_repo, lockfile: "#{TEMP_DIR}/NoRepoJarfile.lock") do
             jar 'org.eclipse.jetty:jetty-servlet:8.1.3.v20120416'
           end
 
-          File.exist?("#{TEMP_DIR}/NoRepoJarfile.lock").should be_true
+          File.exist?("#{TEMP_DIR}/NoRepoJarfile.lock").should be_truthy
 
           LockJar.read("#{TEMP_DIR}/NoRepoJarfile.lock")
         end
 
         let(:expected_version) { LockJar::VERSION }
-        let(:expected_remote_repositories) { %w(http://repo1.maven.org/maven2/) }
+        let(:expected_remote_repositories) { %w(https://repo1.maven.org/maven2/) }
         let(:expected_groups) do
           {
             'default' => {
               'dependencies' => %w(
                 org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016
                 org.eclipse.jetty:jetty-continuation:jar:8.1.3.v20120416
--- spec/lock_jar/maven_spec.rb	2025-11-14 22:10:46.000000000 
+++ spec/lock_jar/maven_spec.rb	2025-11-16 18:49:23.000000000 
@@ -13,9 +13,9 @@
     LockJar::Maven.pom_version('spec/pom.xml').should eql('3')
   end
 
   it 'should install artifact' do
     LockJar::Maven.install('maven_spec:install:7', 'spec/pom.xml', nil, local_repo: "#{TEMP_DIR}/test-repo")
 
-    File.exist?("#{TEMP_DIR}/test-repo/maven_spec/install/7/install-7.pom").should be_true
+    File.exist?("#{TEMP_DIR}/test-repo/maven_spec/install/7/install-7.pom").should be_truthy
   end
 end
--- README.md	2025-11-14 22:10:46.000000000 
+++ README.md	2025-11-16 18:49:23.000000000 
@@ -20,13 +20,13 @@
 ## Install
 
     gem install lock_jar
 
 ## Ruby Usage
 
-JRuby is natively supported. Ruby 1.9.3 and 2.1 uses [Rjb](http://rjb.rubyforge.org/) to proxy over JNI.
+JRuby is natively supported. Ruby 2.x uses [Rjb](http://rjb.rubyforge.org/) to proxy over JNI.
 
 ### Jarfile
 
 A Jarfile is a simple file using a Ruby DSL for defining a project's dependencies using the following
 methods:
 
@@ -315,19 +314,17 @@
            jar 'junit:junit:jar:4.12'
          end
     end
 
     define 'app' do
 
-       def 'project1' do
+       define 'project1' do
          lock_jar do
            jar  "org.apache.mina:mina-core:2.0.4"
          end
        end
 
-       def 'project2' do
+       define 'project2' do
           lock_jar do
             pom 'pom.xml'
           end
        end
 
     end
--- spec/lock_jar/resolver_spec.rb	2025-11-14 22:10:46.000000000 
+++ spec/lock_jar/resolver_spec.rb	2025-11-16 18:49:23.000000000 
@@ -52,18 +52,18 @@
         end
       end
     end
 
     let(:expected_remote_repos) do
       [
-        { url: 'http://repo1.maven.org/maven2/' },
+        { url: 'https://repo1.maven.org/maven2/' },
         { url: 'https://test/repo', username: 'user1', password: 'pass1' }
       ]
     end
 
     it 'should use repo config for auth' do
       subject.add_remote_repository('https://test/repo')
 
       expect(remote_repos).to eq(expected_remote_repos)
     end
   end
 end
--- spec/spec_helper.rb	2025-11-14 22:10:46.000000000 
+++ spec/spec_helper.rb	2025-11-16 18:49:23.000000000 
@@ -6,16 +6,12 @@
 require 'lock_jar'
 require 'lock_jar/cli'
 require 'stringio'
 require 'fileutils'
 require 'lock_jar/logging'
 require 'pry'
-require 'codeclimate-test-reporter'
 
-# coverage
-CodeClimate::TestReporter.start
 
 # Requires supporting ruby files with custom matchers and macros, etc,
 # in spec/support/ and its subdirectories.
 Dir[File.expand_path('.') + '/spec/support/**/*.rb'].each { |f| require f }
 
 LockJar::Logging.verbose!
@@ -31,13 +27,12 @@
 TEMP_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
 TEST_REPO = File.expand_path(File.join(TEMP_DIR, 'test-repo-install'))
 PARAM_CONFIG = File.expand_path(File.join(TEMP_DIR, 'param_config'))
 DSL_CONFIG = File.expand_path(File.join(TEMP_DIR, 'dsl_config'))
 
 RSpec.configure do |config|
-  config.order = 'default'
   config.treat_symbols_as_metadata_keys_with_true_values = true
   config.run_all_when_everything_filtered = true
   config.filter_run :focus
 
   config.before(:suite) do
     FileUtils.mkdir_p(DSL_CONFIG)
--- lib/lock_jar/version.rb	2025-11-14 22:10:46.000000000 
+++ lib/lock_jar/version.rb	2025-11-16 18:49:23.000000000 
@@ -1,5 +1,5 @@
 # frozen_string_literal: true
 module LockJar
   # still the version
-  VERSION = '0.15.2'.freeze
+  VERSION = '0.15.11'.freeze
 end