Spring Boot / GraalVM native-maven-plugin failing with runtime vs build-time class initialization - spring-boot

I'm trying to build a native image using Spring Boot 3, referring to these docs.
I'm hitting the below exception at build time:
[INFO] [creator]
[INFO] [creator] Error: Classes that should be initialized at run time got initialized during image building:
[INFO] [creator] ch.qos.logback.core.status.InfoStatus was unintentionally initialized at build time. To see why ch.qos.logback.core.status.InfoStatus got initialized use --trace-class-initialization=ch.qos.logback.core.status.InfoStatus
[INFO] [creator] ch.qos.logback.core.util.Loader was unintentionally initialized at build time. To see why ch.qos.logback.core.util.Loader got initialized use --trace-class-initialization=ch.qos.logback.core.util.Loader
[INFO] [creator] ch.qos.logback.classic.Logger was unintentionally initialized at build time. To see why ch.qos.logback.classic.Logger got initialized use --trace-class-initialization=ch.qos.logback.classic.Logger
[INFO] [creator] ch.qos.logback.core.util.StatusPrinter was unintentionally initialized at build time. To see why ch.qos.logback.core.util.StatusPrinter got initialized use --trace-class-initialization=ch.qos.logback.core.util.StatusPrinter
[INFO] [creator] ch.qos.logback.classic.Level was unintentionally initialized at build time. To see why ch.qos.logback.classic.Level got initialized use --trace-class-initialization=ch.qos.logback.classic.Level
[INFO] [creator] ch.qos.logback.core.status.StatusBase was unintentionally initialized at build time. To see why ch.qos.logback.core.status.StatusBase got initialized use --trace-class-initialization=ch.qos.logback.core.status.StatusBase
[INFO] [creator] To see how the classes got initialized, use --trace-class-initialization=ch.qos.logback.core.status.InfoStatus,ch.qos.logback.core.util.Loader,ch.qos.logback.classic.Logger,ch.qos.logback.core.util.StatusPrinter,ch.qos.logback.classic.Level,ch.qos.logback.core.status.StatusBase
[INFO] [creator] Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO] [creator] --------------------------------------------------------------------------------
[INFO] [creator] 1.6s (3.8% of total time) in 25 GCs | Peak RSS: 5.87GB | CPU load: 4.39
Based on other similar questions, I've configured the maven plugin as follows, but it hasn't had any effect:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<!-- note: I've tried several combinations of combine.children here, including omitting it entirely, none seem to have any effect -->
<buildArgs combine.children="append">
<buildArg>--initialize-at-build-time=ch.qos.logback.classic.Level,ch.qos.logback.classic.Logger,ch.qos.logback.core.util.StatusPrinter,ch.qos.logback.core.status.StatusBase,ch.qos.logback.core.status.InfoStatus,ch.qos.logback.core.util.Loader,org.slf4j.impl.StaticLoggerBinder,org.slf4j.LoggerFactory,ch.qos.logback.classic.Logger,ch.qos.logback.core.spi.AppenderAttachableImpl,ch.qos.logback.core.status.StatusBase,ch.qos.logback.classic.Level,ch.qos.logback.core.status.InfoStatus,ch.qos.logback.classic.PatternLayout,ch.qos.logback.core.CoreConstants</buildArg>
<buildArg>-H:+TraceClassInitialization</buildArg>
</buildArgs>
</configuration>
</plugin>
My POM inherits from spring-boot-starter-parent:3.0.2 :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I've tried multiple different configurations, but I can't seem to change the exception.
I note that adding -H:+ReportExceptionStackTraces had no impact, so I'm wondering if I'm passing these args incorrectly?
How do I correctly configure the maven plugin to remove these errors?

Related

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>

Maven build hangs during build

Whenever I run the maven build on my POM.xml, the build just hangs and the laptop becomes unresponsive. The last lines I always see are:
[INFO] --- filevault-package-maven-plugin:1.0.3:check-signature (default-check-signature) # my-project.ui.apps ---
[INFO] No signature defined. Skipping signature check.
[INFO]
[INFO] --- filevault-package-maven-plugin:1.0.3:analyze-classes (default-analyze-classes) # my-project.ui.apps ---
[INFO] Analyzing java package dependencies.
The plugin configuration in my POM file is below:
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<version>1.0.3</version>
<configuration>
<filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
<failOnDependencyErrors>false</failOnDependencyErrors>
</configuration>
</plugin>
I am trying to build this using archetype 22. The same code and dependencies worked fine in archetype 13 project earlier.

Build Failure: Version increase required: Failed to execute goal org.apache.felix:maven-bundle-plugin:3.0.1:baseline

