Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GraalVM native image support for Spring server #1769

Merged
merged 2 commits into from
May 7, 2023

Conversation

dariuszkuc
Copy link
Collaborator

📝 Description

Changes to enable GraalVM native image support for graphql-kotlin-spring-server.

🔗 Related Issues

Changes to enable GraalVM native image support for `graphql-kotlin-spring-server`.
@dariuszkuc dariuszkuc added changes: minor Changes require a minor version module: server Issue affects the server code module: plugin Issue affects the plugins code labels May 3, 2023
@@ -34,7 +34,7 @@ class GenerateGraalVmMetadataMojo : AbstractSourceMojo() {
override lateinit var outputDirectory: File

override fun generate() {
val metadataDirectory = File(outputDirectory, "META-INF/native-image/${project.groupId}/${project.name}")
val metadataDirectory = File(outputDirectory, "META-INF/native-image/${project.groupId}/${project.name}/graphql")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraalVM plugin looks for reachability metadata under any META-INF/native-image subdirectories. Per GraalVM documentation they suggest to generate reachability metadata under <groupId>/<artifactId> subdirectory to avoid collisions. Adding explicit graphql subdirectory to avoid collision with SpringBoot plugin generating metadata under the same directory.

@@ -29,13 +30,21 @@ data class GraphQLConfigurationProperties(
val packages: List<String>,
/** Boolean flag indicating whether to print the schema after generator creates it */
val printSchema: Boolean = false,
@NestedConfigurationProperty
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required extra metadata to generate GraalVM native image (docs)

@@ -1,5 +1,10 @@
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
plugins {
alias(libs.plugins.graalvm.native) apply false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GraalVM native plugin dynamically generates some "helper" methods so we need to ensure they are generated just once for whole composite project, otherwise build blows up with classpath issues.

Apply same change to Gradle (use `graphql` subdirectory) as was done for Maven. SpringBoot JAR complains about duplicate resources otherwise...
@dariuszkuc dariuszkuc enabled auto-merge (squash) May 3, 2023 21:38
@dariuszkuc dariuszkuc requested a review from samuelAndalon May 3, 2023 21:40
@dariuszkuc dariuszkuc merged commit 78d3014 into ExpediaGroup:master May 7, 2023
@dariuszkuc dariuszkuc deleted the graalvmSpring branch May 7, 2023 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: minor Changes require a minor version module: plugin Issue affects the plugins code module: server Issue affects the server code
Development

Successfully merging this pull request may close these issues.

None yet

2 participants