我们有一个使用Java 8构建的代码库,其中包含多个REST服务。我们想要迁移到Java 11,正在尝试找出最佳方法。我们考虑逐个模块进行升级。例如,将一个服务从Java 8改为Java 11,而其他服务仍然是Java 8。我们不确定Maven是否支持这样的操作?
我们有一个使用Java 8构建的代码库,其中包含多个REST服务。我们想要迁移到Java 11,正在尝试找出最佳方法。我们考虑逐个模块进行升级。例如,将一个服务从Java 8改为Java 11,而其他服务仍然是Java 8。我们不确定Maven是否支持这样的操作?
声明:这不是一个答案,只是我最近经验的部分报告。如果您觉得它不符合SO标准,请随意标记此答案。
Maven支持这个吗?
是的,使用编译器插件3.8.0/3.8.1
但是,这种迁移需要额外的关注。
最近我们做了类似于从ORACLE JDK 8到OPENJDK 11的迁移。由于我们有数百个具有不同任务的存储库,我们遇到了各种问题。仅举几个我在这里通过电子邮件标记为[jdk11_migration]的问题:
It is quite obvious but I'd like to highlight that in order to migrate from java 8 to 11 we have to meet the requirements from java 9 and 10 as well
Some maven plugins like cobertura do not support Java 11 and I guess they will never support it. In some cases, these plugins have reached the abandoned life cycle stage. The solution was looking for alternatives in a case to case manner. For example, we replaced cobertura by Jacoco.
rt.jar and tools.jar have been removed! Everything you have explicity refered from them will probably break.
some classes which we shouldn't use in java 9 or less now in java 11 no longer exist. I'm talking about to access classes in packages like sun.*, sun.misc etc. The solution is to look for a one-to-one replacement or refactor the code to avoid the usage.
Reflection usually is the last bullet to use and, for these cases, in java 9 and above we geta warning messages like:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by ...
WARNING: Please consider reporting this to the maintainers of ...
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
虽然它并不是一个完美的解决方案,但有一个标记可以消除这个警告——illegal-access=permit。当使用surefire maven插件时,这尤其重要。
虽然对我们来说这不是问题,但我注意到你的存储库主要由REST组件组成。可能你会遇到ClassNotFound问题,涉及到一些像javax.xml.bind这样的包,它们基本上已经从Java标准版中删除了。你可以通过在pom.xml中显式地包含它们来修复它们。
幸运的是,在你的迁移过程中,你可能会在SO或互联网上找到每个问题的好问题和答案。野外还有一些迁移指南,是很好的起点。特定问题,如混淆和IDE集成,可能需要花费一些时间,但至少根据我的经验,这次迁移比我想象的要容易。