SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
180 stars 33 forks source link

WebJars plugin breaks GraalVM Native Image building #146

Closed Skater901 closed 1 month ago

Skater901 commented 1 month ago

I tried using GraalVM to build a Native Image of my project using ktor-swagger-ui, but the build failed with the following errors:

Error: Unsupported features in 5 methods
Detailed message:
Error: Detected a ZipFile object in the image heap. A ZipFile object contains pointers to unmanaged C memory and file descriptors, and these resources are no longer available at image runtime. If these objects should not be stored in the image heap, you can use

    '--trace-object-instantiation=java.util.jar.JarFile'

to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with

    '--initialize-at-run-time=<culprit>'

to prevent the instantiation of the object.
The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.

I spent some time debugging, and was able to figure out that the problem is the presence of the Ktor WebJars plugin. Specifically, this.

I made my own artifact locally of ktor-swagger-ui without the WebJars plugin, and my native image built successfully. Additionally, I tested my application, and the Swagger UI was still available, even with WebJars removed.

Since the WebJars plugin doesn't seem to actually be needed for ktor-swagger-ui to work, is it possible to remove it? Or, if it is needed and I've just missed how it's needed, is it possible to make it a configurable option, so that I can disable the WebJars plugin? (And potentially exclude it from my dependencies, if required)

SMILEY4 commented 1 month ago

Hi, i haven't tested in quite some time without the webjars plugin so i'm not sure why i originally added it, but with your and my testing, it seems like its not required. I'll remove it with the next version :+1: