源本科技 | 码上会

SCA 项目骨架

2026/05/19
3
0

创建项目

  • 首先创建一个名为 sca 的文件夹,作为我们的项目目录

  • 使用 IDEA 打开这个目录

创建依赖管理模块

  • 创建一个名为 sca-dependencies 的模块,pom.xml 配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lusifer</groupId>
    <artifactId>sca-dependencies</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>

    <name>${project.artifactId}</name>
    <description>依赖管理模块</description>

    <properties>
        <!-- 项目版本统一管理 -->
        <revision>1.0.0-SNAPSHOT</revision>
        <flatten-maven-plugin.version>1.7.3</flatten-maven-plugin.version>

        <!-- 第三方工具类 -->
        <hutool.version>5.8.44</hutool.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>${hutool.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <!-- Flatten 统一 revision 版本 -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>${flatten-maven-plugin.version}</version>
                <configuration>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                    <updatePomFile>true</updatePomFile>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                    </execution>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

创建 Parent POM

  • sca 目录下创建 pom.xml

  • 当前这个项目我们称之为 parentroot 项目

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lusifer</groupId>
    <artifactId>sca</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>

    <name>${project.artifactId}</name>
    <description>微服务架构案例项目</description>

    <properties>
        <!-- 项目版本统一管理 -->
        <revision>1.0.0-SNAPSHOT</revision>
        <flatten-maven-plugin.version>1.7.3</flatten-maven-plugin.version>

        <!-- Maven 相关 -->
        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring -->
        <spring.boot.version>3.5.0</spring.boot.version>
        <spring.cloud.version>2025.0.0</spring.cloud.version>
        <spring.cloud.alibaba.version>2025.0.0.0</spring.cloud.alibaba.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Spring Boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Spring Cloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring.cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Spring Cloud Alibaba -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring.cloud.alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Project Dependencies -->
            <dependency>
                <groupId>com.lusifer</groupId>
                <artifactId>sca-dependencies</artifactId>
                <version>${revision}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Spring Boot -->
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.version}</version>
                    <configuration>
                        <executable>true</executable>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>repackage</goal>
                                <goal>build-info</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Compiler -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <!-- 适配 Maven 3.9.8 版本,如果升级到 4.x 可以删除版本号 -->
                    <version>3.11.0</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <skip>true</skip>
                        <encoding>${project.build.sourceEncoding}</encoding>
                        <compilerArgs>
                            <arg>-parameters</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>

                <!-- Flatten 统一 revision 版本 -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>flatten-maven-plugin</artifactId>
                    <version>${flatten-maven-plugin.version}</version>
                    <configuration>
                        <flattenMode>resolveCiFriendliesOnly</flattenMode>
                        <updatePomFile>true</updatePomFile>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>flatten</goal>
                            </goals>
                            <id>flatten</id>
                            <phase>process-resources</phase>
                        </execution>
                        <execution>
                            <goals>
                                <goal>clean</goal>
                            </goals>
                            <id>flatten.clean</id>
                            <phase>clean</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <modules>
        <module>sca-dependencies</module>
    </modules>
</project>
  • 在终端中使用 mvn clean package 测试是否能够正常打包

创建通用工具模块

  • 创建一个名为 sca-common 的模块pom.xml 配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.lusifer</groupId>
        <artifactId>sca</artifactId>
        <version>${revision}</version>
    </parent>

    <artifactId>sca-common</artifactId>
    <packaging>jar</packaging>

    <name>${project.artifactId}</name>
    <description>通用类库模块</description>

    <dependencies>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
    </build>
</project>
  • 在 Parent 项目的 pom.xml 中追加与之对应的 module,名为 sca-common

补充说明

https://sca.aliyun.com/docs/2025.x/overview/version-explain/

2025.x 分支

2025.x 分支包含两个主要版本线,分别适配不同的 Spring Boot 和 Spring Cloud 版本。各版本按从新到旧排列如下表(最新版本用 * 标记):

2025.1.x

适配 Spring Boot 4.0.x,Spring Cloud 2025.1.x 版本。

Spring Cloud Alibaba Version

Spring Cloud Version

Spring Boot Version

2025.1.0.0

2025.1.0

4.0.0

2025.0.x

适配 Spring Boot 3.5.x,Spring Cloud 2025.0.x 版本。

Spring Cloud Alibaba Version

Spring Cloud Version

Spring Boot Version

2025.0.0.0

2025.0.0

3.5.0