Spring Boot Native: no valid dependencies for native-image-svm - spring-boot

I've just upgraded several projects to Java 19, Spring Boot 3.0.2, Kotlin 1.8.0 with Maven and I'd like Spring Boot to generate native images.
<java.version>19</java.version>
<kotlin.version>1.8.0</kotlin.version>
The relevant part of the configuration of spring-boot-maven-plugin is:
<configuration>
<image>
<env>
<BP_JVM_VERSION>19.*</BP_JVM_VERSION>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BPE_APPEND_JAVA_TOOL_OPTIONS>-XX:+HeapDumpOnOutOfMemoryError -XX:MaxDirectMemorySize=64M</BPE_APPEND_JAVA_TOOL_OPTIONS>
<BPE_DELIM_JAVA_TOOL_OPTIONS xml:space="preserve"> </BPE_DELIM_JAVA_TOOL_OPTIONS>
</env>
</image>
</configuration>
However, when I build one of the projects with
mvn -Pnative spring-boot:build-image
then the build fails with the following error message:
[INFO] [creator] Paketo Buildpack for BellSoft Liberica 9.10.2
[INFO] [creator] unable to find dependency
[INFO] [creator] no valid dependencies for native-image-svm, 19.*, and io.paketo.stacks.tiny in [(jdk, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 8.0.362, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 11.0.18, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (native-image-svm, 11.0.17, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 17.0.6, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 17.0.6, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (native-image-svm, 17.0.5, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jdk, 19.0.2, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *]) (jre, 19.0.2, [io.buildpacks.stacks.bionic io.paketo.stacks.tiny *])]
[INFO] [creator] ERROR: failed to build: exit status 1
What's missing?
Update: When I downgrade to Java 17 with Kotlin 1.7.21, then the build succeeds and apparently there's no support yet in the Liberica Native Image Kit for Java 19. https://bell-sw.com/pages/downloads/native-image-kit/#/nik-22-19

Let me provide you with alternatives to downgrading your Java version (in case you e.g. want to use virtual threads).
You might be successful using GraalVM instead of Liberica NIK. You can configure this in your pom.xml as described in the section Use an alternative native image toolkit of the Spring Boot Documentation:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
</buildpacks>
</image>
</configuration>
</plugin>
Since The GraalVM Buildpack supports Java 19, you should be able to use it:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/graalvm</buildpack>
<buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
</buildpacks>
<env>
<BP_JVM_VERSION>19.0.1</BP_JVM_VERSION>
</env>
</image>
</configuration>
</plugin>
As an alternative, it would be possible to not use buildpacks for creating the native image but instead create a native executable using mvn -Pnative package See Getting started with Native Build Tools.
Then, you could create your own docker image (e.g. using a Dockerfile or similar) and include that.

When I downgrade to Java 17 with Kotlin 1.7.21, then the build succeeds and apparently there's no support yet in the Liberica Native Image Kit for Java 19. https://bell-sw.com/pages/downloads/native-image-kit/#/nik-22-19.
Furthermore, it's stated on the same page:
What Java versions are supported by NIK?
Two latest Java LTS versions, Java 11 and Java 17, are supported by Liberica NIK.

Related

How do I specify the type of asset when I publish asset to mulesoft's exchange?

When I was building a CI/CD with github actions, I ran into the following problems.
[INFO] ------------------------------------------------------------
[INFO] Publication status: error
[INFO] ------------------------------------------------------------
[INFO] Steps:
[INFO] - Description: Publishing asset
[INFO] - Status: error
[INFO] - Errors: [The asset is invalid, Error while trying to set type: app. Expected type is: rest-api.]
[INFO] .........................................
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
The following is my maven configuration
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</sharedLibrary>
</sharedLibraries>
<cloudhub2Deployment>
<uri>https://anypoint.mulesoft.com</uri>
<provider>MC</provider>
<environment>DEV</environment>
<target>****</target>
<muleVersion>4.4.0</muleVersion>
<server>anypoint-exchange-v3</server>
<businessGroup>AAAA</businessGroup>
<businessGroupId>*********</businessGroupId>
<applicationName>test-app2023</applicationName>
<replicas>1</replicas>
<vCores>0.1</vCores>
<deploymentSettings>
<http>
<inbound>
<publicUrl>tes-app2023t.anypoint.com</publicUrl>
</inbound>
</http>
<lastMileSecurity>false</lastMileSecurity>
<forwardSslSession>false</forwardSslSession>
<generateDefaultPublicUrl>true</generateDefaultPublicUrl>
</deploymentSettings>
<server>****</server>
<properties>
<anypoint.platform.base_uri>https://anypoint.mulesoft.com/</anypoint.platform.base_uri>
<anypoint.platform.client_id>****</anypoint.platform.client_id>
<anypoint.platform.client_secret>****</anypoint.platform.client_secret>
<anypoint.platform.analytics_base_uri>https://analytics-ingest.anypoint.mulesoft.com</anypoint.platform.analytics_base_uri>
</properties>
</cloudhub2Deployment>
<classifier>mule-application</classifier>
</configuration>
</plugin>
How should I properly set my exchange asset to rest-api instead of app?
I checked mulesoft's documentation and couldn't find a way to define...
The Mule Maven Plugin shared is configured for a Mule application. The asset type is set by the <classifier> element. Since this is a Mule application it is a correct type. In Anypoint Exchange a rest-api asset type identify an API description composed of RAML or OAS files. The Mule Maven Plugin is not compatible with that kind of assets, which makes sense because they are not built with Maven. If the Mule application implements a REST API, it is still a Mule application asset.
On the other hand if your asset is really RAML or OAS files you should use the Anypoint CLI instead to publish it to Anypoint Exchange. Read https://docs.mulesoft.com/exchange/to-create-an-asset for the different ways to create different types of assets.
I solved this problem myself.
The problem was caused by the duplication of the asset name of the API (raml) published from Design center and the asset name of the API (app) published from Maven.
I changed the artifactId in the pom.xml and solved the problem.
<groupId>****</groupId>
<artifactId>{asset name}</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>

Buildpack: customisation needed to add opentelemetry

I'm checking into buildpacks to create container images without Dockerfiles. Spring Boot’s build plugin uses a BuildPack builder image which will automatically detect that it's a spring boot application and builds the relevant image for us.
Now my question is, When i am running below maven command
mvn -f $GITHUB_WORKSPACE/pom.xml -pl service spring-boot:build-image -B -e -Dspring-boot.build-image.imageName="${{steps.acr_repo_server.outputs.acr_server}}/${{steps.acr_repo_server.outputs.acr_repository_name}}/${{inputs.microservice_name}}:${{ inputs.build_version }}" -Dmaven.test.skip=true -Dmaven.repo.local=${{ github.workspace }}/.m2/repository
I can see it internally uses below 6 buildpack for the application.
[INFO] [creator] 6 of 24 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.2.4
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 9.3.7
[INFO] [creator] paketo-buildpacks/syft 1.12.0
[INFO] [creator] paketo-buildpacks/executable-jar 6.2.4
[INFO] [creator] paketo-buildpacks/dist-zip 5.2.4
[INFO] [creator] paketo-buildpacks/spring-boot 5.12.0
How can i add or ask maven to add this buildpack paketo-buildpacks/opentelemetry as well ? Is there any way to customise it or manually pass open telemetry build pack as an argument.
You can add Opentelemetry to the end of the existing buildpack list. See the example in the docs here.
pack build samples/java -b urn:cnb:builder:paketo-buildpacks/java -b paketo-buildpacks/opentelemetry -e BP_OPENTELEMETRY_ENABLED=true
With Spring Boot see the Maven and Gradle examples.
<project>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>urn:cnb:builder:paketo-buildpacks/java</buildpack>
<buildpack>gcr.io/paketo-buildpacks/opentelemetry</buildpack>
</buildpacks>
<env>
<BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
</env>
</image>
</configuration>
</plugin>
</plugins>
</build>
</project>

how maven version working, can't update ojdbc8 version

Example code:
https://github.com/yszzu1/mvn-version-test
Question:
1. why the admin-module always using ojdbc8 19.3.0.0 ?
# mvn dependency:tree
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) # admin-module ---
[INFO] org.example:admin-module:jar:3.12.0
[INFO] +- org.example:db-module:jar:3.12.0:compile
[INFO] | \- com.oracle.database.jdbc:ojdbc8:jar:19.3.0.0:compile
as we can see that the db-module is using 19.9.0.0
2. even after upgrade the db-module pom.xml with
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>21.1.0.0</version>
</dependency>
, the admin-module mvn dependency:tree is still showing 19.3.0.0
mvn & windows & JVM version:
# mvn --version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: C:\Users\shuayan\Documents\open\apache-maven-3.8.5
Java version: 1.8.0_321, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_321\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"
BTW: I have read these two wiki
https://www.mojohaus.org/versions-maven-plugin/faq.html
https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN401
That is how dependency management works in maven.
you have defined direct ojdbc8 dependency for db-module and it does work as expected
for admin-module the situation is "bit different":
it depends directly on db-module, and ojdbc8 is now a transitive dependency
it inherits ojdbc8 version from spring-boot-starter-parent (actually from spring-boot-dependencies)
if you really want to use spring-boot-starter-parent as a parent you need to configure your project in the following way:
/pom.xml:
<properties>
...
<ojdbc.version>21.1.0.0</ojdbc.version>
<oracle-database.version>21.1.0.0</oracle-database.version>
...
</properties>
/db-module/pom.xml:
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<!-- omit version information -->
</dependency>
</dependencies>

