jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.55k stars 4.02k forks source link

Add native image support with GraalVM and Spring Native #13733

Closed mraible closed 3 years ago

mraible commented 3 years ago
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:

org.springframework.experimental:spring-graalvm-native

Then, for Maven config:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot.version}</version>
    <executions>...</executions>
    <configuration>
        ...
        <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
                <BP_BOOT_NATIVE_IMAGE>true</BP_BOOT_NATIVE_IMAGE>
                <BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>
                    --enable-all-security-services
                </BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>
            </env>
        </image>
    </configuration>
</plugin>

For Gradle (with a build.gradle.kts):

tasks.getByName<BootBuildImage>("bootBuildImage") {
    builder = "paketobuildpacks/builder:tiny"
    environment = mapOf(
            "BP_BOOT_NATIVE_IMAGE" to "1",
            "BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS" to """
                --enable-all-security-services
                -Dspring.native.remove-yaml-support=true
            """.trimIndent()
    )
}
Motivation for or Use Case

Fast startup times for JHipster apps.

Related issues or PR

Depends on https://github.com/jhipster/generator-jhipster/pull/13551 (Spring Boot 2.4 support).

github-actions[bot] commented 3 years ago

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 :smiley:. Comment or this will be closed in 7 days

mraible commented 3 years ago

🌴

mraible commented 3 years ago

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:

spring-native 0.9.0-SNAPSHOT is designed to be used with Spring Boot 2.4.3.
DanielFran commented 3 years ago

@mraible The version 0.9.0 is expected for tomorrow: https://github.com/spring-projects-experimental/spring-native/milestones

mraible commented 3 years ago

It's released! https://twitter.com/springcentral/status/1370060267011334148?s=20

mraible commented 3 years ago

I tried it with the main branch and jhipster jdl blog-oauth2. Here are the changes I needed to make to my pom.xml:

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:

Builder lifecycle 'creator' failed with status code 145

Log from ./mvn spring-boot:build-image:

