Skip to content

Commit ac28416

Browse files
committed
Minor improvement
1 parent 31feba7 commit ac28416

File tree

19 files changed

+514
-493
lines changed

19 files changed

+514
-493
lines changed

.cursor/rules/321-frameworks-spring-boot-native-compilation.mdc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,6 @@ These guidelines are built upon the following core principles:
5252
<plugin>
5353
<groupId>org.springframework.boot</groupId>
5454
<artifactId>spring-boot-maven-plugin</artifactId>
55-
<configuration>
56-
<image>
57-
<builder>paketobuildpacks/builder:tiny</builder>
58-
<env>
59-
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
60-
</env>
61-
</image>
62-
</configuration>
63-
</plugin>
64-
<plugin>
65-
<groupId>org.graalvm.buildtools</groupId>
66-
<artifactId>native-maven-plugin</artifactId>
67-
<version>${native.maven.plugin.version}</version>
6855
</plugin>
6956
</plugins>
7057
</build>

.cursor/rules/templates/java-maven-questions-template.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ Options:
2929

3030
Options:
3131
- Format source code (Spotless)
32+
- Maven Enforcer
3233
- Compiler behaviour improvements with ErrorProne + NullAway (Ask for JSpecify)
34+
- Unit Testing (Surefire)
3335
- Integration testing (Failsafe)
3436
- Code coverage reporting (JaCoCo)
3537
- Mutation testing (PiTest)
3638
- Security vulnerability scanning (OWASP)
37-
- Static code analysis (SpotBugs, Sonar)
39+
- Static code analysis (SpotBugs, PMD)
40+
- Sonar
3841

3942
## 4. Coverage Threshold
4043

examples/spring-boot-demo/implementation/README-DEV.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
./mvnw versions:display-plugin-updates
2727

2828
# Generate project reports
29-
./mvnw site
29+
./mvnw clear site
3030
jwebserver -p 8005 -d "$(pwd)/target/site/"
3131

3232
./mvnw clean spring-boot:run -Dspring-boot.run.profiles=local
3333
curl "http://localhost:8080/api/v1/films?startsWith=A"
3434
open http://localhost:8080/api/v1/swagger-ui.html
35+
36+
docker compose up -d
3537
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Readme
1+
# README
22

33
## References
44

