#!/usr/bin/env python3 # -*- coding: utf-8 -*- r"""Java 网关离线构建(与 backend-java/build_offline.py 同法:mvn -o compile + 组装 target/lib)。""" from __future__ import annotations import os import pathlib import shutil import subprocess import sys HERE = pathlib.Path(__file__).resolve().parent MVN = r'D:\Program Files\apache-maven-3.8.9\bin\mvn.cmd' REPO = r'C:\Users\86189\.m2\repository' def main() -> int: print('① 离线编译(mvn -o compile)…') r = subprocess.run([MVN, '-o', '-q', '-s', str(HERE / 'settings-offline.xml'), '-Dmaven.repo.local=' + REPO, '-Dmaven.legacyLocalRepo=true', '-Dmaven.test.skip=true', 'compile'], cwd=str(HERE)) if r.returncode != 0: print(' [X] 编译失败') return r.returncode print(' [OK] 编译通过') print('② 组装依赖到 target/lib …') r2 = subprocess.run([MVN, '-o', '-q', '-s', str(HERE / 'settings-offline.xml'), '-Dmaven.repo.local=' + REPO, '-Dmaven.legacyLocalRepo=true', 'dependency:copy-dependencies', '-DoutputDirectory=target/lib'], cwd=str(HERE)) lib = HERE / 'target/lib' n = len(list(lib.glob('*.jar'))) if lib.exists() else 0 print(' %s target/lib(%d 个 jar)' % ('[OK]' if r2.returncode == 0 else '[X]', n)) print('③ 启动: java -cp "target/classes;target/lib/*" com.guanlan.gateway.GuanlanGatewayApplication') return 0 if r2.returncode == 0 else r2.returncode if __name__ == '__main__': raise SystemExit(main())