Skip to content

Commit 153307a

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 6a9364a commit 153307a

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

server/pom.xml

+49-15
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.1.0</jmolecules.version>
2222
<moduliths.version>1.3.0</moduliths.version>
23+
<spring-native.version>0.12.1-SNAPSHOT</spring-native.version>
2324
</properties>
2425

2526
<dependencyManagement>
@@ -163,6 +164,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
163164
<optional>true</optional>
164165
</dependency>
165166

167+
<dependency>
168+
<groupId>org.springframework.experimental</groupId>
169+
<artifactId>spring-native</artifactId>
170+
<version>${spring-native.version}</version>
171+
</dependency>
172+
166173
</dependencies>
167174

168175
<profiles>
@@ -236,27 +243,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
236243

237244
</dependencies>
238245
</profile>
239-
246+
247+
<!-- General AOT support -->
248+
240249
<profile>
241250

242251
<id>aot</id>
243252

244-
<properties>
245-
<spring-native.version>0.12.1-SNAPSHOT</spring-native.version>
246-
</properties>
247-
248-
<dependencies>
249-
<dependency>
250-
<groupId>org.springframework.experimental</groupId>
251-
<artifactId>spring-native</artifactId>
252-
<version>${spring-native.version}</version>
253-
</dependency>
254-
</dependencies>
255-
256253
<build>
257254

258-
<defaultGoal>verify</defaultGoal>
259-
260255
<plugins>
261256
<plugin>
262257
<groupId>org.springframework.boot</groupId>
@@ -282,7 +277,46 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
282277
</build>
283278

284279
</profile>
280+
281+
<!-- To build native images -->
285282

283+
<profile>
284+
285+
<id>native</id>
286+
287+
<build>
288+
<defaultGoal>spring-boot:build-image</defaultGoal>
289+
<plugins>
290+
<plugin>
291+
<groupId>org.springframework.experimental</groupId>
292+
<artifactId>spring-aot-maven-plugin</artifactId>
293+
<version>${spring-native.version}</version>
294+
<executions>
295+
<execution>
296+
<id>generate</id>
297+
<goals>
298+
<goal>generate</goal>
299+
</goals>
300+
</execution>
301+
</executions>
302+
</plugin>
303+
<plugin>
304+
<groupId>org.springframework.boot</groupId>
305+
<artifactId>spring-boot-maven-plugin</artifactId>
306+
<configuration>
307+
<image>
308+
<builder>paketobuildpacks/builder:tiny</builder>
309+
<env>
310+
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
311+
</env>
312+
</image>
313+
</configuration>
314+
</plugin>
315+
</plugins>
316+
</build>
317+
318+
</profile>
319+
286320
</profiles>
287321

288322
<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)