[INFO]     [creator]     Paketo Native Image Buildpack 4.0.0
[INFO]     [creator]       https://github.com/paketo-buildpacks/native-image
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_NATIVE_IMAGE                  true                            enable native image build
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS  --enable-all-security-services  arguments to pass to the native-image command
[INFO]     [creator]       Native Image: Contributing to layer
[INFO]     [creator]         GraalVM Version 21.0.0.2 (Java Version 11.0.10+8-jvmci-21.0-b06)
[INFO]     [creator]         Executing native-image --enable-all-security-services -H:+StaticExecutableWithDynamicLibC -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/jhipster-framework-7.0.0-SNAPSHOT.jar:/workspace/BOOT-INF/lib/spring-context-support-5.3.4.jar:/workspace/BOOT-INF/lib/spring-beans-5.3.4.jar:/workspace/BOOT-INF/lib/spring-context-5.3.4.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-2.4.3.jar:/workspace/BOOT-INF/lib/spring-aop-5.3.4.jar:/workspace/BOOT-INF/lib/aspectjweaver-1.9.6.jar:/workspace/BOOT-INF/lib/logstash-logback-encoder-6.6.jar:/workspace/BOOT-INF/lib/javax.annotation-api-1.3.2.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar:/workspace/BOOT-INF/lib/snakeyaml-1.27.jar:/workspace/BOOT-INF/lib/jackson-module-jaxb-annotations-2.11.4.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.11.4.jar:/workspace/BOOT-INF/lib/jackson-core-2.11.4.jar:/workspace/BOOT-INF/lib/jackson-databind-2.11.4.jar:/workspace/BOOT-INF/lib/jakarta.xml.bind-api-2.3.3.jar:/workspace/BOOT-INF/lib/jakarta.activation-api-1.2.2.jar:/workspace/BOOT-INF/lib/jackson-datatype-hibernate5-2.11.4.jar:/workspace/BOOT-INF/lib/javax.transaction-api-1.3.jar:/workspace/BOOT-INF/lib/jackson-datatype-hppc-2.11.4.jar:/workspace/BOOT-INF/lib/hppc-0.8.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.11.4.jar:/workspace/BOOT-INF/lib/h2-1.4.200.jar:/workspace/BOOT-INF/lib/hazelcast-4.1.1.jar:/workspace/BOOT-INF/lib/hazelcast-hibernate53-2.2.0.jar:/workspace/BOOT-INF/lib/caffeine-2.8.8.jar:/workspace/BOOT-INF/lib/checker-qual-3.8.0.jar:/workspace/BOOT-INF/lib/error_prone_annotations-2.4.0.jar:/workspace/BOOT-INF/lib/hazelcast-spring-4.1.1.jar:/workspace/BOOT-INF/lib/spring-native-0.9.0.jar:/workspace/BOOT-INF/lib/springfox-oas-3.0.0.jar:/workspace/BOOT-INF/lib/swagger-annotations-2.1.2.jar:/workspace/BOOT-INF/lib/swagger-models-2.1.2.jar:/workspace/BOOT-INF/lib/springfox-spi-3.0.0.jar:/workspace/BOOT-INF/lib/springfox-schema-3.0.0.jar:/workspace/BOOT-INF/lib/springfox-core-3.0.0.jar:/workspace/BOOT-INF/lib/springfox-spring-web-3.0.0.jar:/workspace/BOOT-INF/lib/classgraph-4.8.83.jar:/workspace/BOOT-INF/lib/springfox-spring-webmvc-3.0.0.jar:/workspace/BOOT-INF/lib/springfox-spring-webflux-3.0.0.jar:/workspace/BOOT-INF/lib/springfox-swagger-common-3.0.0.jar:/workspace/BOOT-INF/lib/classmate-1.5.1.jar:/workspace/BOOT-INF/lib/slf4j-api-1.7.30.jar:/workspace/BOOT-INF/lib/spring-plugin-core-2.0.0.RELEASE.jar:/workspace/BOOT-INF/lib/spring-plugin-metadata-2.0.0.RELEASE.jar:/workspace/BOOT-INF/lib/springfox-swagger2-3.0.0.jar:/workspace/BOOT-INF/lib/swagger-annotations-1.5.20.jar:/workspace/BOOT-INF/lib/swagger-models-1.5.20.jar:/workspace/BOOT-INF/lib/springfox-bean-validators-3.0.0.jar:/workspace/BOOT-INF/lib/HikariCP-3.4.5.jar:/workspace/BOOT-INF/lib/commons-lang3-3.11.jar:/workspace/BOOT-INF/lib/cache-api-1.1.1.jar:/workspace/BOOT-INF/lib/mysql-connector-java-8.0.22.jar:/workspace/BOOT-INF/lib/protobuf-java-3.11.4.jar:/workspace/BOOT-INF/lib/hibernate-jpamodelgen-5.4.28.Final.jar:/workspace/BOOT-INF/lib/jboss-logging-3.4.1.Final.jar:/workspace/BOOT-INF/lib/jaxb-api-2.3.1.jar:/workspace/BOOT-INF/lib/jaxb-runtime-2.3.3.jar:/workspace/BOOT-INF/lib/txw2-2.3.3.jar:/workspace/BOOT-INF/lib/istack-commons-runtime-3.0.11.jar:/workspace/BOOT-INF/lib/jakarta.activation-1.2.2.jar:/workspace/BOOT-INF/lib/hibernate-core-5.4.28.Final.jar:/workspace/BOOT-INF/lib/javax.persistence-api-2.2.jar:/workspace/BOOT-INF/lib/javassist-3.27.0-GA.jar:/workspace/BOOT-INF/lib/byte-buddy-1.10.20.jar:/workspace/BOOT-INF/lib/antlr-2.7.7.jar:/workspace/BOOT-INF/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar:/workspace/BOOT-INF/lib/jandex-2.2.3.Final.jar:/workspace/BOOT-INF/lib/javax.activation-api-1.2.0.jar:/workspace/BOOT-INF/lib/dom4j-2.1.3.jar:/workspace/BOOT-INF/lib/hibernate-commons-annotations-5.1.2.Final.jar:/workspace/BOOT-INF/lib/hibernate-validator-6.1.7.Final.jar:/workspace/BOOT-INF/lib/jakarta.validation-api-2.0.2.jar:/workspace/BOOT-INF/lib/liquibase-core-4.3.1.jar:/workspace/BOOT-INF/lib/mapstruct-1.4.2.Final.jar:/workspace/BOOT-INF/lib/spring-boot-loader-tools-2.4.3.jar:/workspace/BOOT-INF/lib/commons-compress-1.20.jar:/workspace/BOOT-INF/lib/spring-core-5.3.4.jar:/workspace/BOOT-INF/lib/spring-jcl-5.3.4.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-autoconfigure-2.4.3.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-2.4.3.jar:/workspace/BOOT-INF/lib/micrometer-core-1.6.4.jar:/workspace/BOOT-INF/lib/HdrHistogram-2.1.12.jar:/workspace/BOOT-INF/lib/LatencyUtils-2.0.3.jar:/workspace/BOOT-INF/lib/spring-jdbc-5.3.4.jar:/workspace/BOOT-INF/lib/jakarta.transaction-api-1.3.3.jar:/workspace/BOOT-INF/lib/jakarta.persistence-api-2.2.3.jar:/workspace/BOOT-INF/lib/spring-data-jpa-2.4.5.jar:/workspace/BOOT-INF/lib/spring-orm-5.3.4.jar:/workspace/BOOT-INF/lib/spring-tx-5.3.4.jar:/workspace/BOOT-INF/lib/spring-aspects-5.3.4.jar:/workspace/BOOT-INF/lib/logback-classic-1.2.3.jar:/workspace/BOOT-INF/lib/logback-core-1.2.3.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.13.3.jar:/workspace/BOOT-INF/lib/log4j-api-2.13.3.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-1.7.30.jar:/workspace/BOOT-INF/lib/jakarta.mail-1.6.5.jar:/workspace/BOOT-INF/lib/thymeleaf-spring5-3.0.12.RELEASE.jar:/workspace/BOOT-INF/lib/thymeleaf-3.0.12.RELEASE.jar:/workspace/BOOT-INF/lib/attoparser-2.0.5.RELEASE.jar:/workspace/BOOT-INF/lib/unbescape-1.1.6.RELEASE.jar:/workspace/BOOT-INF/lib/thymeleaf-extras-java8time-3.0.4.RELEASE.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.11.4.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.11.4.jar:/workspace/BOOT-INF/lib/spring-web-5.3.4.jar:/workspace/BOOT-INF/lib/spring-webmvc-5.3.4.jar:/workspace/BOOT-INF/lib/spring-expression-5.3.4.jar:/workspace/BOOT-INF/lib/json-smart-2.3.jar:/workspace/BOOT-INF/lib/accessors-smart-1.2.jar:/workspace/BOOT-INF/lib/asm-5.0.4.jar:/workspace/BOOT-INF/lib/spring-boot-2.4.3.jar:/workspace/BOOT-INF/lib/spring-security-core-5.4.5.jar:/workspace/BOOT-INF/lib/spring-security-web-5.4.5.jar:/workspace/BOOT-INF/lib/problem-spring-web-0.26.2.jar:/workspace/BOOT-INF/lib/problem-violations-0.26.2.jar:/workspace/BOOT-INF/lib/problem-spring-common-0.26.2.jar:/workspace/BOOT-INF/lib/apiguardian-api-1.1.0.jar:/workspace/BOOT-INF/lib/jsr305-3.0.2.jar:/workspace/BOOT-INF/lib/problem-0.25.0.jar:/workspace/BOOT-INF/lib/jackson-datatype-problem-0.25.0.jar:/workspace/BOOT-INF/lib/faux-pas-0.8.0.jar:/workspace/BOOT-INF/lib/validation-api-2.0.1.Final.jar:/workspace/BOOT-INF/lib/spring-security-config-5.4.5.jar:/workspace/BOOT-INF/lib/spring-security-oauth2-client-5.4.5.jar:/workspace/BOOT-INF/lib/oauth2-oidc-sdk-8.36.jar:/workspace/BOOT-INF/lib/jcip-annotations-1.0-1.jar:/workspace/BOOT-INF/lib/content-type-2.1.jar:/workspace/BOOT-INF/lib/lang-tag-1.4.4.jar:/workspace/BOOT-INF/lib/spring-security-oauth2-core-5.4.5.jar:/workspace/BOOT-INF/lib/spring-security-oauth2-jose-5.4.5.jar:/workspace/BOOT-INF/lib/nimbus-jose-jwt-8.20.2.jar:/workspace/BOOT-INF/lib/spring-security-oauth2-resource-server-5.4.5.jar:/workspace/BOOT-INF/lib/spring-security-data-5.4.5.jar:/workspace/BOOT-INF/lib/spring-data-commons-2.4.5.jar:/workspace/BOOT-INF/lib/micrometer-registry-prometheus-1.6.4.jar:/workspace/BOOT-INF/lib/simpleclient_common-0.9.0.jar:/workspace/BOOT-INF/lib/simpleclient-0.10.0.jar:/workspace/BOOT-INF/lib/metrics-core-4.1.17.jar:/workspace/BOOT-INF/lib/undertow-core-2.2.4.Final.jar:/workspace/BOOT-INF/lib/xnio-api-3.8.0.Final.jar:/workspace/BOOT-INF/lib/wildfly-common-1.5.2.Final.jar:/workspace/BOOT-INF/lib/wildfly-client-config-1.0.1.Final.jar:/workspace/BOOT-INF/lib/xnio-nio-3.8.0.Final.jar:/workspace/BOOT-INF/lib/jboss-threads-3.1.0.Final.jar:/workspace/BOOT-INF/lib/undertow-servlet-2.2.4.Final.jar:/workspace/BOOT-INF/lib/jboss-annotations-api_1.3_spec-2.0.1.Final.jar:/workspace/BOOT-INF/lib/undertow-websockets-jsr-2.2.4.Final.jar:/workspace/BOOT-INF/lib/jboss-websocket-api_1.1_spec-2.0.0.Final.jar:/workspace/BOOT-INF/lib/jakarta.servlet-api-4.0.4.jar:/workspace/BOOT-INF/lib/jakarta.el-3.0.3.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-2.4.3.jar com.jhipster.demo.blog.BlogApp
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:169]    classlist:  14,441.36 ms,  2.69 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:169]        (cap):   1,047.56 ms,  2.69 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:169]        setup:   4,861.69 ms,  2.69 GB
[INFO]     [creator]     To see how the classes got initialized, use --trace-class-initialization=org.springframework.util.unit.DataSize
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:169]     analysis:  13,883.12 ms,  2.69 GB
[INFO]     [creator]     Error: Classes that should be initialized at run time got initialized during image building:
[INFO]     [creator]      org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize
[INFO]     [creator]     
[INFO]     [creator]     Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO]     [creator]     Error: Image build request failed with exit status 1
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:29 min
[INFO] Finished at: 2021-03-11T10:38:14-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image (default-cli) on project blog: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:build-image failed: Builder lifecycle 'creator' failed with status code 145 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Execution time: 3 min. 31 s.                                
mraible commented 3 years ago

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:

