gdub(gwonthecommandline)isagradle/gradlewwrapper.NottobeconfusedwiththeGradleWrapper,gwinvokes./gradlewonprojectswhereoneisconfigured,andfallsbacktousethegradlefromthe$PATHifawrapperisnotavailable.Also,gwis66%shortertotypethangradleand78%shortertotypethan./gradlew.
InstallationTherearenowafewwaystoinstallgdub,withmoreontheway.Usewhicheverismostconvenientforyouorfeelfreetosuggestanother!
HomebrewIfyouareonOSXandnotusinghomebrew,I'mnotquitesurewhattodowithyou.Installgdubwithhomebrewlikeso:
brewinstallgdubMacPortsIfyouuseMacPorts,youcaninstallgdublikeso:
sudoportinstallgdubbpkgIfyouusebpkg,youmayinstalllikeso:
bpkginstalldougborg/gdub-gInstallinggdubfromsourceYouwillprobablywanttoinstallGradlefirst.WhilethisisnottechnicallynecessaryifallyourprojectsareusingaGradleWrapper,itisagoodideatohavethelatestversionofgradleavailablesystem-widebecausesomehandyGradlefeaturesareavailableoutsidethecontextofanexistingproject.
Checkoutacopyofthegdubrepository.Then,eitheraddthegdubbindirectorytoyour$PATH,orruntheprovidedinstallcommandwiththelocationtotheprefixinwhichyouwanttoinstallgdub.Thedefaultprefixis/usr/local.
Forexample,toinstallgdubinto/usr/local/bin:
gitclonehttps://github.com/dougborg/gdub.gitcdgdub./installNote:youmayneedtorun./installwithsudoifyoudonothavepermissiontowritetotheinstallationprefix.
AliasingthegradlecommandFormaximumfidelityaddagradlealiastogwtoyourshell'sconfigurationfile.
Examplebash:
echo"aliasgradle=gw">>~/.bashrcsource~/.bashrcFromnowonyoucanjusttypegradle...fromwhereveryouareandgwtakescareoftherest.Happinessensues!
Whygdub?TheproblemswithgradleandgradlewgdubisaconveniencefordevelopersrunninglocalGradlecommandsandaddressesafewminorshortcomingsofgradleandgradlew'scommandlinebehaviour.Theseareknownissues,andtheyaresettobeaddressedinfutureversionsofGradle.Ifyouareinterestedinthediscussionssurroundingthem,checkout:
IssueGradle-2429SpencerAllain'sGradleForumPostPhilSwenson'sGradleForumPostHerearetheissuesIfeelaremostimportant,andtheonesgdubattemptstoaddress:
Youhavetoprovidearelativepathtobuild.GradleIfyouareusingthegradlecommand,andyouarenotinthesamedirectoryasthebuild.gradlefileyouwanttorun,youhavetoprovidegradlethepath.Dependingonwhereyouhappentobe,thiscanbesomewhatcumbersome:
$pwd~/myProject/src/main/java/org/project$gradle-b../../../../../build.gradlebuildWithgw,thisbecomes:
$gwbuildYouhavetoprovidearelativepathtogradlewIfyouareusinggradlewandyouwanttorunyourbuild,youneedtodosomethingsimiliarandprovidetherelativepathtothegradlewscript:
$pwd~/myProject/src/main/java/org/project/stuff$../../../../../../gradlewbuildAgain,withgwthisbecomes:
$gwbuildYouhaveacombinationoftheaboveproblemsIdon'tevenwanttotypeoutanexampleofthis,letalonedoitonaday-to-daybasis.Useyourimagination.
Typing./gradlewtoruntheGradlewrapperiskindofinconvenientEvenwithtabcompletionandsittingattherootofyourproject,youhavetotypeatleast./gr<tab>.ItgetsabitworseifyouhappentohaveaGradle.propertiesfile,andwiththeGradlewrapper,youhaveagradledirectorytocontendwithaswell.Asimplealiaswouldsolvethisproblem,butyoustillhavetheother(moreannoying)issuestocontendwith.
Youmeanttousetheproject'sgradlew,buttypedgradleinsteadThiscanbeaproblemiftheprojectyouarebuildinghascustomizationstotheGradlewrapperorforsomereasonisonlycompatiblewithacertainversionofGradlethatisconfiguredinthewrapper.IfyouknowtheprojectusesGradle,youmaybetemptedtojustuseyourownsystem'sGradlebinary.Thismightbeok,oritmightcausethebuildtobreak,butifaprojecthasagradlew,itisaprettysafebetyoushoulduseit,andnotwhateverGradledistributionyouhappentohaveinstalledonyoursystem.
ThegwpayoffAnywhereyouhappentobeonyourproject,youcanruntheGradletasksofyourprojectbytypinggw<tasks>,regardlessofwhetheryouusetheGradleWrapperinyourprojectornot.
gwworksbylookingupwardsfromyourcurrentdirectoryandwillrunthenearestbuild.Gradlefilewiththenearestgradlew.Ifagradlewcannotbefound,itwillrunthenearestbuild.Gradlewithyoursystem'sGradle.ThisisprobablyalwayswhatyouwanttodoifyouarerunningGradlefromwithinaproject'streethatusestheGradlebuildsystem.
评论