xuxiaowei-com-cn opened a new pull request, #8162:
URL: https://github.com/apache/incubator-seata/pull/8162
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing
guidelines -->
- [ ] I have read the
[CONTRIBUTING.md](https://github.com/apache/incubator-seata/blob/2.x/CONTRIBUTING.md)
guidelines.
- [ ] I have registered the PR
[changes](https://github.com/apache/incubator-seata/tree/2.x/changes).
### Ⅰ. Describe what this PR did
This PR adds **GraalVM Native Image** packaging support to the Seata Server,
enabling users to build and deploy the Seata Server as a self-contained native
binary with **sub-second startup time**, **lower memory footprint**, and **no
JDK dependency** at runtime.
#### Changes Overview (14 files, +3636 / −105)
**1. GraalVM Native Image Build Profiles (`server/pom.xml`)**
- Added `native` Maven profile that configures `spring-boot-maven-plugin`
(AOT processing) and `native-maven-plugin` (GraalVM native image compilation).
- Added `nativeTest` profile for AOT-based native testing with
`junit-platform-launcher`.
- Note: The OS/arch auto-activation profiles (`native-linux-amd64`,
`native-linux-aarch64`, `native-darwin-x86_64`, `native-darwin-aarch64`,
`native-windows-amd64`) that set the `native.platform` classifier were later
promoted to the root `pom.xml` so the property is available to all submodules.
- Configured build-time initialization for `logback`, `slf4j`, `fastjson2`
and run-time initialization for `netty.channel.kqueue`.
- Set `mainClass` to `org.apache.seata.server.ServerApplication`.
- Added `Spring-Boot-Native-Processed: true` manifest entry.
- Excluded `spring-boot-devtools` from native compilation.
**2. GraalVM Reachability Metadata (3 new config files)**
- Added `reflect-config.json` (~2801 lines) — registers classes, methods,
and fields for reflective access at native image build time, covering Seata's
core components (serializers, codecs, RPC handlers, store managers,
configuration providers, discovery providers, etc.).
- Added `resource-config.json` (~463 lines) — registers resource bundles and
configuration files (Spring factories, SPI service descriptors, SQL scripts,
configuration templates) for inclusion in the native image.
- Added `proxy-config.json` — registers dynamic proxy interfaces used by
Seata (e.g., Spring AOP proxies, configuration binding interfaces).
All metadata files are placed under
`META-INF/native-image/org.apache.seata/seata-server/` for GraalVM 25
compatibility.
**3. CI/CD: Multi-Platform Native Build Workflow
(`.github/workflows/native.yml`)**
- Added a new GitHub Actions workflow (`Native Build`) that builds GraalVM
native images for the Seata Server across **5 platforms**: `ubuntu-24.04`
(amd64), `ubuntu-24.04-arm` (arm64), `macos-26-intel` (x86_64), `macos-26`
(apple silicon), `windows-latest` (amd64).
- Uses **GraalVM JDK 25** distribution via `actions/[email protected]`.
- Includes Maven repository caching (`actions/cache/restore@v4` /
`actions/cache/save@v4`) with SNAPSHOT cleanup.
- Uploads native binaries as workflow artifacts via
`actions/[email protected]`.
- Triggers on push and PR to `2.x`, `develop`, `master` branches (ignores
markdown-only changes).
**4. logback-spring.xml Simplification (GraalVM Compatibility)**
- **Removed all Janino `<if>` conditional logic** (e.g., `<if
condition='property("LOGSTASH_APPENDER_ENABLED").equals("true")'>`) because
Janino's dynamic bytecode compilation is not supported in GraalVM native images.
- Simplified the configuration to always include `console-appender` and
`file-appender` by default.
- Removed the `LOG_BASH_DIR` external directory path logic.
- Conditional appenders (logstash, kafka, metric) can still be enabled by
uncommenting the corresponding `<appender-ref>` elements — these are documented
with inline comments.
**5. Spring AOT Compatibility: `@Resource` → `@Autowired` Setter Injection**
- **`AbstractSeataInstanceStrategy`**: Replaced `@Resource` field injection
with `@Autowired` setter-based injection for `registryProperties`,
`serverProperties`, and `registryNamingServerProperties`. Removed
`ApplicationContext` dependency and `@PostConstruct` initialization —
properties are now injected directly via setters, which is compatible with
Spring AOT's closed-world analysis.
- **`ServerInstanceStrategyConfig`**: Changed `seataInstanceStrategy()` bean
method to accept dependencies via constructor parameters and pass them to the
strategy via setters, eliminating the implicit `ApplicationContext.getBean()`
lookup.
- **`SpringBootConfigurationProvider`**: Adjusted for AOT compatibility.
**6. Build Infrastructure (`build/pom.xml`, root `pom.xml`, `Makefile`)**
- `build/pom.xml`:
- Added `native-maven-plugin` version (`1.1.3`) to `pluginManagement`.
- Added default `native.platform` property (promoted from
`server/pom.xml`) so it is available to all submodules for GraalVM native-image
builds.
- Root `pom.xml`:
- Added Spotless Maven plugin configuration for JSON formatting of
native-image metadata files.
- Added OS/arch auto-activation profiles (`native-linux-*`,
`native-darwin-*`, `native-windows-*`) — promoted from `server/pom.xml` so the
`native.platform` property is available to all submodules for GraalVM
native-image builds.
- `Makefile`:
- Added `package-server-native-pre`, `package-server-native`,
`package-server-native-only` targets for building native images.
- Added `spotless-check` and `spotless-apply` targets.
- Added `-e` flag to all Maven commands for consistent error output.
- Widened help text column width.
**7. Dependency Update**
- Upgraded `zstd-jni` from `1.5.0-4` to `1.5.7-3` (`dependencies/pom.xml`).
**8. Test Adjustment**
- Disabled `AppenderTest` (`@Disabled`) due to the logback configuration
simplification that removed Janino-based conditional appender logic.
#### Usage
Build the native image:
```bash
# One-step: build all dependencies and compile native image
make package-server-native
# Or manually:
mvn clean install -DskipTests -pl server -am
mvn clean package -DskipTests -pl server -Pnative spring-boot:process-aot
native:compile
```
Run the native binary (no JDK required):
```bash
./server/target/seata-server-{version}-{platform}
```
### Ⅱ. Does this pull request fix one issue?
This PR implements the feature proposal described in issue #8137 (Spring
Boot 4 upgrade) follow-up — adding GraalVM Native Image support to the Seata
Server for improved deployment efficiency and cloud-native compatibility.
### Ⅲ. Why don't you add test cases (unit test/integration test)?
- The native image build itself serves as an integration test — the CI
workflow (`native.yml`) builds native binaries on 5 platforms on every PR/push,
and a successful native image compilation validates the GraalVM reachability
metadata and AOT compatibility.
- `AppenderTest` has been disabled because it tested Janino `<if>`
conditional logic in `logback-spring.xml`, which was removed for GraalVM
compatibility. The logback appender behavior (console, file) is implicitly
verified by the native image build succeeding and the server starting correctly.
- A `nativeTest` Maven profile is provided for future AOT-based native
testing using `junit-platform-launcher`.
### Ⅳ. Describe how to verify it
**Option 1: Local verification (requires GraalVM JDK 25)**
```bash
# Build dependencies
mvn clean install -DskipTests -pl server -am
# Compile native image
mvn clean package -DskipTests -pl server -Pnative spring-boot:process-aot
native:compile
# Run the native server
./server/target/seata-server-*-$(uname -s | tr '[:upper:]'
'[:lower:]')-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
```
Expected: The Seata Server starts in **milliseconds** (vs. seconds in JVM
mode) and is ready to accept transactions.
**Option 2: CI verification**
Check the `Native Build` workflow results on this PR — it builds native
images on ubuntu-24.04 (amd64), ubuntu-24.04-arm (arm64), macos-26-intel,
macos-26 (apple silicon), and windows-latest.
### Ⅴ. Special notes for reviews
1. **GraalVM reachability metadata** (`reflect-config.json`,
`resource-config.json`, `proxy-config.json`): These files were generated
through iterative native image builds and testing. They register all classes,
methods, resources, and proxies that Seata accesses via reflection at runtime.
Reviewers should focus on whether any critical Seata components are missing
from these configs.
2. **Injection style change**: `@Resource` field injection was replaced with
`@Autowired` setter/constructor injection in `AbstractSeataInstanceStrategy`
and `ServerInstanceStrategyConfig`. This is required because Spring AOT's
closed-world analysis cannot resolve `@Resource`-injected fields during native
compilation. The runtime behavior is identical.
3. **logback-spring.xml breaking change**: The removal of Janino `<if>`
conditions means that `LOGSTASH_APPENDER_ENABLED`, `KAFKA_APPENDER_ENABLED`,
and `METRIC_APPENDER_ENABLED` properties no longer dynamically control appender
inclusion at runtime. Users who need these appenders must manually uncomment
the corresponding `<appender-ref>` elements in `logback-spring.xml`. This is a
known limitation of GraalVM native images (no runtime bytecode generation). A
follow-up PR could add programmatic appender registration via Spring's
`@Conditional` beans.
4. **Phased approach**: This PR focuses on **Phase 1** — basic server
startup, configuration loading, and core transaction coordination in native
mode. Full feature parity with JVM mode (all serializers, all store modes, all
discovery modes) will be addressed in follow-up PRs as testing coverage expands.
5. **PGO (Profile-Guided Optimization)**: Not included in this PR. Can be
added later to further improve native image runtime performance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]