[INFO]     [creator]      org.springframework.util.unit.DataSize was unintentionally initialized at build time. 
org.springframework.util.unit.DataSize has been initialized without the native-image initialization 
instrumentation and the stack trace can't be tracked. Try marking this class for build-time initialization with -
-initialize-at-build-time=org.springframework.util.unit.DataSize
sdeleuze commented 3 years ago

Did you configured the AOT plugin as documented here and here ?

mraible commented 3 years ago

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:

[INFO] Successfully built image 'docker.io/library/blog:0.0.1-SNAPSHOT'
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  06:47 min
[INFO] Finished at: 2021-03-11T10:53:20-07:00
[INFO] ------------------------------------------------------------------------

Although I'm not sure where the binary is created at. 🤔

I'll try it with the AOT plugin.

DanielFran commented 3 years ago

@mraible Seems missing the definition of the spring-aot-maven-plugin

sdeleuze commented 3 years ago

DataSize error is documented here it means you don't have native support. Happy to refine error messages with a repro if needed.

mraible commented 3 years ago

Am I running this right?

docker run -it -p8080:8080 docker.io/library/blog:0.0.1-SNAPSHOT

Results in:

/workspace/com.jhipster.demo.blog.BlogApp: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
sdeleuze commented 3 years ago

Could you please share the project you are trying to build in order to allow me to help by looking at the build configuration ?

