spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
710 stars 391 forks source link

Unable to build a native image using Native Build tools #1060

Closed iAMSagar44 closed 2 months ago

iAMSagar44 commented 2 months ago

Hi,

I am unable to build a native image using the maven build tools (using the graalvm native maven plugin).

I have a very simple Spring Shell application, using the following versions -

The pom.xml has the following build plugins -

<plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <configuration>
                    <metadataRepository>
                        <enabled>true</enabled>
                    </metadataRepository>
                </configuration>
            </plugin>
        </plugins>

When I try to build a native image using the following command ./mvnw native:compile -Pnative, I can see in the logs -

[INFO] >>> native:0.9.28:compile (default-cli) > package @ data-loader >>>
[INFO]
[INFO] --- native:0.9.28:add-reachability-metadata (add-reachability-metadata) @ data-loader ---
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.1.Final]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.1.Final]: Latest version not found!
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.1.Final]: missing.
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.1.Final]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.hibernate.validator:hibernate-validator:8.0.1.Final]: Configuration directory is org.hibernate.validator/hibernate-validator/7.0.4.Final
[INFO] [graalvm reachability metadata repository for org.jboss.logging:jboss-logging:3.5.3.Final]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.jboss.logging:jboss-logging:3.5.3.Final]: Configuration directory is org.jboss.logging/jboss-logging/3.5.0.Final
**[INFO] [graalvm reachability metadata repository for org.jline:jline-console:3.26.0]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.jline:jline-console:3.26.0]: Latest version not found!
[INFO] [graalvm reachability metadata repository for org.jline:jline-console:3.26.0]: missing.
[INFO] [graalvm reachability metadata repository for org.jline:jline-terminal:3.26.0]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.jline:jline-terminal:3.26.0]: Latest version not found!
[INFO] [graalvm reachability metadata repository for org.jline:jline-terminal:3.26.0]: missing.**
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.14]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.14]: Configuration directory is ch.qos.logback/logback-classic/1.4.1
[INFO] [graalvm reachability metadata repository for com.fasterxml.jackson.core:jackson-databind:2.15.4]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for com.fasterxml.jackson.core:jackson-databind:2.15.4]: Configuration directory is com.fasterxml.jackson.core/jackson-databind/2.15.2
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.20]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.1.20]: Configuration directory is org.apache.tomcat.embed/tomcat-embed-core/10.0.20

The application then starts as follows, and the native image does not get built.

2024-04-25T19:31:03.282+10:00  INFO 22248 --- [           main] c.e.d.DataLoaderApplicationTests         : Starting DataLoaderApplicationTests using Java 21.0.3 with PID 22248 (started by sagar in /Users/sagar/MrRobot/Spring-central/Spring-AI/data-indexer-cli)
2024-04-25T19:31:03.284+10:00  INFO 22248 --- [           main] c.e.d.DataLoaderApplicationTests         : No active profile set, falling back to 1 default profile: "default"
**2024-04-25T19:31:04.682+10:00  WARN 22248 --- [           main] org.jline                                : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)**
2024-04-25T19:31:05.048+10:00  INFO 22248 --- [           main] c.e.d.DataLoaderApplicationTests         : Started DataLoaderApplicationTests in 2.313 seconds (process running for 3.711)

Is the issue because of the jline version being used in Spring Shell 3.2.4 (or 3.2.3 - had the same issue in that version too)?

jvalkeal commented 2 months ago

I think DataLoaderApplicationTests hangs up(as interactive shell takes over). There's some fixes for this in upcoming 3.3.x but essentially you need to make sure interactive shell doesn't start with tests.

This should fail with normal build with tests if this is the case?

iAMSagar44 commented 2 months ago

Thanks @jvalkeal for the response. I was able to successfully build a native image by skipping the tests (used this command ./mvnw native:compile -Pnative -DskipTests=true.