2014-01-10 20:10:20 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
bindir="$(dirname $0)"
|
|
|
|
basedir="$(dirname $bindir)"
|
|
|
|
verdir="${basedir}/versions"
|
|
|
|
args=("$@")
|
|
|
|
|
|
|
|
run_gradle() {
|
2014-12-12 12:29:16 +01:00
|
|
|
"${verdir}/${v_found}/bin/gradle" "${args[@]}"
|
2014-01-10 20:10:20 +01:00
|
|
|
exit $?
|
|
|
|
}
|
|
|
|
|
2014-03-11 17:33:19 +01:00
|
|
|
contains() {
|
|
|
|
local e
|
|
|
|
for e in $2; do
|
|
|
|
[[ $e == $1 ]] && return 0;
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-04-18 23:36:01 +02:00
|
|
|
# key-value pairs of what gradle version (value) each gradle plugin version
|
|
|
|
# (key) should accept. plugin versions are actually prefixes and catch sub-
|
|
|
|
# versions as well. Pairs are taken from:
|
|
|
|
# https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle
|
2018-04-05 14:11:28 +02:00
|
|
|
d_plugin_k=(3.1 3.0 2.3 2.2 2.1.3 2.1 2.0 1.5 1.3 1.2 1.1 1.0 0.14 0.13 0.12 0.11 0.10 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2)
|
|
|
|
d_plugin_v=(4.4 4.1 3.3 2.14.1 2.14.1 2.12 2.12 2.4 2.4 2.3 2.2.1 2.2.1 2.1 2.1 1.12 1.12 1.12 1.11 1.10 1.9 1.8 1.6 1.6 1.4 1.4)
|
2014-01-10 20:10:20 +01:00
|
|
|
|
2015-08-13 20:28:01 +02:00
|
|
|
# All gradle versions we know about
|
2018-04-20 17:55:51 +02:00
|
|
|
plugin_v=(4.7 4.6 4.5.1 4.5 4.4.1 4.4 4.3.1 4.3 4.2.1 4.2 4.1 4.0.2 4.0.1 4.0 3.5.1 3.5 3.4.1 3.4 3.3 3.2.1 3.2 3.1 3.0 2.14.1 2.14 2.13 2.12 2.11 2.10 2.9 2.8 2.7 2.6 2.5 2.4 2.3 2.2.1 2.2 2.1 1.12 1.11 1.10 1.9 1.8 1.7 1.6 1.4)
|
2015-08-13 20:28:01 +02:00
|
|
|
|
2016-09-15 20:10:18 +02:00
|
|
|
v_all=${plugin_v[@]}
|
|
|
|
echo "Available gradle versions: ${v_all[@]}"
|
2014-03-11 17:33:19 +01:00
|
|
|
|
2014-11-15 21:38:48 +01:00
|
|
|
# Earliest takes priority
|
2016-09-15 20:14:40 +02:00
|
|
|
for f in {.,..}/gradle/wrapper/gradle-wrapper.properties; do
|
|
|
|
[[ -f $f ]] || continue
|
|
|
|
while read l; do
|
|
|
|
if [[ $l == 'distributionUrl='* ]]; then
|
|
|
|
wrapper_ver=$(echo -n "$l" | sed "s/.*gradle-\\([0-9\\.\\+]\\+\\).*/\\1/")
|
|
|
|
fi
|
|
|
|
done < $f
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -n $wrapper_ver ]]; then
|
|
|
|
v_found=$wrapper_ver
|
|
|
|
echo "Found $v_found via distributionUrl"
|
|
|
|
run_gradle
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Earliest takes priority
|
|
|
|
for f in {.,..}/build.gradle; do
|
2014-01-10 20:10:20 +01:00
|
|
|
[[ -f $f ]] || continue
|
|
|
|
while read l; do
|
2014-05-12 15:49:23 +02:00
|
|
|
if [[ -z "$plugin_pver" && $l == *'com.android.tools.build:gradle:'* ]]; then
|
2014-01-10 20:10:20 +01:00
|
|
|
plugin_pver=$(echo -n "$l" | sed "s/.*com.android.tools.build:gradle:\\([0-9\\.\\+]\\+\\).*/\\1/")
|
2015-12-24 23:08:31 +01:00
|
|
|
elif [[ -z "$wrapper_ver" && $l == *'gradleVersion = '* ]]; then
|
2014-12-31 13:29:03 +01:00
|
|
|
wrapper_ver=$(echo -n "$l" | sed "s/.*gradleVersion *=* *[\"']\\([0-9\\.]\\+\\)[\"'].*/\\1/")
|
2014-01-10 20:10:20 +01:00
|
|
|
fi
|
|
|
|
done < $f
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -n $wrapper_ver ]]; then
|
|
|
|
v_found=$wrapper_ver
|
2014-01-15 18:05:26 +01:00
|
|
|
echo "Found $v_found via gradleVersion"
|
2014-01-10 20:10:20 +01:00
|
|
|
run_gradle
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n $plugin_pver ]]; then
|
|
|
|
i=0
|
|
|
|
match=false
|
|
|
|
for k in ${d_plugin_k[@]}; do
|
|
|
|
if [[ $plugin_pver == ${k}* ]]; then
|
|
|
|
plugin_ver=${d_plugin_v[$i]}
|
|
|
|
match=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
let i++
|
|
|
|
done
|
|
|
|
if $match; then
|
|
|
|
v_found=$plugin_ver
|
2014-01-15 18:05:26 +01:00
|
|
|
echo "Found $v_found via gradle plugin version $k"
|
2014-01-10 20:10:20 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-09-15 20:10:18 +02:00
|
|
|
# Find the highest version available
|
|
|
|
for v in ${plugin_v[*]}; do
|
|
|
|
if contains $v "${v_all[*]}"; then
|
|
|
|
v_def=$v
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2014-03-07 15:37:14 +01:00
|
|
|
if [[ -z $v_found ]]; then
|
|
|
|
echo "No suitable gradle version found - defaulting to $v_def"
|
|
|
|
v_found=$v_def
|
|
|
|
fi
|
2014-01-10 20:10:20 +01:00
|
|
|
|
|
|
|
run_gradle
|