Skip to content

Commit 2aff4c6

Browse files
committed
Set up build to use Paketo build packs for Spring Native.
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.
1 parent a46d973 commit 2aff4c6

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed

server/pom.xml

+61-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
1818
<properties>
1919
<java.version>11</java.version>
2020
<spring-data-bom.version>2021.0.2</spring-data-bom.version>
21+
<spring-native.version>0.10.0</spring-native.version>
2122
</properties>
2223

2324
<dependencyManagement>
@@ -71,7 +72,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
7172
<dependency>
7273
<groupId>org.springframework.data</groupId>
7374
<artifactId>spring-data-rest-hal-explorer</artifactId>
74-
<scope>runtime</scope>
75+
<!--<scope>runtime</scope>-->
7576
</dependency>
7677

7778
<dependency>
@@ -124,11 +125,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
124125

125126
<!-- Misc -->
126127

128+
<!--
127129
<dependency>
128130
<groupId>org.springframework.boot</groupId>
129131
<artifactId>spring-boot-devtools</artifactId>
130132
<optional>true</optional>
131133
</dependency>
134+
-->
132135

133136
<dependency>
134137
<groupId>org.javamoney.moneta</groupId>
@@ -146,6 +149,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
146149
<artifactId>json-path</artifactId>
147150
</dependency>
148151

152+
<!-- Spring native -->
153+
154+
<dependency>
155+
<groupId>org.springframework.experimental</groupId>
156+
<artifactId>spring-native</artifactId>
157+
<version>${spring-native.version}</version>
158+
</dependency>
159+
160+
<dependency>
161+
<groupId>org.springframework.experimental</groupId>
162+
<artifactId>spring-native-configuration</artifactId>
163+
<version>${spring-native.version}</version>
164+
</dependency>
165+
149166
</dependencies>
150167

151168
<build>
@@ -156,13 +173,21 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
156173
<artifactId>spring-boot-maven-plugin</artifactId>
157174
<configuration>
158175
<executable>true</executable>
176+
<image>
177+
<builder>paketobuildpacks/builder:tiny</builder>
178+
<env>
179+
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
180+
</env>
181+
</image>
159182
</configuration>
160183
<dependencies>
184+
<!--
161185
<dependency>
162186
<groupId>org.springframework.boot.experimental</groupId>
163187
<artifactId>spring-boot-thin-layout</artifactId>
164-
<version>1.0.27.BUILD-SNAPSHOT</version>
188+
<version>1.0.27.RELEASE</version>
165189
</dependency>
190+
-->
166191
</dependencies>
167192
</plugin>
168193

@@ -186,6 +211,26 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
186211
</dependencies>
187212
</plugin>
188213

214+
<plugin>
215+
<groupId>org.springframework.experimental</groupId>
216+
<artifactId>spring-aot-maven-plugin</artifactId>
217+
<version>${spring-native.version}</version>
218+
<executions>
219+
<execution>
220+
<id>generate</id>
221+
<goals>
222+
<goal>generate</goal>
223+
</goals>
224+
</execution>
225+
<execution>
226+
<id>test-generate</id>
227+
<goals>
228+
<goal>test-generate</goal>
229+
</goals>
230+
</execution>
231+
</executions>
232+
</plugin>
233+
189234
</plugins>
190235
</build>
191236

@@ -201,6 +246,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
201246
<enabled>false</enabled>
202247
</snapshots>
203248
</repository>
249+
<repository>
250+
<id>spring-release</id>
251+
<url>https://repo.spring.io/release</url>
252+
<snapshots>
253+
<enabled>false</enabled>
254+
</snapshots>
255+
</repository>
204256
</repositories>
205257

206258
<pluginRepositories>
@@ -215,6 +267,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
215267
<enabled>false</enabled>
216268
</snapshots>
217269
</pluginRepository>
270+
<pluginRepository>
271+
<id>spring-release</id>
272+
<url>https://repo.spring.io/release</url>
273+
<snapshots>
274+
<enabled>false</enabled>
275+
</snapshots>
276+
</pluginRepository>
218277
</pluginRepositories>
219278

220279
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.context.event.EventListener;
20+
import org.springframework.core.annotation.SynthesizedAnnotation;
21+
import org.springframework.nativex.hint.AccessBits;
22+
import org.springframework.nativex.hint.AotProxyHint;
23+
import org.springframework.nativex.hint.JdkProxyHint;
24+
import org.springframework.nativex.hint.NativeHint;
25+
import org.springframework.nativex.hint.ProxyBits;
26+
import org.springframework.nativex.hint.TypeHint;
27+
import org.springframework.transaction.event.TransactionalEventListener;
28+
import org.springsource.restbucks.drinks.Drink;
29+
30+
/**
31+
* Additional configuration needed to produce Graal metadata to let some application properly work on it.
32+
*
33+
* @author Oliver Drotbohm
34+
*/
35+
@Configuration
36+
// Standard user component requiring proxying due to @Async
37+
@AotProxyHint(targetClassName = "org.springsource.restbucks.engine.Engine", proxyFeatures = ProxyBits.IS_STATIC)
38+
39+
// Due to DrinksOptions.BY_NAME (i.e. the usage of a domain type with Spring Data's TypedSort)
40+
@AotProxyHint(targetClass = Drink.class, proxyFeatures = ProxyBits.IS_STATIC)
41+
42+
// Referred to by a custom AttributeConverter
43+
// https://github.com/spring-projects-experimental/spring-native/issues/829
44+
@TypeHint(types = { org.javamoney.moneta.Money.class }, access = AccessBits.LOAD_AND_CONSTRUCT)
45+
46+
// Needed to get @TransactionalEventListener on Engine.process(…) working
47+
// https://github.com/spring-projects-experimental/spring-native/issues/828
48+
@TypeHint(types = { EventListener.class, TransactionalEventListener.class }, access = AccessBits.ANNOTATION)
49+
// Additional wrapping needed due to https://github.com/spring-projects-experimental/spring-native/issues/830
50+
@NativeHint( //
51+
jdkProxies = @JdkProxyHint(types = { TransactionalEventListener.class, SynthesizedAnnotation.class }) //
52+
)
53+
class NativeConfiguration {}

0 commit comments

Comments
 (0)