完整依赖和 profiles 配置
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<graalvm.version>23.1.1</graalvm.version>
<tio-boot.version>1.8.7</tio-boot.version>
<lombok-version>1.18.30</lombok-version>
<hotswap-classloader.version>1.2.2</hotswap-classloader.version>
<final.name>web-hello</final.name>
<main.class>com.litongjava.tio.web.hello.HelloApp</main.class>
</properties>
<dependencies>
<dependency>
<groupId>com.litongjava</groupId>
<artifactId>tio-boot</artifactId>
<version>${tio-boot.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok-version}</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.litongjava</groupId>
<artifactId>hotswap-classloader</artifactId>
<version>${hotswap-classloader.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<!-- 开发环境 -->
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</profile>
<!-- 生产环境 -->
<profile>
<id>production</id>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.4</version>
<configuration>
<mainClass>${main.class}</mainClass>
<excludeGroupIds>org.projectlombok</excludeGroupIds>
</configuration>
<!-- 设置执行目标 -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- assembly -->
<profile>
<id>assembly</id>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<dependencies>
<!-- GraalVM 环境使用 jdk log -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.31</version>
</dependency>
<!-- GraalVM -->
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${final.name}</finalName>
<plugins>
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>21.2.0</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<skip>false</skip>
<imageName>${final.name}</imageName>
<mainClass>${main.class}</mainClass>
<buildArgs>
-H:+RemoveSaturatedTypeFlows
--allow-incomplete-classpath
--no-fallback
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
依赖解释
<properties>
部分
project.build.sourceEncoding
: 设置项目的源代码编码为 UTF-8。java.version
: 定义 Java 版本为 1.8。maven.compiler.source
和maven.compiler.target
: 指定 Maven 编译器使用的 Java 版本。graalvm.version
: 设置 GraalVM 版本为 23.1.1。tio.boot.version
: 定义 TIO Boot 版本为lombok-version
: 指定 Lombok 库的版本为 1.18.30。final.name
: 指定构建的最终文件名为web-hello
。main.class
: 定义项目的主类为com.litongjava.tio.web.hello.App
。
<dependencies>
部分 列出了项目所需的依赖库:
tio-boot
: TIO Boot 库,用于 TIO 框架的启动和配置。lombok
: 一个 Java 库,用于自动处理一些常见的任务,如 getter/setter 的生成。hotswap-classloader
: 一个类加载器,支持热交换功能,用于动态替换类定义。
<profiles>
部分 定义了不同环境下的特定配置:
开发环境 (development): 当 Maven 构建在开发环境下时,会添加
logback-classic
依赖,用于日志管理。生产环境 (production): 在生产环境中使用 spring-boot-maven-plugin 打包
自定义环境(assembly): 同样使用
logback-classic
,并配置了maven-jar-plugin
和maven-assembly-plugin
用于打包。GraalVM 环境 (native): 用于 GraalVM 的特定配置,包括
slf4j-jdk14
和graal-sdk
依赖,以及native-image-maven-plugin
插件,用于生成 GraalVM 的本地映像。