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
Add native image support with GraalVM and Spring Native #13733
Comments
This issue is stale because it has been open 30 days with no activity. |
🌴 |
I was going to look into this tonight, but it appears that Spring Boot 2.4.3 is not quite ready for native support. From https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#support-spring-boot:
|
@mraible The version 0.9.0 is expected for tomorrow: https://github.com/spring-projects-experimental/spring-native/milestones |
I tried it with the Index: pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/pom.xml b/pom.xml
--- a/pom.xml (revision 4e7c0fc5d9c716248b0efa9867876ba66de56141)
+++ b/pom.xml (date 1615484078715)
@@ -19,10 +19,20 @@
<enabled>false</enabled>
</releases>
</repository>
+ <repository>
+ <id>spring-releases</id>
+ <name>Spring Releases</name>
+ <url>https://repo.spring.io/release</url>
+ </repository>
<!-- jhipster-needle-maven-repository -->
</repositories>
<pluginRepositories>
+ <pluginRepository>
+ <id>spring-releases</id>
+ <name>Spring Releases</name>
+ <url>https://repo.spring.io/release</url>
+ </pluginRepository>
<!-- jhipster-needle-maven-plugin-repository -->
</pluginRepositories>
@@ -158,6 +168,11 @@
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.experimental</groupId>
+ <artifactId>spring-native</artifactId>
+ <version>0.9.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
@@ -838,6 +853,15 @@
Enable the line below to have remote debugging of your application on port 5005
<jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
-->
+ <image>
+ <builder>paketobuildpacks/builder:tiny</builder>
+ <env>
+ <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
+ <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
+ --enable-all-security-services
+ </BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
+ </env>
+ </image>
</configuration>
</plugin> Result is an error:
Log from
|
If I use: <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
--enable-all-security-services
--trace-class-initialization=org.springframework.util.unit.DataSize
</BP_NATIVE_IMAGE_BUILD_ARGUMENTS> I get:
|
This works! <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
--enable-all-security-services
--initialize-at-build-time=org.springframework.util.unit.DataSize
</BP_NATIVE_IMAGE_BUILD_ARGUMENTS> Result:
Although I'm not sure where the binary is created at. 🤔 I'll try it with the AOT plugin. |
@mraible Seems missing the definition of the spring-aot-maven-plugin |
|
Am I running this right?
Results in:
|
Could you please share the project you are trying to build in order to allow me to help by looking at the build configuration ? |
I tried removing the |
Ok I think I have found indeed something weird that I see with your application but not our samples. We will work on solving the related issue before 0.9.1 that is planned next week. In the mean time you can follow spring-attic/spring-native#593. I also need to refine the logback support to support. I will drop a comment here when I will have some news. |
Sorry I created a duplicate at #14289 I'm adding my comment here, as I got a good example for @sdeleuze : JHipster 7 is based on Spring Boot 2.4.3, and thus should work fine with Spring Native Beta using https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#_build_the_native_application -> Here is a sample application, generated today from the main branch, using the default options: https://github.com/jdubois/experimental-jhipster7-native
I'm adding a $500 bug bounty on this ticket, as this is super important. |
Did someone already try with gradle? Looks it should work basically like for maven, right? |
I have not tried this with Gradle.
… On Mar 12, 2021, at 07:44, Frederik Hahne ***@***.***> wrote:
Did someone already try with gradle? Looks it should work basically like for maven, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Speaking of gradle, don't forget we have our Gradle Entreprise server: I have no idea if that could help, but GraalVM is so slow that anything that can help the build could be welcome |
I tried this again today with JHipster 7.0.0 and Spring Native 0.9.1. For the Spring Boot Maven Plugin's configuration, I used: <image>
<builder>paketobuildpacks/builder:tiny</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
--enable-all-security-services
</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
</image> This still fails with the DataSize error:
I added the
... but doesn't run.
|
I gave https://github.com/jdubois/experimental-jhipster7-native another try and I currently see this error (whether I use Zulu or Liberica JDK) :
It does not seems to be related with native, could it be something broken in JHipster |
This issue is stale because it has been open 30 days with no activity. |
Keep it open please.
… On May 6, 2021, at 6:03 PM, github-actions[bot] ***@***.***> wrote:
This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This issue is stale because it has been open 30 days with no activity. |
Still a desirable feature.
… On Jun 6, 2021, at 18:13, github-actions[bot] ***@***.***> wrote:
This issue is stale because it has been open 30 days with no activity.
Our core developers tend to be more verbose on denying. If there is no negative comment, possibly this feature will be accepted.
We are accepting PRs 😃.
Comment or this will be closed in 7 days
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This issue is stale because it has been open 30 days with no activity. |
I believe we can do it! |
@mraible oh yes we will!!! I have some time today, who's with me? |
I hope to look into this sometime in the next week. |
I updated mraible/blog-oauth2#1 to use the latest
However, when I try to run it, I get an error about logback:
Trying this workaround. |
10 minutes later... same error. I tried deleting
Looking at spring-attic/spring-native#777 to try and figure out a solution. |
Tried adding the following to the main @NativeHint(
types = @TypeHint(
access = AccessBits.ALL,
typeNames = {
"springfox.documentation.spi.schema.ModelBuilderPlugin",
"springfox.documentation.spi.schema.ModelPropertyBuilderPlugin",
"springfox.documentation.spi.schema.SyntheticModelProviderPlugin",
"springfox.documentation.spi.schema.TypeNameProviderPlugin",
"springfox.documentation.spi.schema.ViewProviderPlugin",
"springfox.documentation.spi.service.DocumentationPlugin",
"springfox.documentation.spi.service.ApiListingBuilderPlugin",
"springfox.documentation.spi.service.ApiListingScannerPlugin",
"springfox.documentation.spi.service.DefaultsProviderPlugin",
"springfox.documentation.spi.service.ExpandedParameterBuilderPlugin",
"springfox.documentation.spi.service.ModelNamesRegistryFactoryPlugin",
"springfox.documentation.spi.service.OperationBuilderPlugin",
"springfox.documentation.spi.service.OperationModelsProviderPlugin",
"springfox.documentation.spi.service.ParameterBuilderPlugin",
"springfox.documentation.spi.service.ResponseBuilderPlugin",
"springfox.documentation.service.PathDecorator",
"springfox.documentation.spi.DocumentationType"
}
)
) Commit: mraible/blog-oauth2@2de5d06 11 minutes later... the error is:
I believe this is because JHipster uses Undertow by default and only Tomcat is supported. To fix, I tried 10 minutes later... an error happens when starting.
Here's the method it fails in, line 84 is the 4th line: private String resolvePathPrefix() {
String fullExecutablePath;
try { // line 84 is below
fullExecutablePath = decode(this.getClass().getResource("").getPath(), StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
/* try without decoding if this ever happens */
fullExecutablePath = this.getClass().getResource("").getPath();
}
String rootPath = Paths.get(".").toUri().normalize().getPath();
String extractedPath = fullExecutablePath.replace(rootPath, "");
int extractionEndIndex = extractedPath.indexOf("target/");
if (extractionEndIndex <= 0) {
return "";
}
return extractedPath.substring(0, extractionEndIndex);
} That's all I have time for today. Please let me know if y'all know how to fix this issue. |
To work around this issue, I changed
Then, I got an error about HTTP not being enabled. So I added:
This doesn't seem to work as it fails to connect to Keycloak when starting, even though it's available with my browser.
Then, I remembered I had to remove the following lines from # If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:9080:9080
- 127.0.0.1:9443:9443
- 127.0.0.1:10990:10990 Unfortunately, this results in the same error. If I change it to enable https:
And use Okta:
It fails with a new error:
|
Today I realized that my # If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 9080:9080
- 9443:9443
- 10990:10990 I removed all Docker images, rebuilt the image, and tried again with Keycloak. It still fails to connect.
I did notice this error on startup:
So I tried adding the Servlet API as a dependency: <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency> This results in the same issue, so adding the dependency doesn't seem to change anything. Back to Okta. I added the entities classes as resources in hopes of fixing the @NativeHint(
options = { "--enable-url-protocols=http", "--enable-url-protocols=https" },
resources = {
@ResourceHint(patterns = "org/jhipster/blog/config/WebConfigurer.class"),
@ResourceHint(patterns = "org/jhipster/blog/domain/User.class"),
@ResourceHint(patterns = "org/jhipster/blog/domain/Authority.class"),
@ResourceHint(patterns = "org/jhipster/blog/domain/Blog.class"),
@ResourceHint(patterns = "org/jhipster/blog/domain/Post.class"),
@ResourceHint(patterns = "org/jhipster/blog/domain/Tag.class")
},
... This does not solve the problem. Next, I tried replacing the @Bean
public JCacheManagerCustomizer cacheManagerCustomizer() {
return cm -> {
createCache(cm, org.jhipster.blog.repository.UserRepository.USERS_BY_LOGIN_CACHE);
createCache(cm, org.jhipster.blog.repository.UserRepository.USERS_BY_EMAIL_CACHE);
createCache(cm, "User");
createCache(cm, "Authority");
createCache(cm, "User.authorities");
createCache(cm, "Blog");
createCache(cm, "Post");
createCache(cm, "Post.tags");
createCache(cm, "Tag");
createCache(cm, "Tag.entries");
// jhipster-needle-ehcache-add-entry
};
} While building, I noticed that <plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>5.4.32.Final</version>
<executions>
<execution>
<id>enhance</id>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
<enableDirtyTracking>true</enableDirtyTracking>
<enableAssociationManagement>true</enableAssociationManagement>
<enableExtendedEnhancement>false</enableExtendedEnhancement>
</configuration>
</execution>
</executions>
</plugin> Unfortunately, the error message is the same. ¯_(ツ)_/¯ |
PR with the changes I tried: mraible/blog-oauth2#1. |
I tried creating an app today with no database to see if I could get things working. Unfortunately, it fails with a different error:
You can see the PR with changes at mraible/blog-oauth2#2. |
I've been trying for the last day to get things working in mraible/blog-oauth2#1, but I still haven't had any luck. The good news is I did figure out how to talk to Keycloak: you have to use the IP address instead of localhost. I also discovered there are open issues for Spring Native and caching and Liquibase. I tried removing both of them from my project, but it doesn't seem to help. There's still a Hibernate error on startup. |
I'm happy to report that @joshlong and I had great success this week! We documented our findings in mraible/spring-native-examples and I published an article about our experience on LinkedIn. I'm closing this issue and will open a new one to create a module that incorporates our findings. |
Overview of the feature request
Now that Spring Native has Spring Security support, we might be able to integrate native image support into JHipster.
The current version of spring-graalvm-native (v0.8.5) requires Spring Boot 2.4.1 support, so we might have to wait until the next release.
To add, we'll need to add the dependency:
Then, for Maven config:
For Gradle (with a
build.gradle.kts
):Motivation for or Use Case
Fast startup times for JHipster apps.
Related issues or PR
Depends on #13551 (Spring Boot 2.4 support).
The text was updated successfully, but these errors were encountered: