Retro Eye care Haitian Deep Dark Default

Build GraalVM Native Image(Alpha)


This section mainly introduces how to build the Native Image of ShardingSphere-Proxy and the corresponding Docker Image through the native-image component of GraalVM.


version: "3.8"

      - ./custom/conf:/opt/shardingsphere-proxy-native/conf
      - "3307:3307"
  • If you find that the build process has missing GraalVM Reachability Metadata, a new issue should be opened at, and submit a PR containing GraalVM Reachability Metadata missing from ShardingSphere itself or dependent third-party libraries.

  • The master branch of ShardingSphere is not yet ready to handle unit tests in Native Image, you always need to build GraalVM Native Image in the process, Plus -DskipNativeTests or -DskipTests parameter specific to GraalVM Native Build Tools to skip unit tests in Native Image.

  • The following algorithm classes are not available under GraalVM Native Image due to involved.

    • org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm
    • org.apache.shardingsphere.sharding.algorithm.sharding.inline.ComplexInlineShardingAlgorithm
    • org.apache.shardingsphere.sharding.algorithm.sharding.hint.HintInlineShardingAlgorithm
  • At this stage, ShardingSphere Proxy in the form of GraalVM Native Image does not support row expressions using the default implementation of the InlineExpressionParser SPI. This first results in the actualDataNodes property of the data sharding feature that can only be configured using other implementations of the InlineExpressionParser SPI, for example using LITERAL implemented InlineExpressionParser SPI for row expression, i.e. <LITERAL>ds_0.t_order_0, ds_0.t_order_1 or <LITERAL>ds_0.t_user_0, ds_15.t_user_1023.

  • This section assumes a Linux (amd64, aarch64), MacOS (amd64) or Windows (amd64) environment. If you are on MacOS (aarch64/M1) environment, you need to follow which is not closed yet.

  • org.apache.shardingsphere:shardingsphere-cluster-mode-repository-etcd is affected by and cannot be used.


  1. Install and configure GraalVM Community Edition or a downstream distribution of GraalVM Community Edition for JDK 17 according to If SDKMAN! is used,
sdk install java 17.0.8-graalce
  1. Install the local toolchain as required by

  2. If you need to build a Docker Image, make sure docker-ce is installed.

  3. First, you need to execute the following command in the root directory of the project to collect the GraalVM Reachability Metadata of the Standard form for all submodules.

./mvnw -PgenerateStandardMetadata -DskipNativeTests -B -T1C clean test


  1. Get Apache ShardingSphere Git Source
  1. Build the product on the command line, in two cases.
  • Scenario 1: No need to use JARs with SPI implementations or 3rd party dependencies

  • Execute the following command in the same directory of Git Source to directly complete the construction of Native Image.

./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native -DskipTests clean package
  • Scenario 2: It is necessary to use a JAR that has an SPI implementation or a third-party dependent JAR of a LICENSE such as GPL V2.

  • Add SPI implementation JARs or third-party dependent JARs to dependencies in distribution/proxy-native/pom.xml. Examples are as follows

  • Build GraalVM Native Image via command line.
./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native -DskipTests clean package
  1. To start Native Image through the command line, you need to bring 4 parameters. The first parameter is the Port used by ShardingSphere Proxy, the second parameter is the /conf folder containing server.yaml written by you, the third parameter is the Address of the bound port, and the fourth parameter is Force Start, if it is true, it will ensure that ShardingSphere Proxy Native can start normally no matter whether it is connected or not. Assuming the folder ./custom/conf already exists, the example is
./apache-shardingsphere-proxy-native 3307 ./custom/conf "" false
  1. If you need to build a Docker Image, execute the following command on the command line after adding dependencies that exist for SPI implementation or third-party dependencies.
./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native,docker.native -DskipTests clean package
  • Assuming that there is a conf folder containing server.yaml as ./custom/conf, you can start the Docker Image corresponding to GraalVM Native Image through the following docker-compose.yml file.
version: "3.8"

    image: apache/shardingsphere-proxy-native:latest
      - ./custom/conf:/opt/shardingsphere-proxy-native/conf
      - "3307:3307"
  • If you don’t make any changes to the Git Source, the commands mentioned above will use oraclelinux:9-slim as the Base Docker Image. But if you want to use a smaller Docker Image like busybox:glic, or scratch as the Base Docker Image, you need according to, add operations such as -H:+StaticExecutableWithDynamicLibC to jvmArgs as the native profile of pom.xml. Also note that some 3rd-party dependencies will require more system libraries such as libdl to be installed in the Dockerfile. So make sure to tune distribution/proxy-native according to your usage pom.xml and Dockerfile below.


  1. Download and untar it to distribution/proxy-native in ShardingSphere Git Source.

  2. Modify the native profile of distribution/proxy-native/pom.xml, Add the following jvmArgs to the configuration of org.graalvm.buildtools:native-maven-plugin.

    <arg>-Dskywalking.agent.service_name="your service name"</arg>
    <arg>-Dskywalking.collector.backend_service="your skywalking oap ip and port"</arg>
  1. Build the GraalVM Native Image from the command line.
./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native -DskipTests clean package