From 8e798148ff92bb0fa1a326f928747278c17a190b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Rosick=C3=BD?= Date: Thu, 30 Mar 2023 02:10:29 +0200 Subject: Don't use --release flag on Java 8 (#213) this allows using ``` Rake::JavaExtensionTask.new("name", gemspec) do |ext| ext.release = '8' end ``` on Java 8 (for building the gem), because the flag is available since Java 9, see https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html this flag is for backward compatibility, so it's safe to just skip it if we can't use it. relates to https://github.com/puma/puma/pull/3109 https://github.com/socketry/nio4r/pull/292 --- lib/rake/javaextensiontask.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rake/javaextensiontask.rb b/lib/rake/javaextensiontask.rb index 5603afc..7ad9095 100644 --- a/lib/rake/javaextensiontask.rb +++ b/lib/rake/javaextensiontask.rb @@ -212,7 +212,7 @@ execute the Rake compilation task using the JRuby interpreter. end def java_target_args - if @release + if @release && release_flag_supported? ["--release=#{@release}"] else ["-target", @target_version, "-source", @source_version] @@ -303,5 +303,11 @@ execute the Rake compilation task using the JRuby interpreter. "-Xlint:#{@lint_option}" end + + def release_flag_supported? + return true unless RUBY_PLATFORM =~ /java/ + + Gem::Version.new(Java::java.lang.System.getProperty('java.version')) >= Gem::Version.new("9") + end end end -- cgit v1.2.1