# Gitee Go CI/CD 配置 # Gitee CI 语法基于 GitLab CI,文件名必须为 .gitee-ci.yml # 放置在项目根目录,推送后自动触发流水线 # # 使用方式: # 1. 开启 Gitee 仓库的 CI/CD 功能(管理 > CI/CD) # 2. 确保 .gitee-ci.yml 在项目根目录 # 3. 推送代码后自动触发 image: maven:3.9-eclipse-temurin-21 stages: - build - test - quality - security - package - release variables: MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" cache: key: "${CI_COMMIT_REF_SLUG}" paths: - .m2/repository/ # ============================================ # 构建阶段 — 根据分支自动选择 JDK # ============================================ build:java21: stage: build image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B clean compile artifacts: paths: - target/classes/ expire_in: 1 hour only: - master - jre21 build:java17: stage: build image: maven:3.9-eclipse-temurin-17 script: - ./mvnw -B clean compile artifacts: paths: - target/classes/ expire_in: 1 hour only: - master - jre17 build:java11: stage: build image: maven:3.9-eclipse-temurin-11 script: - ./mvnw -B clean compile artifacts: paths: - target/classes/ expire_in: 1 hour only: - master - jre11 build:java8: stage: build image: maven:3.9-eclipse-temurin-8 script: - ./mvnw -B clean compile artifacts: paths: - target/classes/ expire_in: 1 hour only: - master - jre8 # ============================================ # 测试阶段 — 各 JDK 独立跑测试 # ============================================ test:java21: stage: test image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B test artifacts: reports: junit: target/surefire-reports/*.xml paths: - target/surefire-reports/ - target/site/jacoco/ expire_in: 7 days only: - master - jre21 test:java17: stage: test image: maven:3.9-eclipse-temurin-17 script: - ./mvnw -B test artifacts: reports: junit: target/surefire-reports/*.xml paths: - target/surefire-reports/ expire_in: 7 days only: - master - jre17 test:java11: stage: test image: maven:3.9-eclipse-temurin-11 script: - ./mvnw -B test artifacts: reports: junit: target/surefire-reports/*.xml paths: - target/surefire-reports/ expire_in: 7 days only: - master - jre11 test:java8: stage: test image: maven:3.9-eclipse-temurin-8 script: - ./mvnw -B test artifacts: reports: junit: target/surefire-reports/*.xml paths: - target/surefire-reports/ expire_in: 7 days only: - master - jre8 # ============================================ # 代码质量检查 (仅 Java 21) # ============================================ checkstyle: stage: quality image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B checkstyle:check artifacts: paths: - target/checkstyle-result.xml expire_in: 7 days allow_failure: true pmd: stage: quality image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B pmd:pmd artifacts: paths: - target/pmd-report.xml expire_in: 7 days allow_failure: true # ============================================ # 安全扫描 (仅 master/jre21) # ============================================ owasp-check: stage: security image: maven:3.9-eclipse-temurin-21 variables: MAVEN_OPTS: "-Xmx2048m -Dmaven.repo.local=.m2/repository" script: - ./mvnw -B org.owasp:dependency-check-maven:check artifacts: paths: - target/dependency-check-report.html expire_in: 14 days allow_failure: true only: - master - jre21 # ============================================ # 打包 # ============================================ package: stage: package image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B package -DskipTests artifacts: paths: - target/*.jar expire_in: 30 days # ============================================ # 发布到 Maven Central (仅 tag, 手动触发) # ============================================ release:maven-central: stage: release image: maven:3.9-eclipse-temurin-21 script: - ./mvnw -B deploy -Dgpg.skip=false only: - tags when: manual # 需要在 Gitee 仓库设置中配置 CI/CD 变量: # MAVEN_CENTRAL_USERNAME — OSSRH 用户名 # MAVEN_CENTRAL_PASSWORD — OSSRH 密码 # GPG_PRIVATE_KEY — GPG 私钥 (ASCII armored) # GPG_PASSPHRASE — GPG 密钥密码