mraible commented 3 years ago

I tried removing the DataSize flag and adding the AOT plugin. It fails to build with the DataSize error again. I created a repo and PR. https://github.com/mraible/blog-oauth2/pull/1

sdeleuze commented 3 years ago

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 https://github.com/spring-projects-experimental/spring-native/issues/593. I also need to refine the logback support to support. I will drop a comment here when I will have some news.

jdubois commented 3 years ago

Sorry I created a duplicate at https://github.com/jhipster/generator-jhipster/issues/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.

atomfrede commented 3 years ago

Did someone already try with gradle? Looks it should work basically like for maven, right?

mraible commented 3 years ago

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.

jdubois commented 3 years ago

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

mraible commented 3 years ago

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:

[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:160]    classlist:   7,071.23 ms,  1.69 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:160]        (cap):     579.06 ms,  1.69 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:160]        setup:   2,780.17 ms,  1.69 GB
[INFO]     [creator]     To see how the classes got initialized, use --trace-class-initialization=org.springframework.util.unit.DataSize
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/com.jhipster.demo.blog.BlogApp:160]     analysis:   8,191.56 ms,  1.70 GB
[INFO]     [creator]     Error: Classes that should be initialized at run time got initialized during image building:
[INFO]     [creator]      org.springframework.util.unit.DataSize was unintentionally initialized at build time. To see why org.springframework.util.unit.DataSize got initialized use --trace-class-initialization=org.springframework.util.unit.DataSize
[INFO]     [creator]     
[INFO]     [creator]     Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO]     [creator]     Error: Image build request failed with exit status 1
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:25 min
[INFO] Finished at: 2021-03-23T11:52:42-06:00
[INFO] ------------------------------------------------------------------------

