kotlin
kotlin copied to clipboard
[KT-47876] [Maven] Populate class realm in plugin descriptor (where it is available) instead of project.
The option -Xuse-javac requires the tools-jar classpath to be setup before the plugin triggers compilation. This was done by adding the path to the tools Jar to the project realm, but at this point in the plugin phase, the project doesn't actually have a class realm setup yet that can be modified (the behavior of MavenProject changed a lot in 3.2.2 and later it seems). Instead, we populate the plugin class realm, as that is used when executing the compilation anyway, and it does actually exist.
Without this fix, the compilation will fail with an NPE:
Caused by: java.lang.NullPointerException at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute (K2JVMCompileMojo.java:217) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
After this change, compilation with -Xuse-javac works as intended. An integration test is supplied to test that it works.
Tracking issue: https://youtrack.jetbrains.com/issue/KT-47876