...
Markdown |
---|
# StreamPipes on GraalVM I did some tests to compile a native StreamPipes image with GraalVM. For testing, I use the module `streampipes-service-core-nats`minimal`. ## Maven settings I added the following native profile to the pom (streampipes-service-core-minimal): ``` <profiles> <profile> <id>native</id> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <builder>paketobuildpacks/builder:tiny</builder> <env> <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE> </env> </image> </configuration> <executions> <execution> <id>process-aot</id> <goals> <goal>process-aot</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <configuration> <classesDirectory>${project.build.outputDirectory}</classesDirectory> <metadataRepository> <enabled>true</enabled> </metadataRepository> <requiredVersion>22.3</requiredVersion> <buildArgs> <arg>--initialize-at-build-time=org.apache.commons.logging.LogFactory</arg> </buildArgs> </configuration> <executions> <execution> <id>add-reachability-metadata</id> <goals> <goal>add-reachability-metadata</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>nativeTest</id> <dependencies> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-launcher</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>process-test-aot</id> <goals> <goal>process-test-aot</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <configuration> <classesDirectory>${project.build.outputDirectory}</classesDirectory> <metadataRepository> <enabled>true</enabled> </metadataRepository> <requiredVersion>22.3</requiredVersion> </configuration> <executions> <execution> <id>native-test</id> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> <properties> <native-build-tools-plugin.version>0.9.17</native-build-tools-plugin.version> </properties> ``` In addition, I added the `pluginManagement` section to the `build` section: ``` <pluginManagement> <plugins> <plugin> <groupId>org.graalvm.buildtools</groupId> <artifactId>native-maven-plugin</artifactId> <version>${native-build-tools-plugin.version}</version> <extensions>true</extensions> </plugin> </plugins> </pluginManagement> ``` Then, I started the build with `mvn clean package -Pnative -Dcheckstyle.skip`. Afterwards, I ran `java -Dspring.aot.enabled=true -agentlib:native-image-agent=config-output-dir=configs/ -jar streampipes-core-natsminimal.jar`. This will inspect the jar during runtime and create the native image configuration. I had to add the usual environment variables for local execution. In production, we would need to execute everything that is possible in order to ensure that all reflection configs are added. Then I stopped the execution with Ctrl-C. In the `configs` folder, I copied all files to the `src/main/resources/META-INF/native-image` folder. Afterwards, I started to build the image with `mvn spring-boot:build-image -Pnative -Dcheckstyle.skip` and executed the resulting docker image. |
...