maven.yml
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 打包校验:JDK 版本取自根 pom.xml 的 java.version,与当前分支保持一致
# 参考:https://docs.github.com/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-maven
name: Java CI with Maven
on:
push:
branches: [ master, master-jdk17, master-jdk25 ]
# pull_request:
# branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# 读取根 pom.xml 的 properties/java.version(1.8 -> 8),缺失或无效时直接失败
- name: Resolve JDK version
id: jdk
run: |
python3 -I - <<'EOF' >> "$GITHUB_OUTPUT"
import xml.etree.ElementTree as ET
ns = {'m': 'http://maven.apache.org/POM/4.0.0'}
v = (ET.parse('pom.xml').getroot().findtext('m:properties/m:java.version', namespaces=ns) or '').strip().removeprefix('1.')
if not v.isdigit():
raise SystemExit(f'根 pom.xml 的 properties/java.version 缺失或无效: {v!r}')
print(f'version={v}')
EOF
- name: Set up JDK ${{ steps.jdk.outputs.version }}
uses: actions/setup-java@v6
with:
java-version: ${{ steps.jdk.outputs.version }}
distribution: 'temurin'
cache: maven
cache-dependency-path: '**/pom.xml'
- name: Build with Maven
run: mvn -B package --file pom.xml -Dmaven.test.skip=true