Why is modules' bytecode version not the same as JDK verson?
Answered
I set the Project SDK to my local JDK1.8 installed in my computer. It is It is File => Project Settings => Project => Project SDK.
When I click the Build button here, which JDK it uses to compile all the modules? My local JDK or some other JDK in Idea?
If it is use my local JDK1.8, why there is many premodule bytecode version settings for my modules in Settings => Build,Execution,Deployment =>Compiler => Java Compiler => Per-module bytecode version?
why is that there are many target bytecode version settings? If the JDK is 1.8, I guess all the modules' targer bytecode version should be 1.8. Why not?
Please sign in to leave a comment.
I have just answered you in the support request. The java compiler from the JDK which is set for you project is used.
Each module can be compiled with separate target bytecode version. It is not necessary should be the same as JDK version. With 1.8 JDK it can be <= 1.8. See javac documentation about cross compilation: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#BHCIJIEG
Then it is clear to me. Very thanks!!!
Then it comes anthoer quesiton.
There are several modules in my project. I set the target bytecode version of all modules to 1.8. But when I open my project another day, some of the bytecode versions are just reverted to 1.6 and others.
I googled a lot. Someone says to add some plugin in in the main pom.xml file.
I did that. But it doesn't work. It's a SpringBoot project. I am compiling the code by the embed green "down arrow" icon debugging by the embed green "bug" icon in idea. I am not using Maven to compile and run. Is this related with the problem?
Any idea about this problem?
First please make sure that the Maven itself uses the needed target level: you can check the source and target levels that the Maven actually uses itself by enabling Debug level in Settings(Preferences) | Build, Execution, Deployment | Build Tools | Maven | 'Output level:' option and execute 'compile' Maven goal from Maven projects tool window in IDE.
If it uses the expected (1.8) level, make sure the that all modules are imported into IDE as a Maven modules: to make sure you can re-create project by re-importing it from Maven: https://www.jetbrains.com/help/idea/creating-and-managing-projects.html#importing-project.
If issue remains, please provide the sample project to reproduce.
Hi All,
I finally resolved my problem. It is my neglect.
I have several modules in my project. But in the pom of sub module, I didn't add parent information correctly. Or I have set compile target versoin independently in sub pom. So the change in the parent pom has no influnce to some modules.
So in summary,
Add compile target information in parent pom can resolve this target version revert problem if you have correctly set the parent - child relationship.