å ±æã©ã¤ãã©ãªã管çããããã« Sonatype ã® Nexus Repository Manager OSS ã使ç¨ãã ( çªå¤ç·¨ )( build.gradle ã«ã³ãã³ããæ¸ãã¦å®è¡ãã )
æ¦è¦
å¤é¨ã©ã¤ãã©ãªã«ä¾åããã©ã¤ãã©ãªã®ä½ãæ¹ã調ã¹ãããã«ãããããªã©ã¤ãã©ãªã® GitHub ãè¦ã¦ããã®ã§ãããspock ã® build.gradle ( https://github.com/spockframework/spock/blob/master/build.gradle ) ãè¦ãæã« commandLine "sh", "-c", """..."""
ã¨ããè¨è¿°ãè¦ã¤ãã¾ãããGradle ããã³ãã³ãããã®ã¾ã¾å®è¡ã§ããã¨ã¯åãã¦ç¥ãã¾ããã
使ãæ¹ãåããã¨çµæ§ä¾¿å©ããã«æããã®ã¨ãspock ã® build.gradle 㯠Linux ä¸ã§ sh ã§å®è¡ããåæ㧠Windows ã®å ´åã«ã¯ã©ãããã°ããã®ãåãããªãã£ãã®ã§ã調ã¹ã¦ã¿ã¾ãã
åç §ãããµã¤ãã»æ¸ç±
- Gradle Build Language Reference - Exec
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html
ç®æ¬¡
- cmd.exe ã§ï¼è¡ã³ãã³ããå®è¡ãã
- cmd.exe ã§ã¯
"""..."""
ã§ã³ãã³ããå®è¡ã§ããªãããã - .bat ãã¡ã¤ã«ãå®è¡ãã
- Git for Windows ã® bash.exe ãå©ç¨ãã¦
"""..."""
ã§è¤æ°ã³ãã³ããå®è¡ãã - plugin ãå©ç¨ããã« git ã³ãã³ããå®è¡ãã
æ¬é¡
cmd.exe ã§ï¼è¡ã³ãã³ããå®è¡ãã
ksbysample-nexus-repomng/ksbysample-webapp-demo ããã¸ã§ã¯ãã® build.gradle ã«ã¿ã¹ã¯ã追å ãã¦è©¦ãã¾ãã
Windows ãªã®ã§ cmd.exe ã ããã¨æããæåã«ä»¥ä¸ã®ã¿ã¹ã¯ãä½æãã¦ã¿ã¾ããã
task sampleTask(type: Exec) { commandLine "cmd.exe", "/C", "echo hello > hello.txt" }
Gradle projects View ã®å·¦ä¸ã«ãããRefresh all Gradle projectsããã¿ã³ãã¯ãªãã¯ã㦠build.gradle ãåæ ãã¾ãããotherãã®ä¸ã«ãsampleTaskãã表示ããã¾ãã
ãsampleTaskããå®è¡ãã㨠"BUILD SUCCESSFUL" ã表示ããã
ksbysample-webapp-demo ããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã§ãã C:\project-springboot\ksbysample-nexus-repomng\ksbysample-webapp-demo ã®ä¸ã« hello.txt ãåºåããã¦ãã¾ããã
ä½æããã hello.txt ã¯ä¸æ¦åé¤ãã¾ãã
cmd.exe ã§ã¯ """..."""
ã§ã³ãã³ããå®è¡ã§ããªãããã
次㫠build.gradle ã® sampleTask ã """..."""
ã®å½¢å¼ã«å¤æ´ãã¦ã¿ã¾ãã
task sampleTask(type: Exec) { commandLine "cmd.exe", "/C" """ echo hello > hello.txt """ }
ãsampleTaskããå®è¡ãã㨠"BUILD SUCCESSFUL" ã¯è¡¨ç¤ºãããã®ã§ãããhello.txt ã¯ä½æããã¾ããã§ããã
"""..."""
ã®è¨è¿°ã§è¤æ°ã³ãã³ããå®è¡ã§ããããã«ã¯ã§ããªãããã§ããæ¨æ¸¬ã§ãããcmd.exe ã«ã¯ãã¢ããã¥ã¡ã³ãã®æ©è½ããªãããã¨æããã¾ãã
.bat ãã¡ã¤ã«ãå®è¡ãã
1è¡ã³ãã³ãã¯å®è¡ã§ããã®ã§ã.bat ãã¡ã¤ã«ãä½æããã°è¤æ°ã³ãã³ããå®è¡ã§ããã®ã§ã¯ãªãããã¨æãã¾ããã試ãã¦ã¿ã¾ãã
ã¾ã ksbysample-webapp-demo ããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã«ä»¥ä¸ã®å 容㮠hello.bat ãä½æãã¾ãã
echo hello > hello.txt echo sample >> hello.txt
次㫠build.gradle ã® sampleTask ã hello.bat ãå®è¡ããããå¤æ´ãã¾ãã
task sampleTask(type: Exec) { commandLine "cmd.exe", "/C", "call hello.bat" }
ãsampleTaskããå®è¡ãã㨠hello.bat å ã®ã³ãã³ããï¼è¡ãã¤å®è¡ããã¦ããã¨æããããã°ãåºåããã¦ãæå¾ã« "BUILD SUCCESSFUL" ã表示ããã¾ããã
ksbysample-webapp-demo ããã¸ã§ã¯ãã®ã«ã¼ããã£ã¬ã¯ããªã«ã¯ hello.txt ãåºåããã¦ãããhello.bat ã«è¨è¿°ããå 容ãåºåããã¦ãã¾ããã
.bat ãã¡ã¤ã«ãä½æããã° cmd.exe ã§ãè¤æ°ã³ãã³ããå®è¡ã§ããããã«ã¯ãªãã¾ãããhello.bat, hello.txt ã¯åé¤ãã¾ãã
Git for Windows ã® bash.exe ãå©ç¨ã㦠"""..."""
ã§è¤æ°ã³ãã³ããå®è¡ãã
build.gradle ã®è¨è¿°ã ãã§è¤æ°ã³ãã³ããå®è¡ããæ¹æ³ããªãããèãã¦ã¿ã¾ããWindows ã§ã bash ãå©ç¨ã§ããã°ããã¨æãããã®ã§ãGit for Windows ã«å ¥ã£ã¦ãã bash.exe ãå©ç¨ããã°ããæ°ããã¾ãã試ãã¦ã¿ã¾ãã
ã¾ãç°å¢å¤æ° PATH ã« Git for Windows ã® bash.exe ããããã£ã¬ã¯ããªã追å ãã¾ããèªåã®ç°å¢ã§ã¯ C:\Git\usr\bin ã« bash.exe ãããã®ã§ãC:\Git\usr\bin ã PATH ã«è¿½å ãã¾ãã
ã³ãã³ãããã³ãããèµ·åã㦠bash ã³ãã³ããå®è¡ã§ãããã¨ã確èªãã¾ãã
build.gradle ã® sampleTask ã以ä¸ã®ããã«å¤æ´ãã¾ãã
task sampleTask(type: Exec) { commandLine "bash.exe", "-c", """ echo hello > hello.txt echo sample >> hello.txt """ }
ãsampleTaskããå®è¡ãã㨠"BUILD SUCCESSFUL" ã表示ããã¾ããã
hello.txt ãä½æããã¦ãã¾ããã
hello.txt ã¯åé¤ãã¾ãã
Git for Windows ã® bash.exe ãå©ç¨ããã° build.gradle ã®è¨è¿°ã ãã§è¤æ°ã³ãã³ããå®è¡ã§ãã¾ããã
plugin ãå©ç¨ããã« git ã³ãã³ããå®è¡ãã
ããã¾ã§ build.gradle ãã Git ã³ãã³ããå®è¡ããã«ã¯ org.ajoberstar:grgit
ãå©ç¨ãã¦ããã®ã§ãããä¸ã®æ¹æ³ãå®ç¾ã§ããã®ã§ããã° plugin ãå©ç¨ããã« git ã³ãã³ããå¼ã³åºããã¨æããã¾ãã試ãã¦ã¿ã¾ãã
build.gradle ã® sampleTask ã以ä¸ã®ããã«å¤æ´ãã¾ãã
task sampleTask(type: Exec) { commandLine "bash.exe", "-c", """ git checkout develop git branch feature/xxx-issue git checkout feature/xxx-issue mkdir src/main/resources/META-INF touch src/main/resources/META-INF/.gitkeep git add -A git commit -m 'META-INF ãã£ã¬ã¯ããªãä½æãã¾ãã' """ }
â»"""..."""
ã®ä¸ã§ git commit çã§ã¡ãã»ã¼ã¸æååãæå®ããå ´åãã·ã³ã°ã«ã¯ã©ã¼ãã¼ã·ã§ã³ã§å²ã¿ã¾ãã
ãsampleTaskããå®è¡ããåã® Git ã®ãªãã¸ããªã¯ä»¥ä¸ã®ç¶æ ã§ãã
ãsampleTaskããå®è¡ãã㨠"BUILD SUCCESSFUL" ã表示ããã¾ããã
SourceTree 㧠Git ã®ãªãã¸ããªãè¦ãã¨ãfeature/xxx-issue ãã©ã³ããä½æããã¦ãã¡ã¤ã«ã commit ããã¦ãã¾ããã
ä½æãã feature/xxx-issue ãã©ã³ãã¯åé¤ãã¾ãã
çµè«ã¨ãã¦ã¯ Windows ã§ãåé¡ãªã使ç¨ã§ãããã§ããã³ãã³ããç´æ¥å®è¡ã§ããããã«ãªãã¨ããããããããã¨ãå¢ãããã§ããã