Background
Recently, I find that we need to type some very long gradle commands to run build, check, test, etc. It's very annoying, isn't it?
Idea
Can I write a script to run the gradle commands? Is that easy? If so, I only need to type 2 or 3 charactors(like "go" or "go 1") in this way. Considering we are working with windows 7, so I choose windows batch script to make my dream come true. ^_^
Solution
Step 1: display a menu in the command line
@echo off
::file name: go.bat
::##################Menu##################
:menuLoop
echo Task List
echo 1 Local build (clean build)
echo 2 Quick check (clean check -x :integrationTest ...)
echo 3 Intellij config (--refresh-dependencies cleanIdea idea)
set choice=
echo.&set /p choice=Choose one task or hit ENTER to quit: ||(goto :EOF)
echo.&call :task_%choice%
goto :EOF ::##################Tasks##################
:task_1
call gradle clean build
goto :EOF :task_2
call gradle clean check -x :integrationTest -x :coberturaIntegrationTest
goto :EOF :task_3
call gradle --refresh-dependencies cleanIdea idea
goto :EOF
Step 2: accept one parameters
::#################Accept Parameters#################
::set option=%1
if "%1" == "" (
goto :menuLoop
) else (
goto :task_%1
)
Put this part before the menu codes, then it should work.
OK, now I only need to type "go 2" if I want to do a quick check on my project codes.
NOTE: some tasks in the batch script above were written based on our project requirements. You need to make some changes about the commands.