jmix-framework / jmix

Jmix framework
https://www.jmix.io
Apache License 2.0
558 stars 118 forks source link

Error while building applications with mixed code Java/Kotlin #994

Open GoetzConsulting opened 2 years ago

GoetzConsulting commented 2 years ago

Jmix version: 1.2.3

We started very early with the JMIX framework and wrote our application with Java.

Now we want to migrate our project step by step to Kotlin. In doing so, we encounter an error when we use mixed Java and Kotlin code.

The EclipseLink enhancer runs before the Java files have been compiled and are in the build directory.

> Task :bootBuildInfo

> Task :compileKotlin
Enhancing entities in root project 'xxx' for source set 'main'
Project entities:
    JPA: [];
    DTO: [];
Project converters: [].
Running EclipseLink enhancer in root project 'xxx' for source set 'main'
Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-40007] (Eclipse Persistence Services - 2.7.9.6-jmix): org.eclipse.persistence.exceptions.StaticWeaveException
Exception Description: An exception was thrown while weaving: [Ljava.lang.String;@3d921e20
Internal Exception: java.nio.file.NoSuchFileException: C:\<xxx path>\build\tmp\entitiesEnhancing\main\persistence
    at org.eclipse.persistence.exceptions.StaticWeaveException.exceptionPerformWeaving(StaticWeaveException.java:140)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:88)
Caused by: java.nio.file.NoSuchFileException: C:\<xxx path>\build\tmp\entitiesEnhancing\main\persistence
    at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
    at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
    at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
    at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
    at java.base/sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:194)
    at java.base/java.nio.file.Files.readAttributes(Files.java:1763)
    at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1222)
    at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:726)
    at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:843)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:246)
    at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:176)
    at java.base/java.util.jar.JarFile.<init>(JarFile.java:346)
    at java.base/java.util.jar.JarFile.<init>(JarFile.java:317)
    at java.base/java.util.jar.JarFile.<init>(JarFile.java:283)
    at org.eclipse.persistence.internal.jpa.deployment.ArchiveFactoryImpl.createArchive(ArchiveFactoryImpl.java:95)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveClassTransformer.buildClassTransformers(StaticWeaveClassTransformer.java:108)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveClassTransformer.<init>(StaticWeaveClassTransformer.java:78)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.process(StaticWeaveProcessor.java:252)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.performWeaving(StaticWeaveProcessor.java:174)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.start(StaticWeave.java:117)
    at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:86)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Process 'command 'C:\Program Files\Java\jdk-11.0.2\bin\java.exe'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 14s

> Task :compileKotlin FAILED

We think we have found the responsible place: https://github.com/jmix-framework/jmix/blob/master/jmix-gradle-plugin/src/main/groovy/io/jmix/gradle/JmixPlugin.groovy#L93

gorbunkov commented 1 year ago

We'll need to implement something similar to what has been done in CUBA Gradle plugin (the issue). Kotlin and java entities must be enhanced only after both of them are compiled.

gorbunkov commented 1 year ago

It seems that the reason of the exception described in the issue is that main application class is written in Java. If it was in Kotlin the error would not appear. As a workaround the main class can be converted to Kotlin. The forum discussion: https://forum.jmix.io/t/unable-to-compile-run-when-mix-a-jmix-java-application-with-kotlin-classes/2412/5