Skip to content

Commit db96bfa

Browse files
committed
Set up build to use Paketo build packs for Spring Native.
Move dependency to the native JAR into the common build as we have code to compile to tweak the native image. That code needs to be compilable in non-native scenarios as well. Use buildpack based native image builds. Remove offending libraries: both Spring Boot DevTools and the Thin Launcher are not native-ready yet. Added NativeConfiguration to capture a few manual hints still needed. Declare Money as the type being returned from MonetaryAmountAttributeConverter.convertToEntityAttribute(…) so that it is automatically added to the reflection configuration (makes spring-attic/spring-native#826 obsolete).
1 parent 79786b3 commit db96bfa

File tree

3 files changed

+106
-14
lines changed

3 files changed

+106
-14
lines changed

server/pom.xml

+73-13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
2020
<java.version>17</java.version>
2121
<jmolecules.version>2022.2.0</jmolecules.version>
2222
<moduliths.version>1.3.0</moduliths.version>
23+
<spring-native.version>0.12.1</spring-native.version>
2324
</properties>
2425

2526
<dependencyManagement>
@@ -157,6 +158,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
157158
<optional>true</optional>
158159
</dependency>
159160

161+
<dependency>
162+
<groupId>org.springframework.experimental</groupId>
163+
<artifactId>spring-native</artifactId>
164+
<version>${spring-native.version}</version>
165+
</dependency>
166+
160167
</dependencies>
161168

162169
<profiles>
@@ -230,23 +237,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
230237

231238
</dependencies>
232239
</profile>
233-
240+
241+
<!-- General AOT support -->
242+
234243
<profile>
235244

236245
<id>aot</id>
237246

238-
<properties>
239-
<spring-native.version>0.12.1-SNAPSHOT</spring-native.version>
240-
</properties>
241-
242-
<dependencies>
243-
<dependency>
244-
<groupId>org.springframework.experimental</groupId>
245-
<artifactId>spring-native</artifactId>
246-
<version>${spring-native.version}</version>
247-
</dependency>
248-
</dependencies>
249-
250247
<build>
251248

252249
<defaultGoal>verify</defaultGoal>
@@ -277,6 +274,69 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
277274

278275
</profile>
279276

277+
<!-- To build native images -->
278+
279+
<profile>
280+
281+
<id>native</id>
282+
283+
<build>
284+
<defaultGoal>spring-boot:build-image</defaultGoal>
285+
<plugins>
286+
<plugin>
287+
<groupId>org.springframework.experimental</groupId>
288+
<artifactId>spring-aot-maven-plugin</artifactId>
289+
<version>${spring-native.version}</version>
290+
<executions>
291+
<execution>
292+
<id>generate</id>
293+
<goals>
294+
<goal>generate</goal>
295+
</goals>
296+
</execution>
297+
</executions>
298+
</plugin>
299+
<plugin>
300+
<groupId>org.springframework.boot</groupId>
301+
<artifactId>spring-boot-maven-plugin</artifactId>
302+
<configuration>
303+
<image>
304+
<builder>paketobuildpacks/builder:tiny</builder>
305+
<env>
306+
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
307+
</env>
308+
</image>
309+
</configuration>
310+
</plugin>
311+
</plugins>
312+
</build>
313+
314+
</profile>
315+
316+
<!-- Activate in addition to 'native' if you're building on an ARM machine (such as an M1 MacBook) -->
317+
318+
<profile>
319+
<id>arm64</id>
320+
<activation>
321+
<os>
322+
<arch>aarch64</arch>
323+
</os>
324+
</activation>
325+
<build>
326+
<plugins>
327+
<plugin>
328+
<groupId>org.springframework.boot</groupId>
329+
<artifactId>spring-boot-maven-plugin</artifactId>
330+
<configuration >
331+
<image>
332+
<builder>dashaun/java-native-builder-arm64:7.19.0</builder>
333+
</image>
334+
</configuration>
335+
</plugin>
336+
</plugins>
337+
</build>
338+
</profile>
339+
280340
</profiles>
281341

282342
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springsource.restbucks;
17+
18+
import org.springframework.context.annotation.Configuration;
19+
import org.springframework.nativex.hint.AotProxyHint;
20+
import org.springframework.nativex.hint.ProxyBits;
21+
import org.springsource.restbucks.drinks.Drink;
22+
23+
/**
24+
* Additional configuration needed to produce Graal metadata to let some application properly work on it.
25+
*
26+
* @author Oliver Drotbohm
27+
*/
28+
@Configuration
29+
30+
// Due to DrinksOptions.BY_NAME (i.e. the usage of a domain type with Spring Data's TypedSort)
31+
@AotProxyHint(targetClass = Drink.class, proxyFeatures = ProxyBits.IS_STATIC)
32+
class NativeConfiguration {}

server/src/main/java/org/springsource/restbucks/core/MonetaryAmountAttributeConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public String convertToDatabaseColumn(MonetaryAmount amount) {
4545
}
4646

4747
@Override
48-
public MonetaryAmount convertToEntityAttribute(String source) {
48+
public Money convertToEntityAttribute(String source) {
4949

5050
if (source == null) {
5151
return null;

0 commit comments

Comments
 (0)