I added the --initialize-at-build-time=org.springframework.util.unit.DataSize flag to the config and tried again. It builds:

[INFO] Successfully built image 'docker.io/library/blog:0.0.1-SNAPSHOT'
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:14 min
[INFO] Finished at: 2021-03-23T11:55:50-06:00
[INFO] ------------------------------------------------------------------------

... but doesn't run.

$ docker run -it -p8080:8080 docker.io/library/blog:0.0.1-SNAPSHOT
/workspace/com.jhipster.demo.blog.BlogApp: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
sdeleuze commented 3 years ago

@mraible This error just means no native support has been provided. Have you configured Spring AOT plugin and spring-native dependency?

Be also aware that we make progress on Jhipster support via https://github.com/spring-projects-experimental/spring-native/issues/600, I did some fixes in Spring Native side, @jdubois did other ones on JHipster side that I will test in order to send you a feedback.

mraible commented 3 years ago

@sdeleuze Yes, I have. I'll follow @jdubois work.

diff --git a/pom.xml b/pom.xml
index c02b247..421e333 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,10 +12,20 @@
     <name>Blog</name>

     <repositories>
+        <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>

@@ -300,6 +310,11 @@
             <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.experimental</groupId>
+            <artifactId>spring-native</artifactId>
+            <version>0.9.1</version>
+        </dependency>
         <!-- jhipster-needle-maven-add-dependency -->
     </dependencies>

@@ -784,6 +799,25 @@
                     <artifactId>sonar-maven-plugin</artifactId>
                     <version>${sonar-maven-plugin.version}</version>
                 </plugin>
+                <plugin>
+                    <groupId>org.springframework.experimental</groupId>
+                    <artifactId>spring-aot-maven-plugin</artifactId>
+                    <version>0.9.1</version>
+                    <executions>
+                        <execution>
+                            <id>test-generate</id>
+                            <goals>
+                                <goal>test-generate</goal>
+                            </goals>
+                        </execution>
+                        <execution>
+                            <id>generate</id>
+                            <goals>
+                                <goal>generate</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
                 <plugin>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
@@ -802,6 +836,16 @@
                         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
+                                    --initialize-at-build-time=org.springframework.util.unit.DataSize
+                                </BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
+                            </env>
+                        </image>
                     </configuration>

                 </plugin>
jdubois commented 3 years ago

@mraible thanks - I went much further and I had about 10 more issues that I have solved. This is only the beginning of the road! Not sure when I'll document this, or if I should (I'll try to solve some of those errors). My biggest issue is that it's horribly slow to test....

sdeleuze commented 3 years ago

@mraible Ok we will try to identify with Julien what triggers the strange behavior you see.

