import Ġcom . mo ow ork . gradle . node . npm . N pm Task Ċ import Ġjava . nio . file . Paths Ċ Ċ plugins Ġ{ ĊĠ Ġid (" com . github . node - gradle . node ") Ġversion Ġ" 2 . 2 . 3 " Ċ } Ċ Ċ repositories Ġ{ ĊĠ Ġgradle Plugin Portal () Ċ } Ċ Ċ val Ġdefault Ġby Ġconfigurations . creating Ċ Ċ dependencies Ġ{ ĊĠ Ġdefault ( project (": web - view : viewer ", Ġconfigurations . viewer Application Bundle . name )) Ċ } Ċ Ċ tasks Ġ{ ĊĠ Ġnode Ġ{ ĊĠĠĠ Ġdownload Ġ= Ġtrue ĊĠĠĠ Ġversion Ġ= Ġproject . properties [" node Version "]. toString () ĊĠĠĠ Ġnode Modules Dir Ġ= Ġproject Dir ĊĠ Ġ} Ċ } Ċ Ċ val Ġcopy Application Bundle Ġby Ġtasks . register ing ( Copy :: class ) Ġ{ ĊĠ Ġfrom ( default ) ĊĠ Ġinto ( File ( project Dir , Ġ" application ")) Ċ } Ċ Ċ val Ġensure Node Modules Installed Ġby Ġtasks . register ing Ġ{ ĊĠ Ġdepends On (" node Setup ") ĊĠ Ġdepends On (" npm Setup ") ĊĠ Ġinputs . file ( File ( project Dir , Ġ" package . json ")). with Path Sensitivity ( Path Sensitivity . REL ATIVE ) ĊĠ Ġinputs . file ( File ( project Dir , Ġ" package - lock . json ")). with Path Sensitivity ( Path Sensitivity . REL ATIVE ) ĊĠ Ġif Ġ(! file ( Paths . get ( project Dir . toString (), Ġ" node _ modules ")). exists ()) Ġ{ ĊĠĠĠ Ġdepends On (" npm _ ci ") ĊĠ Ġ} Ċ } Ċ Ċ val Ġcollect Outer Sources Ġby Ġtasks . register ing Ġ{ ĊĠ Ġval Ġfiles Ġ= ĠlistOf ( ĊĠĠĠ Ġ" package . json ", ĊĠĠĠ Ġ" package - lock . json ", ĊĠĠĠ Ġ" post install . js ", ĊĠĠĠ Ġ" webpack . config . js ", ĊĠĠĠ Ġ" webpack . config . js ", ĊĠĠĠ Ġ" missing - props . properties ", ĊĠĠĠ Ġ" index . html " ĊĠ Ġ) ĊĠ Ġfor Ġ( file Ġin Ġfiles ) Ġ{ ĊĠĠĠ Ġinputs . file ( File ( project Dir , Ġfile )). with Path Sensitivity ( Path Sensitivity . REL ATIVE ) ĊĠ Ġ} ĊĠ Ġinputs . dir (" src "). with Path Sensitivity ( Path Sensitivity . REL ATIVE ) ĊĠ Ġoutputs . files ( inputs . files ) Ċ } Ċ Ċ val Ġbuild WebView Ġby Ġtasks . register ing ( N pm Task :: class ) Ġ{ ĊĠ Ġdepends On ( ensure Node Modules Installed ) ĊĠ Ġinputs . files ( ĊĠĠĠ Ġcollect Outer Sources . map Ġ{ Ġit . outputs Ġ}, ĊĠĠĠ Ġcopy Application Bundle . map Ġ{ Ġit . outputs Ġ} ĊĠ Ġ) ĊĠ Ġset Args ( listOf (" run ", Ġ" build ")) ĊĠ Ġoutputs . dir ( File ( project Dir , Ġ" build ")) ĊĠ Ġ// Ġoutputs . cache If Ġ{ Ġtrue Ġ} Ċ } Ċ Ċ artifacts Ġ{ ĊĠ Ġadd ( default . name , Ġbuild WebView ) Ċ } Ċ