Gradle Watch Plugin ãä½ã£ã¦ã¿ã
ä»å¹´ãæ®ããããã¨ãªãã¾ããããä»å¹´æåã¨ãªãã¨ã³ããªã¼ã¯ ãG* Advent Calendar 2013ãã®12æ¥ç®ã§ãã
çãã Gradle 使ã£ã¦ã¾ããï¼
èªåã¯ã¨è¨ãã¨â¦
æ®å¿µãªãããä»å¹´ãæ¥åã¸ã®æ¬æ ¼å°å
¥ã¯ã§ããªãã£ãã®ã§ã
æ¥å¹´ããã¯å°å
¥ãããã¨ããææ°è¾¼ã¿ãè¾¼ãã¦ãGradle ãã©ã°ã¤ã³ãä½ã£ã¦ã¿ã¾ããã
ä»åä½æãã Gradle ãã©ã°ã¤ã³ã§ãããç°¡åã«è¨ã£ã¦ãã¾ã㨠grunt-contrib-watch ã®ãããªãã©ã°ã¤ã³ã§ããã¨ããããã¯ãªã§ãã
grunt-contrib-watch 㯠ãã¡ã¤ã«ãå¤æ´ãããã¿ã¤ãã³ã°ã§ä»»æã®ã¿ã¹ã¯ãå®è¡ãã Grunt ï¼JavaScript 製ãã«ããã¼ã«ï¼ç¨ã®ãã©ã°ã¤ã³ã§ãã
æè¿ãG* ã¤ãªããï¼ã§ Grunt ã«ãå°ãæãåºãå§ãã¦ããã®ã§ãããï¼ã¾ã ãGradle ããæ¬æ ¼å°å
¥ã§ãã¦ããªãã®ã«ï¼
ãã®ä¸ã§ã grunt-contrib-watch ãã©ã°ã¤ã³ãã¨ã£ã¦ã便å©ã
æ©éãGradle ã§ãåããã©ã°ã¤ã³ããªããæ¢ãã¦ã¿ãã®ã§ãããæ®å¿µãªããè¦ã¤ãããã¨ãã§ãã¾ããã§ããã
Java ããã°ã©ã㯠IDE åæã ãããããã£ããã©ã°ã¤ã³ã®éè¦ã¯ãªãã®ããªã¨ã
æãã¾ãããããããªãã¨ã¯æ°ã«ããããªããªãä½ã£ã¡ããã°ããããããã¨è¨ããã¨ã§ãããã£ã¨ä½ã£ã¦ã¿ã¾ããã
ãã©ã°ã¤ã³ã®ä½¿ãæ¹ã®åã«ãã¾ãã¯ããããã¨è¨ã訳â¦
æéããªãã¦ããªãé©å½ãªä½ãã«ãªã£ã¦ãã¾ããï¼ä»å¾ãã¡ããã¨ãã¦ããäºå®ï¼
ã¾ããJava7 ã® NIO.2 ã使ã£ã¦ããã®ã§ Java7 以ä¸ã§ãªãã¨åãã¾ããã
ãã¡ãããè¯ãåã®çãã㯠Java6 ã¨ã使ã£ã¦ãªãã§ãããã
ããããã¦ãè¯ãåã¯ãããã§ã« Java8 使ã£ã¦ãã®ããªï¼
ãã¨ãMac OS X 使ã£ã¦ãã¿ãªãããï¼ç§ããã®ä¸äººã§ããï¼æ®å¿µãªãããWatchService
ã®ãã¡ã¤ã«æ´æ°ã®éç¥ãé
ãã®ã§ãåä½ãã¢ãµãã¨ãã¦ãã¦ã¡ãã£ã¨ã¤ã©ã£ã¨ãã¾ãã
ã¨è¨ããã¨ã§ãGradle Watch Plugin ã®ä½¿ãæ¹ã§ãã ã¨ã£ã¦ãç°¡åã§ãã
ã¾ãããã®ãã©ã°ã¤ã³ãå©ç¨ãããããã¸ã§ã¯ãã® build.gradle ã«
buildscript { repositories { maven { url 'http://bluepapa32.github.io/maven/' } } dependencies { classpath 'com.bluepapa32.gradle.plugins:gradle-watch-plugin:0.1.0' } } apply plugin: 'watch'ã追å ãã¦ãGradle Watch Plugin ãé©ç¨ãã¾ãããã¨ã¯
watch { java { files files('src/main/java') tasks 'compileJava' } resources { files fileTree(dir: 'src/main/resources', // FileTree ã§æå® include: '**/*.properties') tasks 'processResources' } hoge { files files('foo/bar', 'foo/boo/hoo.txt') // è¤æ°ã®ãã£ã¬ã¯ããªãç£è¦ tasks 'hogehoge', 'hugohugo' // è¤æ°ã®ã¿ã¹ã¯ãå®è¡ } }㨠watch ãããã¯å ã« ä»»æã®ååãä»ãããããã¯ï¼watch ãããã¯å ã§ã¦ãã¼ã¯ã§ããã°ä½ã§ãå¯ï¼ãå®ç¾©ãã¦ããã®ãããã¯å ã«
åå | 説æ | å |
---|---|---|
files | ç£è¦ããããã£ã¬ã¯ã㪠ã¾ã㯠ãã¡ã¤ã« | FileCollection |
tasks | ãã¡ã¤ã«ãå¤æ´ãããéã«å®è¡ããã¿ã¹ã¯ | String[] |
gradle watchã¨å®è¡ããã ãã§ã常é§ããã»ã¹ããã¡ã¤ã«ãç£è¦ãã¦ãå¤æ´ããã£ãã¿ã¤ãã³ã°ã§æå®ããã¿ã¹ã¯ãå®è¡ãã¦ãããããã«ãªãã¾ãã
ä¸ã®ä¾ã®å ´åãsrc/main/java é ä¸ã®ãã¡ã¤ã«ãæ´æ°ããã㨠compileJava ã¿ã¹ã¯ãå®è¡ãããsrc/main/resources é ä¸ã® ããããã£ãã¡ã¤ã«ãæ´æ°ããã㨠processResources ã¿ã¹ã¯ãå®è¡ããã¾ãã
ãããèå³ãããã°ããã²ä½¿ã£ã¦ã¿ã¦ãã ããã
ã¡ãªã¿ã«ã½ã¼ã¹ã¯ GitHub ã«å
¬éãã¦ãã¾ãã
ãã£ãããªã®ã§ãä»åãã©ã°ã¤ã³ãä½æããã«ããããããã¤ãæ°ããæ©è½ã使ã£ã¦ã¿ãã®ã§ç°¡åã«ç´¹ä»ãããã¨æãã¾ãã
ãã®åã«ãGradle ãã©ã°ã¤ã³ã®åºæ¬çãªä½ãæ¹ã§ããã
ä»å使ã£ã¦ã¿ãæ°ããæ©è½ï¼ããæ°æ©è½ã§ã¯ãªãããããã¾ããã...ï¼ã¯
ã®2ã¤ã§ããextension ãªãã¸ã§ã¯ã
ã¾ããextension ãªãã¸ã§ã¯ãã§ããããã£ããè¨ãã¨ç¬èªã§DSLãæ¡å¼µã§ããä»çµã¿ã§ãã
ä¾ãã°ãä¸è¨ã® watch ãããã¯ã¯ ãã®æ©è½ã使ã£ã¦è¿½å ãããã®ã§ãã
æ´ã« ä»åã®å ´åãwatch ãããã¯å é¨ã§èªç±ã«ãããã¯ã追å ã§ããã®ã§ããããã 㯠NamedDomainObjectContainer ã¨ããã¯ã©ã¹ã使ã£ã¦å®ç¾ãã¦ãã¾ãã
以ä¸ããããå®ç¾ãã¦ããã³ã¼ãã§ãããã£ãããã ãã§ããã¨ã£ã¦ãç°¡åã§ãããclass WatchPlugin implements Plugin<Project> { void apply(Project project) { project.extensions.watch = project.container(WatchTarget) { name -> project.extensions.create(name, WatchTarget, name) } ... } }
NamedDomainObjectContainer 㯠Project ã¯ã©ã¹ã® container ã¡ã½ããã§çæãããã¨ãã§ãã¾ãã
ä»åã®å ´å watch ã NamedDomainObjectContainer ã«å¯¾å¿ãã¦ãã¾ãã
container ã¡ã½ããã®å¼æ°ã«æå®ãã¦ããåã NamedDomainObjectContainerå
ã®è¦ç´ ã®åã
ãã®å¾ãã®ã¯ãã¼ã¸ã£ãå®éã« NamedDomainObjectContainer å
ã®è¦ç´ ãçæããé¨åã«ãªãã¾ãã
ä»åã®å ´åãwatch ãããã¯å
ã® java, resources, hoge ãé çªã« name å¤æ°ã§åãåãã
ã¯ãã¼ã¸ã£å
㧠WatchTarget ãçæãã¦ãã¾ãã
ãã¡ããçæããã WatchTarget ã«ã¯ files ã tasks ã§å®ç¾©ããå¤ãåæã«è¨å®ããã¾ãã
ãã£ãããã ãã§èªç±ã«DSLãæ¡å¼µã§ãããªãã¦ã便å©ãªä¸ã®ä¸ã«ãªãã¾ãããã
Gradle tooling API
ããä¸ã¤å©ç¨ããæ©è½ã Gradle tooling API ã§ãã
ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(new File("someProjectFolder")) .connect(); try { connection.newBuild().forTasks("taskA", "taskB").run(); } finally { connection.close(); }ã®ããã«æ¸ãã ãã§ãGradle以å¤ã®ï¼ä¾ãã° IDE ã¿ãããªï¼ã¢ããªã±ã¼ã·ã§ã³ããç´æ¥ Gradle ã®ã¿ã¹ã¯ãå®è¡ã§ããããã«ãªãã¨ãã便å©ãªæ©è½ã§ãã
ä»å㯠Gradle ãã©ã°ã¤ã³ããå®è¡ãã¦ããã®ã§ã¢ã¬ã§ããâ¦
ã¨è¨ããã¨ã§â¦
ä»å¹´ã®å¬ä¼ã¿ã¯ ã¿ãªããã Gradle ãã©ã°ã¤ã³ãä½ã£ã¦ã¿ã¦ã¯ãããã§ããããï¼
ææ¥ã¯ ãã® ããããã ãåã³ç»å ´ã§ãã
ããã§ã¯ å°ãæ©ãã§ãã è¯ãã¯ãªã¹ãã¹ãï¼ï¼