build_offline.py 1.6 KB

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