Java SE 9 ã® javac ã§éå»ãã¼ã¸ã§ã³ãã¿ã¼ã²ããã«ããã¨ãã«ã¯ --release ãªãã·ã§ã³ã使ç¨ããã¨è¯ã
JDK ã® javac
ã³ãã³ãã使ã£ã¦éå»ãã¼ã¸ã§ã³ã® Java è¨èªã§æ¸ãããã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ããéã«ã¯ã-source
ãªãã·ã§ã³ã -target
ãªãã·ã§ã³ã使ç¨ãã¦ãã¾ããã (JDK 8 ã¾ã§ã®è©±ã) ãã®ã¨ããé©åãªãã¼ãã¹ãã©ããã¯ã©ã¹ãã¹ãè¨å®ããªããã°ã対象ãã¼ã¸ã§ã³ã«åå¨ããªã Java API ã使ç¨ãã¦ãã¦ããã«ããéã£ã¦ãã¾ããã¨ããåé¡ãããã¾ããã
JDK 9 ã® javac
ã³ãã³ãã«ã¯ --release
ãªãã·ã§ã³ã追å ããã¾ããã ä»å¾ã¯ (åºæ¬çã«ã¯) ãã®ãªãã·ã§ã³ã使ç¨ããããã«ããã¨è¯ãããã§ãã
- ããã¥ã¡ã³ã : javac
Java SE 9 (Oracle JDK 9) ã®ãã¤ã°ã¬ã¼ã·ã§ã³ã¬ã¤ããã
マイグレーションガイドã«ã¯ä»¥ä¸ã®ããã«æ¸ããã¦ãã¾ãã
If you use the
-source
and-target
options withjavac
, then check the values that you use. In JDK 9,javac
uses a "one plus three back" policy of supporting-source
and-target
options.The supported
-source
/-target
values are 9 (the default), 8, 7, and 6 (6 is deprecated, and a warning is displayed when this value is used).In JDK 8,
-source
and-target
values of 1.5/5 and earlier were deprecated and caused a warning to be generated. In JDK 9, those values cause an error.>javac -source 5 -target 5 Sample.java warning: [options] bootstrap class path not set in conjunction with -source 1.5 error: Source option 1.5 is no longer supported. Use 1.6 or later. error: Target option 1.5 is no longer supported. Use 1.6 or later.If possible, use the new
--release
flag instead of the-source
and-target
options. The--release N
flag is conceptually a macro for:-source N -target N -bootclasspath $PATH_TO_rt.jar_FOR_RELEASE_NThe valid arguments for the
--release
flag follow the same policy as for-source
and-target
, one plus three back.javac can recognize and process class files of all previous JDKs, going all the way back to JDK 1.0.2 class files.
See JEP 182: Policy for Retiring
Java Platform, Standard Edition Oracle JDK 9 Migration Guide, Release 9javac
-source
and-target
Options.
ã¤ã¾ãã--release
ãã©ã°ãæå®ããã¨ã-source
ãªãã·ã§ã³ã¨ -target
ãªãã·ã§ã³ãæå®ããããã«é©åãªãã¼ãã¯ã©ã¹ãã¹ã®æå®ãè¡ã£ãç¶æ
ã«ãªãã¾ãã ããã¾ã§ãéå»ãã¼ã¸ã§ã³ã®ãã¼ãã¯ã©ã¹ãã¹ãè¨å®ããã«ã¯ãéå»ãã¼ã¸ã§ã³ã® Java å®è¡ç°å¢ãåå¾ãã¦ãã®ä¸ã® rt.jar ãæå®ãã¦ããå¿
è¦ããã£ãã®ã§ãæ ¼æ®µã«ä¾¿å©ã«ãªãã¾ããã
試ãã¦ã¿ã
å®éã«ã以ä¸ã®ãããªã³ã¼ããå«ã Java ã®ã½ã¼ã¹ãã¡ã¤ã«ãã³ã³ãã¤ã«ãã¦ã¿ã¾ããã
public class Main { public static void main(String[] args) { String test = String.join("", ""); // Java SE 8 㧠Java API ã«å°å ¥ãããã¡ã½ããã } }
--release 8
ãæå®ããå ´åã¯ãåé¡ãªãã³ã³ãã¤ã«ããã¾ãã
~\java-project> javac --release 8 .\Main.java
--release 7
ãæå®ããå ´åã¯ãä¸è¨ã®ããã«ã¨ã©ã¼ã«ãªãã¾ãã
~\java-project> javac --release 7 .\Main.java .\Main.java:3: ã¨ã©ã¼: ã·ã³ãã«ãè¦ã¤ãããã¾ãã String test = String.join("", ""); ^ ã·ã³ãã«: ã¡ã½ãã join(String,String) å ´æ: ã¯ã©ã¹ String ã¨ã©ã¼1å
Java 7 åãã«ãã«ããããã© Java 7 ã®å®è¡ç°å¢ã§åãã㨠(Java 7 ã«ãªã API ã使ã£ã¦ãã¦) ä¾å¤ãçºçãããã¨ãããããªãã¹ãæ¸ãããã§æé«ã§ããï¼
Gradle ã§ã®ä½¿ãæ¹
Gradle 4.2.1 ç¾å¨ãJavaCompile
ã¿ã¹ã¯ã§ javac
ã® --release
ãªãã·ã§ã³ãæå®ããæ¹æ³ã¨ãã¦ç¹å¥ãªã¡ã½ããã¯æä¾ããã¦ãã¾ããã é常ã®ã³ã³ãã¤ã©ãªãã·ã§ã³ãæå®ããæ¹æ³ã¯ä½¿ç¨ã§ããã®ã§ãé常ã®ã³ã³ãã¤ã©ãªãã·ã§ã³ã®æå®ã¨åãæ¹æ³ã§ --release
ãªãã·ã§ã³ãæå®ãã¾ãã
å
·ä½çã«ã¯ CompileOptions#compilerArgs
ããããã£ã使ç¨ãã¾ãã ãã®ããã¥ã¡ã³ããèªãã¨ããFor example, it is possible to pass the --release
option of JDK 9ã ã¨ã ãNote that if --release
is added then -target
and -source
are ignored.ã ã¨ãæ¸ããã¦ãã¾ãã --release
ãªãã·ã§ã³ã«ãã°ã£ã¡ã対å¿ããã¦ãã¾ããã
è¶ åç´ãª build.gradle ã®ä¾ãæ¸ãã¦ããã¾ãã
apply plugin: 'java' tasks.withType(JavaCompile) { options.compilerArgs.addAll(['--release', '8']) }