How to fix 'Openshift has not been detected' on fabric8 via maven during deployment

I would like to use Openshift's S2I-build to deploy to Openshift where it is a private cloud.
So, I am trying to deploy my Spring Boot app to Openshift with the command
mvn fabric8:deploy but it got error and failed to build the application. It always returned Openshift platform has been specified but Openshift has not been detected! but I got oc client installed on Windows 10 and it works properly.
I searched it on Google for a long time but got no answer. Could anyone help on this issue?
Thanks.
Here is part of my pom.xml
<properties>
<java.version>1.8</java.version>
<fabric8.mode>openshift</fabric8.mode>
<fabric8.namespace>example</fabric8.namespace>
<fabric8.username>acc</fabric8.username>
<fabric8.password>pwd</fabric8.password>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>4.1.0</version>
<executions>
<execution>
<id>fmp</id>
<goals>
<goal>resource</goal>
<goal>helm</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The actual error:
[INFO] F8: Running in OpenShift mode
[INFO] F8: Using OpenShift build with strategy S2I
[WARNING] F8: Cannot access cluster for detecting mode: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[INFO] F8: Running generator spring-boot
[INFO] F8: spring-boot: Using Docker image fabric8/s2i-java:2.3 as base / builder
[WARNING] F8: Cannot access cluster for detecting mode: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
[ERROR] F8: Failed to execute the build [Openshift platform has been specified but Openshift has not been detected!]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.639 s
[INFO] Finished at: 2019-07-12T15:36:34+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:4.1.0:build (fmp) on project greeting: Failed to execute the build: Openshift platform has been specified but Openshift has not been detected! -> [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/MojoExecutionException
Maven info:
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: C:\somewhere
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_211\jre
Default locale: en_US, platform encoding: MS950
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
PS C:\Users\somewhere\workspace\greeting>
Openshift info:
oc v3.11.16
kubernetes v1.11.0+d4cacc0
features: Basic-Auth SSPI Kerberos SPNEGO
Server https://openshift-sample-domain.com:8443
openshift v3.11.69
kubernetes v1.11.0+d4cacc0
I ran into this issue today and the resolution was:
Make sure you are logged in to the openshift cluster before you try build/deploy
Make sure the public certificate of the cluster is imported into your JRE cacerts truststore.
Let me know if you would like a concrete example of how to achieve the certificate import.

mvn selenium:selenese hangs in the Spring Roo Tutorial

I am working my way through the Spring Roo Tutorial and I get stuck at this point:
http://static.springsource.org/spring-roo/reference/html/beginning.html#beginning-step-7
This is the Maven Command line output:
C:\pizza>mvn selenium:selenese
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pizzashop 0.1.0.BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- selenium-maven-plugin:2.1:selenese (default-cli) # pizzashop ---
log4j:WARN No appenders could be found for logger (org.openqa.selenium.server.SeleniumServer).
log4j:WARN Please initialize the log4j system properly.
14:53:20.476 INFO - Preparing Firefox profile...
14:53:23.026 INFO - Launching Firefox...
at this point my FireFox 11 browser is launched but there is now visible URL and everything just seems to hang.
Any suggestions or ideas are welcome.
Environment:
OS Windows 7
JDK 1.6
Maven 3.0.3
Firefox 11
latest spring roo downloaded
It's the selenium plugin configuration in the pom.xml. Note: Out of the box ( so to speak ) Roo is going to expect firefox 3.x You can either install Firefox 3.x or you can change the configuration to use another supported browser - for example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<browser>*safari</browser>
<suite>src/main/webapp/selenium/test-suite.xhtml</suite>
<results>${project.build.directory}/selenium.html</results>
<startURL>http://localhost:4444/</startURL>
</configuration>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</plugin>

Resources