@@ -68,19 +68,31 @@ repositories {
6868}
6969
7070
71- private static int getVersionCode () {
71+ private int getVersionCode () {
7272 def cmd = ' git rev-list HEAD --first-parent --count'
73- cmd. execute(). text. trim(). toInteger()
73+ try {
74+ return cmd. execute(). text. trim(). toInteger()
75+ } catch (Exception e) {
76+ logger. error(" Failed to get version code with git, return 1 by default.\n ${ e.message} " )
77+ return 1
78+ }
7479}
7580
76- private static String getVersionName () {
81+ private String getVersionName () {
7782 def cmd = ' git describe --tags --long --first-parent --abbrev=7 --dirty="-dev"'
78- def v = cmd. execute(). text. trim()
79- def matcher = v =~ / ^v([\d |.]+)-\d +-g[A-Za-z0-9]{7}(-dev)?$/
83+ try {
84+ def v = cmd. execute(). text. trim()
85+ def matcher = v =~ / ^v([\d |.]+)-\d +-g[A-Za-z0-9]{7}(-dev)?$/
8086
81- if (! matcher) {
82- throw new RuntimeException (" Cannot match git tag name. raw=$v " )
87+ if (! matcher) {
88+ logger. error(" Failed to get version name with git.\n " +
89+ " Cannot match git tag describe, return <UNKNOWN> by default. raw=$v " )
90+ return " UNKNOWN"
91+ }
92+ def suffix = matcher[0 ][2 ] ? matcher[0 ][2 ] : ' '
93+ return " ${ matcher[0][1]} $suffix "
94+ } catch (Exception e) {
95+ logger. error(" Failed to get version name with git, return <UNKNOWN> by default.\n ${ e.message} " )
96+ return " UNKNOWN"
8397 }
84- def suffix = matcher[0 ][2 ] ? matcher[0 ][2 ] : ' '
85- " ${ matcher[0][1]} $suffix "
8698}
0 commit comments