Below is the error i am getting when i am adding any new method to existing code (especially when i am adding any method to interface or class)
--- animal-sniffer-maven-plugin:1.15:check (default) # deepser ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO]
[INFO] --- maven-bundle-plugin:3.0.1:bundle (default-bundle) # deepser ---
[INFO]
[INFO] --- maven-bundle-plugin:3.0.1:baseline (baseline) # deepser ---
[INFO] Baseline Report - Generated by Apache Felix Maven Bundle Plugin on 2018-07-09T20:24Z based on Bnd - see http://www.aqute.biz/Bnd/Bnd
[INFO] Comparing bundle deepser version 18.6.5-SNAPSHOT to version 18.6.4
[INFO]
[INFO] PACKAGE_NAME DELTA CUR_VER BASE_VER REC_VER WARNINGS
[INFO] = ================================================== ========== ========== ========== ========== ==========
[INFO] * com.myowncompany.analytica.deepser.config major 18.6.5 18.6.4 19.0.0 Version increase required
[INFO] > interface com.myowncompany.analytica.deepser.config.DeepSearchConfig
[INFO] + method getDeepSearchLibsCDNUrl()
[INFO] + access abstract
[INFO] + return java.lang.String
[INFO] - version 18.6.4
[INFO] + version 18.6.5
[INFO] -----------------------------------------------------------------------------------------------------------
[INFO] * com.myowncompany.analytica.deepser.config.impl minor 18.6.5 18.6.4 18.7.0 Version increase required
[INFO] < class com.myowncompany.analytica.deepser.config.impl.DeepSearchConfigImpl
[INFO] + method getDeepSearchLibsCDNUrl()
[INFO] + return java.lang.String
[INFO] - version 18.6.4
[INFO] + version 18.6.5
[INFO] -----------------------------------------------------------------------------------------------------------
[ERROR] com.myowncompany.analytica.deepser.config: Version increase required; detected 18.6.5, suggested 19.0.0
[ERROR] com.myowncompany.analytica.deepser.config.impl: Version increase required; detected 18.6.5, suggested 18.7.0
[INFO] Baseline analysis complete, 2 error(s), 0 warning(s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.179 s
[INFO] Finished at: 2018-07-09T20:24:41+05:30
[INFO] Final Memory: 41M/1038M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.felix:maven-bundle-plugin:3.0.1:baseline (baseline) on project deepser: Baseline failed, see generated report -> [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/MojoFailureException
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=1024m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
My pom.xml contains below plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${scr.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${mvn.bundle.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Category>search</Bundle-Category>
<!-- Export only the packages that should be visible to other bundles
and JSPs -->
<Export-Package>
com.myowncompany.analytica.*
</Export-Package>
</instructions>
</configuration>
</plugin>
Any idea....i googled it out, and spend 3 hours, still not able to find root cause. Earlier this was working fine. But recently it start giving issue version need to be updated.
The baseline plugin checks if exported packages changed according to semantic versioning rules. It compares the signature of classes in the new packages against the latest release by default.
The results tell you that a minor version increase is needed for the impl package and a major version increase for the .config package.
In case you did not intend to run the baseline goal you can skip it using the maven property: baseline.skip=true
Btw. you should only run the baseline checks on API packages. On impl they do not make much sense .. but you should try to not export impl packages anyway.
On Basis of AEM 6.5
I tried the -Dbaseline.skip=true option as indicated by others but still failed.
This article here: https://felix.apache.org/components/bundle-plugin/baseline-mojo.html
Talks about adding 'skip' property.
I then added this property under my core module as indicated below and all worked fine:
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-baseline-maven-plugin</artifactId>
<configuration>
<failOnMissing>false</failOnMissing>
<skip>true</skip>
</configuration>
</plugin>
I ran the command :
mvn clean -Dbaseline.skip=true install,
it worked like a charm

Using compose in (fabric8io) docker-maven-plugin deactivates image build

I have a maven project to build an image that runs fine, it looks like :
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
<configuration>
<showLogs>true</showLogs>
<images>
<image>
<name>${docker.image.name}</name>
<alias>${project.artifactId}-${timestamp}</alias>
<build>
<dockerFile>${docker.dockerfile}</dockerFile>
</build>
I want to use docker-compose to run a container from this image so I added right below the former snippet:
<external>
<type>compose</type>
<basedir>src/main/docker</basedir>
<composeFile>docker-compose.yml</composeFile>
</external>
Then when I run, the image is not built anymore :
[INFO] --- docker-maven-plugin:0.20.0:build (build-image) # my-component ---
[INFO]
[INFO] --- docker-maven-plugin:0.20.0:stop (build-image) # my-component ---
[INFO]
[INFO] --- docker-maven-plugin:0.20.0:start (run-image) # my-component ---
[INFO] DOCKER> Pulling repository toto.com/mu-repo/my-component
[ERROR] DOCKER> Error occurred during container startup, shutting down...
[ERROR] DOCKER> I/O Error
Error being that image does not exist localy.
I read the documentation, the "external" expected behaviour is not so clear to me but I did not saw anything implying a image build deactivation.
Did anyone face same issue, does anyone know about correct setup, or if I am not using the plugin the way it's meant to ?

Vaadin Custom Components/Widgets with Maven and Spring Boot

I am relatively new to vaadin and started out with a spring boot application and the vaadin spring boot plugin. Everything worked fine until I got to the point where I tried to create my own components/widgets.
Unfortunately I didn't find any "official" example/documentation how to set up custom components within a spring boot application so I had to search the web to find out how to set up additional plugin(s) in maven to compile the code for the client side widgets. As far as I can tell from the log output the compilation of these components work, but when I try to access these components on the webpage I get an error:
Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for net.gtidev.test.components.MyComponent. Check its component connector's #Connect mapping, widgetsets GWT module description file and re-compile your widgetset. [...]
Here is the widget compiler log:
[INFO] Using com.vaadin:vaadin-client-compiler version 7.6.4
[ERROR] Mar 22, 2016 10:22:43 AM java.util.prefs.WindowsPreferences <init>
[ERROR] WARNUNG: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[INFO] Compiling module net.gtidev.test.components.TestWidgetset
[INFO] Computing all possible rebind results for 'com.vaadin.client.metadata.ConnectorBundleLoader'
[INFO] Rebinding com.vaadin.client.metadata.ConnectorBundleLoader
[INFO] Invoking generator com.vaadin.server.widgetsetutils.ConnectorBundleLoaderFactory
[INFO] Populating eager bundle
. . . . . 250 more lines
[INFO] Computing all possible rebind results for 'com.vaadin.client.ui.dd.VAcceptCriterionFactory'
[INFO] Rebinding com.vaadin.client.ui.dd.VAcceptCriterionFactory
[INFO] Invoking generator com.vaadin.server.widgetsetutils.AcceptCriteriaFactoryGenerator
[INFO] Detecting available criteria ...
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.AcceptAll
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.And
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIs
[INFO] creating mapping for com.vaadin.ui.AbstractSelect.TargetItemIs
[INFO] creating mapping for com.vaadin.ui.AbstractSelect.AcceptItem
[INFO] creating mapping for com.vaadin.ui.Table.TableDropCriterion
[INFO] creating mapping for com.vaadin.ui.Tree.TreeDropCriterion
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.Not
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.Or
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.ServerSideCriterion
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.SourceIsTarget
[INFO] creating mapping for com.vaadin.event.dd.acceptcriteria.TargetDetailIs
[INFO] creating mapping for com.vaadin.ui.Tree.TargetInSubtree
[INFO] Done. (0seconds)
[INFO] Compiling 1 permutation
[INFO] Compiling permutation 0...
[INFO] Compile of permutations succeeded
[INFO] Compilation succeeded -- 59,217s
[INFO] Linking into C:\projects\misc\vaadin-boot\target\vaadin-boot-0.0.1-SNAPSHOT\net.gtidev.test.components.TestWidgetset
[INFO] Link succeeded
[INFO] Linking succeeded -- 0,492s
The files I use for my custom component were generated by the eclipse vaadin addon within a vaadin 7 project which I created only for this purpose. When I started this vaadin 7 project in eclipse the component worked. I then copied these files into my spring boot maven project where the custom component does not get loaded any more.
I know that spring boot applications have a slightly different bootstrap mechanism and layout than "classic" webapps and that amongst other things static resources are not loaded from the webapp-folder but from the classpath:/static folder. I think that the core of the problem has something to do with this fact but I don't know what to do to fix it.
My Plugin configuration (I tried with and without the commented options):
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>7.6.4</version>
<configuration>
<strict>true</strict>
<force>true</force>
<!-- Enable during development to speed compiling. -->
<!-- <draftCompile>true</draftCompile>
<style>DETAILED</style> -->
<!-- End development options -->
<!--<webappDirectory>src/main/webapp/VAADIN/widgetsets</webappDirectory>-->
<modules>
<module>net.gtidev.test.components.TestWidgetset</module>
</modules>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
I tried different maven plugin combinations and configurations. In one example, there was also a Google-GWT Plugin mentioned, but running this plugin on the code produced the same log output as the vaadin plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<!--<configuration>-->
<!--<webappDirectory>src/main/webapp/VAADIN/widgetsets</webappDirectory>-->
<!--<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>-->
<!--<runTarget>clean</runTarget>-->
<!--<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>-->
<!--<noServer>true</noServer>-->
<!--<port>8080</port>-->
<!--<soycDetailed>false</soycDetailed>-->
<!--</configuration>-->
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
To use custom client side extensions, Vaadin Add-ons, you'll need to add vaadin-maven-plugin to your project. It will scan the add-ons you use and GWT compile a new widgetset for your project that contains those extensions.
If you created the project with start.spring.io the maven plugin is not in your project by default. Create an example project for example using this Vaadin+Spring archetype or the official servlet based archetype and copy the vaadin-maven-plugin related parts from the pom.xml to your projects pom.xml. Then do a full build and everything should works as expected.

Resources