@jdubois I agree that the slow feedback loop is the main pain point, that's why we collaborate with GraalVM team to limit this issue. We have some upcoming WIP improvements that will likely allow to check much more things on JVM side.

sdeleuze commented 3 years ago

I gave https://github.com/jdubois/experimental-jhipster7-native another try and I currently see this error (whether I use Zulu or Liberica JDK) :

constituent[42]: file:/home/seb/.sdkman/candidates/maven/current/lib/javax.inject-1.jar
---------------------------------------------------
Exception in thread "main" java.lang.AssertionError
    at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
    at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
    at jdk.compiler/com.sun.tools.javac.comp.Modules.enter(Modules.java:247)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:837)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ImplicitCompleter.complete(JavacProcessingEnvironment.java:1529)

It does not seems to be related with native, could it be something broken in JHipster 7.0.0-SNAPSHOT?

github-actions[bot] commented 3 years ago

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 :smiley:. Comment or this will be closed in 7 days

mraible commented 3 years ago

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.

github-actions[bot] commented 3 years ago

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 :smiley:. Comment or this will be closed in 7 days

mraible commented 3 years ago

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.

github-actions[bot] commented 3 years ago

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 :smiley:. Comment or this will be closed in 7 days

mraible commented 3 years ago

I believe we can do it!

jdubois commented 3 years ago

@mraible oh yes we will!!! I have some time today, who's with me?

mraible commented 3 years ago

I hope to look into this sometime in the next week.

mraible commented 3 years ago

I updated https://github.com/mraible/blog-oauth2/pull/1 to use the latest main branch and Spring Native v0.10.2. It builds successfully.

[INFO] Successfully built image 'docker.io/library/blog:0.0.1-SNAPSHOT'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18:36 min
[INFO] Finished at: 2021-08-20T15:29:48-06:00
[INFO] ------------------------------------------------------------------------

However, when I try to run it, I get an error about logback:

$ docker run -it -p8080:8080 docker.io/library/blog:0.0.1-SNAPSHOT

Logging system failed to initialize using configuration from 'null'
java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.xml
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:168)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:313)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:282)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)

Trying this workaround.

mraible commented 3 years ago

10 minutes later... same error. I tried deleting logback-spring.xml as a workaround. New error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Native reflection configuration for springfox.documentation.spi.schema.ModelBuilderPlugin is missing.

Action:

Native configuration for a class accessed reflectively is likely missing.
You can try to configure native hints in order to specify it explicitly.
See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-hints for more details.

Looking at https://github.com/spring-projects-experimental/spring-native/issues/777 to try and figure out a solution.

mraible commented 3 years ago

Tried adding the following to the main BlogApp class:

@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: https://github.com/mraible/blog-oauth2/pull/1/commits/2de5d068c2125d7b4176c6eac18eb48327788d6d

11 minutes later... the error is:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'undertowServletWebServerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: 
Initialization of bean failed; nested exception is java.lang.NullPointerException

I believe this is because JHipster uses Undertow by default and only Tomcat is supported. To fix, I tried %s/undertow/tomcat/g in pom.xml and refactored a test to use Tomcat.

10 minutes later... an error happens when starting.

Caused by: java.lang.NullPointerException: null
    at org.jhipster.blog.config.WebConfigurer.resolvePathPrefix(WebConfigurer.java:84) ~[org.jhipster.blog.BlogApp:na]
    at org.jhipster.blog.config.WebConfigurer.setLocationForStaticAssets(WebConfigurer.java:70) ~[org.jhipster.blog.BlogApp:na]
    at org.jhipster.blog.config.WebConfigurer.customize(WebConfigurer.java:63) ~[org.jhipster.blog.BlogApp:na]
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.lambda$postProcessBeforeInitialization$0(WebServerFactoryCustomizerBeanPostProcessor.java:72) ~[org.jhipster.blog.BlogApp:2.5.3]

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.

mraible commented 3 years ago

To work around this issue, I changed WebConfigurer so it doesn't call resolvePathPrefix():

String prefixPath = "./"; // resolvePathPrefix();

Then, I got an error about HTTP not being enabled. So I added:

