Skip to content

Commit 2564fbf

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 2564fbf

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

Rakefile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,31 @@ if jruby?
6767
jruby_home = RbConfig::CONFIG['prefix']
6868
lib_dir = ext.lib_dir += "/#{ext.platform}/racc"
6969
ext.ext_dir = 'ext/racc'
70-
# source/target jvm
71-
ext.source_version = '1.8'
72-
ext.target_version = '1.8'
70+
71+
# Determine appropriate Java version based on JRuby version
72+
# For JRuby 10.x, we compile with Java 21 but target Java 8 bytecode for compatibility
73+
# This allows using newer Java while maintaining backward compatibility
74+
if defined?(JRUBY_VERSION)
75+
case JRUBY_VERSION
76+
when /^10\./
77+
# JRuby 10.x: compile with available Java but target Java 8 for compatibility
78+
ext.source_version = '1.8'
79+
ext.target_version = '1.8'
80+
when /^9\.4\./
81+
# JRuby 9.4.x: use Java 11
82+
ext.source_version = '11'
83+
ext.target_version = '11'
84+
else
85+
# JRuby 9.3.x and earlier: use Java 8
86+
ext.source_version = '1.8'
87+
ext.target_version = '1.8'
88+
end
89+
else
90+
# Default to Java 8 if JRUBY_VERSION is not defined
91+
ext.source_version = '1.8'
92+
ext.target_version = '1.8'
93+
end
94+
7395
jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
7496
ext.classpath = jars.map { |x| File.expand_path x }.join( ':' )
7597
ext.name = 'cparse-jruby'

0 commit comments

Comments
 (0)