@@ -1609,6 +1609,256 @@ This pulls the latest `jonashackt/spring-boot-graalvm` image and runs our app lo
16091609
16101610
16111611
1612+
1613+
1614+
1615+ # Upgrade to spring-native (from spring-graalvm-native) & spring-aot-maven-plugin & GraalVM 21.3
1616+
1617+ Current docs : https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/index.html#overview
1618+
1619+ https://spring.io/blog/2021/03/11/announcing-spring-native-beta
1620+
1621+
1622+ # ## spring-graalvm-native -> spring-native
1623+
1624+ Switch from `spring-graalvm-native` to `spring-native` :
1625+
1626+ ` ` ` xml
1627+ <spring-graalvm-native.version>0.8.5</spring-graalvm-native.version>
1628+ <dependency>
1629+ <groupId>org.springframework.experimental</groupId>
1630+ <artifactId>spring-graalvm-native</artifactId>
1631+ <version>${spring-graalvm-native.version}</version>
1632+ </dependency>
1633+
1634+ to
1635+
1636+ <spring-native.version>0.10.5</spring-native.version>
1637+ <dependency>
1638+ <groupId>org.springframework.experimental</groupId>
1639+ <artifactId>spring-native</artifactId>
1640+ <version>${spring-native.version}</version>
1641+ </dependency>
1642+ ` ` `
1643+
1644+
1645+ # ## Spring Boot Version <=> spring-native Version <=> GraalVM version <=> Java version
1646+
1647+ https://github.com/spring-projects-experimental/spring-native/milestones?state=closed
1648+
1649+ https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/index.html#_validate_spring_boot_version
1650+
1651+ > Spring Native 0.10.5 only supports Spring Boot 2.5.6, so change the version if necessary.
1652+
1653+ https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/index.html#_freeze_graalvm_version
1654+
1655+ Install the matching GraalVM version with SDKMAN :
1656+
1657+ ` ` ` shell
1658+ sdk install java 21.2.0.r11-grl
1659+ ` ` `
1660+
1661+ This will also configure the correct Maven version.
1662+
1663+
1664+ Run
1665+
1666+ ` ` ` shell
1667+ $ native-image --version
1668+ GraalVM 21.2.0 Java 11 CE (Java Version 11.0.12+6-jvmci-21.2-b08)
1669+
1670+ $ java -version
1671+ openjdk version "11.0.12" 2021-07-20
1672+ OpenJDK Runtime Environment GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08)
1673+ OpenJDK 64-Bit Server VM GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08, mixed mode, sharing)
1674+
1675+ $ mvn --version
1676+ Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
1677+ Maven home: /Users/jonashecht/.sdkman/candidates/maven/current
1678+ Java version: 11.0.12, vendor: GraalVM Community, runtime: /Users/jonashecht/.sdkman/candidates/java/21.2.0.r11-grl
1679+ Default locale: de_DE, platform encoding: UTF-8
1680+ OS name: "mac os x", version: "11.5", arch: "x86_64", family: "mac"
1681+ ` ` `
1682+
1683+ Also use the matching version (see https://github.com/graalvm/container/pkgs/container/graalvm-ce) inside your [Dockerfile](Dockerfile) (if you don't use Buildpacks) :
1684+
1685+ ` ` ` dockerfile
1686+ FROM ghcr.io/graalvm/graalvm-ce:ol7-java11-21.2.0
1687+ ` ` `
1688+
1689+ and inside your CI system like GitHub Actions [.github/workflows/native-image-compile.yml](.github/workflows/native-image-compile.yml) :
1690+
1691+ ` ` ` yaml
1692+ - name: Install GraalVM with SDKMAN
1693+ run: |
1694+ curl -s "https://get.sdkman.io" | bash
1695+ source "$HOME/.sdkman/bin/sdkman-init.sh"
1696+ sdk install java 21.2.0.r11-grl
1697+ java -version
1698+ ` ` `
1699+
1700+
1701+ # ## Enable native image support via spring-boot-maven-plugin
1702+
1703+ https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/index.html#_enable_native_image_support
1704+
1705+ Enhance `spring-boot-maven-plugin` buildpacks configuration & `${repackage.classifier}` :
1706+
1707+ ` ` ` xml
1708+ <build>
1709+ <plugins>
1710+ <plugin>
1711+ <groupId>org.springframework.boot</groupId>
1712+ <artifactId>spring-boot-maven-plugin</artifactId>
1713+ </plugin>
1714+ </plugins>
1715+ </build>
1716+
1717+ to
1718+
1719+ <plugin>
1720+ <groupId>org.springframework.boot</groupId>
1721+ <artifactId>spring-boot-maven-plugin</artifactId>
1722+ <configuration>
1723+ <classifier>${repackage.classifier}</classifier>
1724+ <image>
1725+ <builder>paketobuildpacks/builder:tiny</builder>
1726+ <env>
1727+ <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
1728+ </env>
1729+ </image>
1730+ </configuration>
1731+ </plugin>
1732+ ` ` `
1733+
1734+
1735+ # ## spring-context-indexer --> spring-aot-maven-plugin
1736+
1737+ https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/index.html#_add_the_spring_aot_plugin
1738+
1739+ From `spring-context-indexer` to new Spring ahead-of-time (AOT) Maven build plugin `spring-aot-maven-plugin` :
1740+
1741+ ` ` ` xml
1742+ <dependency>
1743+ <groupId>org.springframework</groupId>
1744+ <artifactId>spring-context-indexer</artifactId>
1745+ </dependency>
1746+
1747+ to
1748+
1749+ <plugin>
1750+ <groupId>org.springframework.experimental</groupId>
1751+ <artifactId>spring-aot-maven-plugin</artifactId>
1752+ <version>${spring-native.version}</version>
1753+ <executions>
1754+ <execution>
1755+ <id>test-generate</id>
1756+ <goals>
1757+ <goal>test-generate</goal>
1758+ </goals>
1759+ </execution>
1760+ <execution>
1761+ <id>generate</id>
1762+ <goals>
1763+ <goal>generate</goal>
1764+ </goals>
1765+ </execution>
1766+ </executions>
1767+ </plugin>
1768+ </plugins>
1769+ </build>
1770+ ` ` `
1771+
1772+
1773+ # ## native-image-maven-plugin --> native-maven-plugin
1774+
1775+ Inside the profile `native` move plugin `org.graalvm.nativeimage.native-image-maven-plugin` to new `org.graalvm.buildtools.native-maven-plugin` :
1776+
1777+ ` ` ` xml
1778+
1779+ <native-image-maven-plugin.version>20.3.2</native-image-maven-plugin.version>
1780+ <profiles>
1781+ <profile>
1782+ <id>native</id>
1783+ <build>
1784+ <plugins>
1785+ <plugin>
1786+ <groupId>org.graalvm.nativeimage</groupId>
1787+ <artifactId>native-image-maven-plugin</artifactId>
1788+ <version>${native-image-maven-plugin.version}</version>
1789+ <configuration>
1790+ <buildArgs>-J-Xmx4G -H:+ReportExceptionStackTraces -Dspring.native.remove-unused-autoconfig=true -Dspring.native.remove-yaml-support=true</buildArgs>
1791+ <imageName>${project.artifactId}</imageName>
1792+ </configuration>
1793+ <executions>
1794+ <execution>
1795+ <goals>
1796+ <goal>native-image</goal>
1797+ </goals>
1798+ <phase>package</phase>
1799+ </execution>
1800+ </executions>
1801+ </plugin>
1802+ <plugin>
1803+ <groupId>org.springframework.boot</groupId>
1804+ <artifactId>spring-boot-maven-plugin</artifactId>
1805+ </plugin>
1806+ </plugins>
1807+ </build>
1808+ </profile>
1809+ </profiles>
1810+
1811+ to
1812+ <native-buildtools.version>0.9.4</native-buildtools.version>
1813+ <profiles>
1814+ <profile>
1815+ <id>native</id>
1816+ <properties>
1817+ <repackage.classifier>exec</repackage.classifier>
1818+ </properties>
1819+ <dependencies>
1820+ <dependency>
1821+ <groupId>org.graalvm.buildtools</groupId>
1822+ <artifactId>junit-platform-native</artifactId>
1823+ <version>${native-buildtools.version}</version>
1824+ <scope>test</scope>
1825+ </dependency>
1826+ </dependencies>
1827+ <build>
1828+ <plugins>
1829+ <plugin>
1830+ <groupId>org.graalvm.buildtools</groupId>
1831+ <artifactId>native-maven-plugin</artifactId>
1832+ <version>${native-buildtools.version}</version>
1833+ <executions>
1834+ <execution>
1835+ <id>test-native</id>
1836+ <phase>test</phase>
1837+ <goals>
1838+ <goal>test</goal>
1839+ </goals>
1840+ </execution>
1841+ <execution>
1842+ <id>build-native</id>
1843+ <phase>package</phase>
1844+ <goals>
1845+ <goal>build</goal>
1846+ </goals>
1847+ </execution>
1848+ </executions>
1849+ </plugin>
1850+ </plugins>
1851+ </build>
1852+ </profile>
1853+ </profiles>
1854+ ` ` `
1855+
1856+
1857+
1858+
1859+
1860+
1861+
16121862# Links
16131863
16141864# ## Spring
0 commit comments