Skip to content

Commit 77ccb43

Browse files
committed
Fix Java version mismatch errors
We are trying to compile for Java 8 with `-target 1.8 -source 1.8 `at compile time but the JRuby jar file (jruby.jar) is compiled with Java 21 - Error message: `class file has wrong version 65.0, should be 61.0` - version 65.0 = Java 21 - version 61.0 = Java 17
1 parent 3c72fbe commit 77ccb43

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

Rakefile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,26 @@ if jruby?
6767
jruby_home = RbConfig::CONFIG['prefix']
6868
lib_dir = ext.lib_dir += "/#{ext.platform}/racc"
6969
ext.ext_dir = 'ext/racc'
70+
71+
# Determine appropriate Java version based on JRuby version
72+
# JRuby 10.x requires Java 21, 9.4.x requires Java 11, earlier versions use Java 8
73+
java_version = if defined?(JRUBY_VERSION)
74+
case JRUBY_VERSION
75+
when /^10\./
76+
'21' # JRuby 10.x requires Java 21
77+
when /^9\.4\./
78+
'11' # JRuby 9.4.x requires Java 11
79+
else
80+
'1.8' # JRuby 9.3.x and earlier can use Java 8
81+
end
82+
else
83+
'1.8' # Default to Java 8 if JRUBY_VERSION is not defined
84+
end
85+
7086
# source/target jvm
71-
ext.source_version = '1.8'
72-
ext.target_version = '1.8'
87+
ext.source_version = java_version
88+
ext.target_version = java_version
89+
7390
jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
7491
ext.classpath = jars.map { |x| File.expand_path x }.join( ':' )
7592
ext.name = 'cparse-jruby'

0 commit comments

Comments
 (0)