@NativeHint(
    options = "--enable-url-protocols=http",
...

This doesn't seem to work as it fails to connect to Keycloak when starting, even though it's available with my browser.

Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for 
"http://localhost:9080/auth/realms/jhipster/.well-known/openid-configuration": Connection refused (Connection refused); 
nested exception is java.net.ConnectException: Connection refused (Connection refused)

Then, I remembered I had to remove the following lines from src/main/docker/keycloak.yml for it to be accessible from outside.

    # 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:

{"--enable-url-protocols=http","--enable-url-protocols=https"}

And use Okta:

docker run -it -p8080:8080 -e SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=https://{oktaDomain/oauth2/default -e SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID={clientId} -e SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET={clientSecret} docker.io/library/blog:0.0.1-SNAPSHOT

It fails with a new error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: 'entityManagerFactory' depends on missing bean 'cacheManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' available
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[org.jhipster.blog.BlogApp:2.5.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[org.jhipster.blog.BlogApp:2.5.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[org.jhipster.blog.BlogApp:2.5.3]
        at org.jhipster.blog.BlogApp.main(BlogApp.java:101) ~[org.jhipster.blog.BlogApp:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cacheManager' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:863) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1344) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:309) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[na:na]
        ... 9 common frames omitted
mraible commented 3 years ago

Today I realized that my keycloak.yml should still have the ports, but not the IP. So I changed it to:

    # 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.

Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for 
"http://localhost:9080/auth/realms/jhipster/.well-known/openid-configuration": Connection refused (Connection refused); 
nested exception is java.net.ConnectException: Connection refused (Connection refused)

I did notice this error on startup:

2021-08-23 17:29:17.762 DEBUG 1 --- [           main] ocalVariableTableParameterNameDiscoverer : ASM ClassReader failed to parse class file [class org.jhipster.blog.web.filter.OAuth2RefreshTokensWebFilter], probably due to a new Java class file version that isn't supported yet - unable to determine constructor/method parameter names

java.lang.IllegalArgumentException: Could not find class [javax.servlet.http.HttpServletResponse]
        at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334) ~[na:na]
        at org.springframework.core.LocalVariableTableParameterNameDiscoverer$LocalVariableTableVisitor.resolveExecutable(LocalVariableTableParameterNameDiscoverer.java:233) ~[na:na]
        at org.springframework.core.LocalVariableTableParameterNameDiscoverer$LocalVariableTableVisitor.visitEnd(LocalVariableTableParameterNameDiscoverer.java:225) ~[na:na]
        at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1518) ~[na:na]
        at org.springframework.asm.ClassReader.accept(ClassReader.java:744) ~[na:na]

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 No bean named 'cacheManager' issue.

@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 getClass() calls in CacheConfiguration to just use strings for cache names.

@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 spring-boot-starter-data-jpa and Hibernate needs some bytecode enhancement. I added the following to my pom.xml and reverted the change to CacheConfiguration.

<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. ¯_(ツ)_/¯

mraible commented 3 years ago

PR with the changes I tried: https://github.com/mraible/blog-oauth2/pull/1.

mraible commented 3 years ago

I tried creating an app today with no database to see if I could get things working. Unfortunately, it fails with a different error:

2021-08-30 19:31:45.961 DEBUG 1 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : Application failed to start due to an exception

java.lang.NoSuchMethodException: org.springframework.plugin.core.support.PluginRegistryFactoryBean.<init>()
    at java.lang.Class.getConstructor0(DynamicHub.java:3349) ~[na:na]
    at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2553) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1308) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[na:na]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[com.jhipster.demo.blog.BlogApp:na]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[com.jhipster.demo.blog.BlogApp:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[com.jhipster.demo.blog.BlogApp:na]
    at com.jhipster.demo.blog.BlogApp.main(BlogApp.java:96) ~[com.jhipster.demo.blog.BlogApp:na]

2021-08-30 19:31:45.961 ERROR 1 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Native reflection configuration for org.springframework.plugin.core.support.PluginRegistryFactoryBean.<init>() is missing.

Action:

Native configuration for a method accessed reflectively is likely missing.
You can try to configure native hints in order to specify it explicitly.
See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-hints for more details.

You can see the PR with changes at https://github.com/mraible/blog-oauth2/pull/2.

mraible commented 3 years ago

I've been trying for the last day to get things working in https://github.com/mraible/blog-oauth2/pull/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.

mraible commented 3 years ago

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.