Goaller
build
compile-no-fork
release
Örnek
Sadece şöyle yapmak yeterli. maven install ile proje derlenir.
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
Profile
Örnek
Bu plugin bazen bir profile ile kullanılıyor. Önce bir profile
ekleriz<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
./mvnw clean package -Pnative
Eğer plugin profile içinde değilse şöyle
yaparız./mvnw clean package -Dpackaging=native-image
If you have not installed it to your own machine, you also have an option to use a Docker container that has GraalVM and the native image extension installed by default. You can use the following command for that:
./mvnw package -Pnative -Dquarkus.native.container-build=true
It might take some time to finish compilation, especially in the docker container, but after a while you should have a native executable named code-with-quarkus-1.0.0.-SNAPSHOT-runner in your target folder.
./mvnw package -Pnative -Dquarkus.native.container-build=true
Örnek
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
<execution>
<id>release-native</id>
<goals>
<goal>release</goal>
</goals>
<phase>release</phase>
</execution>
</executions>
<configuration>
<imageName>${appName}-${project.version}</imageName>
<mainClass>${mainClass}</mainClass>
<buildArgs>
<buildArg>--allow-incomplete-classpath</buildArg>
<buildArg>--no-fallback</buildArg>
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
<buildArg>--verbose</buildArg>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
./mvnw -B --file pom.xml -Pnative package
When you run the resulting application, the application will report the Class files it is unable to find
...
You can then add them to the reflect-config.json in the resources/META-INF/native-image folder of your project.
And you specify the configuration in native-image.properties for GraalVM native-image-plugin to refer the reflect-config.json while building the native image.
-H=ReflectionConfigurationResources=${.}/reflect-config.json
reflect-config.json dosyası
şöyle. Burada her bir eksik class teker teker tanımlanıyor
[
{
"name": "io.jsonwebtoken.impl.crypto.MacProvider",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredClasses": true,
"allPublicClasses": true
},
...
]
configuration Seçenekleri
--allow-incomplete-classpath Seçeneği
reflection-config.json dosyasına her sınıfı yazdığımızı düşünsek bile halen hata almaya devam edebiliriz. Bu durumda şöyle yaparız
<buildArg>--allow-incomplete-classpath</buildArg>
An alternative quick fix could be the option --allow-incomplete-classpath. This ensures that the possible linking errors are shifted from build time to run time.
--initialize-at-build-time Seçeneği
Şöyle bir hata alabiliriz. Yani bir sınıf derleme esnasında (compile time) hata veriyor
ERROR: Classes that should be initialized at run time got initialized during image building:…
The most classes are initialized at build time and GraalVM tries to find out what can be initialized at build time and which classes must be initialized at run time. This error can be fixed with the parameter --initialize-at-run-time. This parameter will force to initialize this class at runtime. Another way to force to initialize a class during build is to use the parameter --initialize-at-build-time.
Örnek
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs>
<buildArg>--initialize-at-build-time=my.build.package</buildArg>
<buildArg>--initialize-at-build-time=my.other.build.package.SpecificClass</buildArg>
<buildArg>--initialize-at-run-time=my.run.package</buildArg>
<buildArg>--initialize-at-run-time=my.other.run.package.SpecificClass</buildArg>
</buildArgs>
</configuration>
Örnek
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs>
<buildArg>--initialize-at-build-time=org.apache.commons.logging.LogFactory,org.apache.commons.logging.LogFactoryService,org.slf4j.MDC,ch.qos.logback.core.pattern.parser.Parser,ch.qos.logback.core.util.Loader,ch.qos.logback.core.util.StatusPrinter,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:+ReportExceptionStackTraces</buildArg>
</buildArgs>
<jvmArgs>
<arg>-Xmx8g</arg>
<arg>-Xms8g</arg>
</jvmArgs>
</configuration>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
jvmArgs
Örnek
Native image oluşturmak çok fazla bellek tüketiyor. Eklentinin kullanacağı belleği ayarlamak için şöyle
yaparız<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<jvmArgs>
<arg>-Xmx8g</arg>
<arg>-Xms8g</arg>
</jvmArgs>
</configuration>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
skipNativeTests Alanı
So far Mockito is not supported for tests. This can bring up problems for a high number of existing applications and result in big test refactoring projects. There are two possible ways to get it running: either exclude all mocking tests or simply skip native tests with setting the configuration skipNativeTests to true:
Örnek
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<skipNativeTests>true</skipNativeTests>
</configuration>