5-
- https://github.com/sakiladb/postgres
5+
- https://github.com/sakiladb/postgres
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#!/bin/bash
2+
3+
# Spring Boot Native Compilation Build Script
4+
# This script demonstrates the various native compilation options available
5+
6+
set -e
7+
8+
echo "🚀 Spring Boot Native Compilation Build Script"
9+
echo "================================================"
10+
11+
# Function to print colored output
12+
print_step() {
13+
echo -e "\n\033[1;34m$1\033[0m"
14+
}
15+
16+
print_success() {
17+
echo -e "\033[1;32m✅ $1\033[0m"
18+
}
19+
20+
print_error() {
21+
echo -e "\033[1;31m❌ $1\033[0m"
22+
}
23+
24+
# Check if GraalVM is available
25+
check_graalvm() {
26+
print_step "Checking GraalVM installation..."
27+
if command -v native-image &> /dev/null; then
28+
print_success "GraalVM native-image found: $(native-image --version | head -n1)"
29+
else
30+
print_error "GraalVM native-image not found. Please install GraalVM."
31+
echo "Install GraalVM: https://www.graalvm.org/downloads/"
32+
echo "Or use SDKMAN: sdk install java 21.0.1-graal"
33+
exit 1
34+
fi
35+
}
36+
37+
# Clean previous builds
38+
clean_build() {
39+
print_step "Cleaning previous builds..."
40+
./mvnw clean
41+
print_success "Clean completed"
42+
}
43+
44+
# Run tests first
45+
run_tests() {
46+
print_step "Running tests to ensure application works..."
47+
./mvnw test
48+
print_success "Tests passed"
49+
}
50+
51+
# Compile native executable
52+
compile_native() {
53+
print_step "Compiling native executable with AOT processing..."
54+
echo "This may take several minutes..."
55+
56+
# Set SPRING_PROFILES_ACTIVE for native compilation
57+
export SPRING_PROFILES_ACTIVE=native
58+
59+
./mvnw -Pnative clean native:compile
60+
print_success "Native executable compiled successfully"
61+
62+
if [ -f target/sakila-api ]; then
63+
echo "📁 Native executable location: target/sakila-api"
64+
echo "📊 Executable size: $(du -h target/sakila-api | cut -f1)"
65+
fi
66+
}
67+
68+
# Test native executable
69+
test_native() {
70+
print_step "Testing native executable..."
71+
if [ -f target/sakila-api ]; then
72+
echo "Starting native executable for quick test..."
73+
timeout 10s ./target/sakila-api --server.port=8081 --spring.profiles.active=native,test > /dev/null 2>&1 &
74+
PID=$!
75+
sleep 5
76+
77+
if kill -0 $PID 2>/dev/null; then
78+
print_success "Native executable started successfully"
79+
kill $PID 2>/dev/null || true
80+
else
81+
print_error "Native executable failed to start"
82+
fi
83+
else
84+
print_error "Native executable not found"
85+
fi
86+
}
87+
88+
# Build container image with native binary
89+
build_container() {
90+
print_step "Building container image with native binary..."
91+
echo "This will create a lightweight container with the native executable..."
92+
93+
./mvnw spring-boot:build-image -Pnative
94+
print_success "Container image built successfully"
95+
96+
echo "🐳 Container image: sakila-api:0.0.1-SNAPSHOT"
97+
echo "Run with: docker run -p 8080:8080 sakila-api:0.0.1-SNAPSHOT"
98+
}
99+
100+
# Run native tests (if available)
101+
run_native_tests() {
102+
print_step "Running native tests..."
103+
./mvnw -Pnative test
104+
print_success "Native tests completed"
105+
}
106+
107+
# Display performance comparison
108+
show_performance_info() {
109+
print_step "Performance Characteristics:"
110+
echo "
111+
🚀 Startup Time: 10-100x faster than JVM
112+
💾 Memory Usage: Reduced footprint (especially for small apps)
113+
⚡ Build Time: Longer compilation (2-10 minutes)
114+
📦 Image Size: Larger executable, but no JVM needed
115+
🎯 Runtime Perf: Different characteristics vs JIT compilation
116+
117+
📋 Commands Summary:
118+
./mvnw -Pnative clean native:compile # Build native executable
119+
./mvnw -Pnative test # Run native tests
120+
./mvnw spring-boot:build-image -Pnative # Build container image
121+
./target/sakila-api # Run native executable
122+
"
123+
}
124+
125+
# Main execution
126+
main() {
127+
case "${1:-help}" in
128+
"check")
129+
check_graalvm
130+
;;
131+
"clean")
132+
clean_build
133+
;;
134+
"test")
135+
run_tests
136+
;;
137+
"compile")
138+
check_graalvm
139+
clean_build
140+
compile_native
141+
test_native
142+
;;
143+
"container")
144+
check_graalvm
145+
build_container
146+
;;
147+
"native-test")
148+
check_graalvm
149+
run_native_tests
150+
;;
151+
"full")
152+
check_graalvm
153+
clean_build
154+
run_tests
155+
compile_native
156+
test_native
157+
show_performance_info
158+
;;
159+
"help"|*)
160+
echo "Usage: $0 [command]"
161+
echo ""
162+
echo "Commands:"
163+
echo " check Check GraalVM installation"
164+
echo " clean Clean previous builds"
165+
echo " test Run application tests"
166+
echo " compile Compile native executable"
167+
echo " container Build container with native image"
168+
echo " native-test Run native-specific tests"
169+
echo " full Complete native build process"
170+
echo " help Show this help message"
171+
echo ""
172+
show_performance_info
173+
;;
174+
esac
175+
}
176+
177+
main "$@"

0 commit comments

Comments
 (0)