JRUBY - Adding Group fails with csv Error

  • Platform information:
    • openHAB 5.2
    • openhabian (trixie)
    • Java Runtime Environment: OpenJDK 64-Bit Server VM (build 21.0.10+7-Debian-1deb13u1, mixed mode, sharing)
  • Issue of the topic: attempting to add a group in jruby (rule and console) fails with cannot load such file – csv (LoadError)
  • Specifically I am trying to add a group that “sum” the value of all the children which are “number” or :number

this works

group_item 'myGroup',
                   'myGroup', type: :number

this fails

group_item 'myGroup',
                   'myGroup', type: :number, function: 'sum'

Full Console Test

rb(main):001* items.build do
irb(main):002*   group_item 'myGroup',
irb(main):003*   'myGroup', type: :number, function: 'sum'
irb(main):004> end
/etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/console/irb.rb:103: warning: csv was loaded from the standard library, but is not part of the default gems starting from Ruby 3.4.0.
You can add csv to your Gemfile or gemspec to silence this warning.
org/jruby/RubyKernel.java:1195:in 'require': cannot load such file -- csv (LoadError)
	from uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundled_gems.rb:81:in 'block in replace_require'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/dsl/items/builder.rb:822:in 'create_item'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/dsl/items/builder.rb:688:in 'build'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/dsl/items/builder.rb:160:in 'add'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/dsl/items/builder.rb:101:in 'group_item'
	from (irb):2:in 'block in evaluate'
	from org/jruby/RubyBasicObject.java:2708:in 'instance_eval'
	from org/jruby/RubyBasicObject.java:2736:in 'instance_eval'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/core/entity_lookup.rb:142:in 'block in instance_eval_with_dummy_items'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/dsl/thread_local.rb:45:in 'thread_local'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/core/entity_lookup.rb:141:in 'instance_eval_with_dummy_items'
	from /etc/openhab/automation/ruby/.gem/10.0.6.0/gems/openhab-scripting-5.50.0/lib/openhab/core/items/registry.rb:57:in 'build'
	from (irb):1:in 'evaluate'
	from org/jruby/RubyKernel.java:1270:in 'eval'
	from org/jruby/RubyKernel.java:1669:in 'loop'
	from org/jruby/RubyKernel.java:1409:in 'catch'
	... 3 levels...

Log file

- cannot load such file -- csv (LoadError)

I do not understand why I am getting a csv error

Jruby info

jrubyscripting info
JRuby 10.0.6.0
JRuby Scripting Library 5.50.0
ENV['GEM_HOME']: /etc/openhab/automation/ruby/.gem/10.0.6.0
ENV['RUBYLIB']: /etc/openhab/automation/ruby/lib
ENV['BUNDLE_GEMFILE']: /etc/openhab/automation/ruby/Gemfile
Script path: /etc/openhab/automation/ruby

JRuby Scripting Add-on Configuration:
=====================================
Ruby Gems
  gems: openhab-scripting=~>5.0
  bundle_gemfile: /etc/openhab/automation/ruby/Gemfile
  check_update: true
  require: openhab/dsl

Ruby Environment
  gem_home: /etc/openhab/automation/ruby/.gem/{RUBY_ENGINE_VERSION}
  rubylib: /etc/openhab/automation/ruby/lib
  dependency_tracking: true

System Properties
  local_context: singlethread
  local_variable: transient

JRuby Console
  console: irb

This happens when you’re using Gemfile.

Current solution: add csv to your Gemfile

openhab> jrubyscripting bundle add csv

There’s an open PR to address this since Feb, but I haven’t got around to finalising it.

Thanks a million @jimtng