-
Notifications
You must be signed in to change notification settings - Fork 45
/
build-gradle.sh
executable file
·87 lines (73 loc) · 1.64 KB
/
build-gradle.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
VERSION="7.6.1"
BREW_VERSION=${VERSION:0:1}
INSTALL_DIR=gradle
CMD=$(which gradle)
check_gradle_installed() {
echo "Checking if gradle is installed globally..."
which gradle > /dev/null 2>&1
return $?
}
install() {
which brew > /dev/null 2>&1
if [ $? -eq 0 ];
then
echo "Homebrew detected. Install gradle globally?"
echo "[yes/no] default: yes"
read brew
if [[ "$brew" == "yes" ]] || [[ "$brew" == "" ]];
then
echo "brew"
install_brew
else
echo "local"
install_locally
fi
else
install_locally
fi
}
install_brew() {
echo "Installing version $BREW_VERSION globally with Homebrew..."
brew install "gradle@$BREW_VERSION"
ln -s /usr/local/opt/gradle@$BREW_VERSION/bin/gradle /usr/local/bin/gradle
CMD=$(which gradle)
}
install_locally() {
echo "Installing version $VERSION locally @ ./$INSTALL_DIR/..."
ls gradle > /dev/null 2>&1
if [ $? -gt 0 ];
then
mkdir gradle
fi
curl "https://downloads.gradle-dn.com/distributions/gradle-$VERSION-bin.zip" > "gradle/gradle-$VERSION-bin.zip"
unzip -d gradle "gradle/gradle-$GRADLE_VERSION-bin.zip"
export GRADLE_HOME="gradle/gradle-$VERSION"
CMD="$GRADLE_HOME/bin/gradle"
}
init() {
ls settings.gradle > /dev/null 2>&1
if [ $? -gt 0 ];
then
echo "Setting up project..."
$CMD init <<< "\r\rno\r"
fi
}
build() {
which gradle > /dev/null 2>&1
if [ $? -gt 0 ];
then
export GRADLE_HOME="gradle/gradle-$VERSION"
CMD="$GRADLE_HOME/bin/gradle"
fi
$CMD build
}
check_gradle_installed
installed=$?
if [ $installed -gt 0 ] ;
then
echo "Gradle not found. Installing..."
install
fi
init
build