import Ġjava . io . FileInputStream Ċ import Ġjava . util .* Ċ Ċ // ĠAuto Ġgenerate ĠVERSION _ CODE Ġ& ĠVERSION _ NAME Ċ val Ġversion Props File Ġ= Ġfile ("${ project Dir }/ version . properties ") Ċ var Ġcode Ġ= Ġ 1 Ċ val Ġversion Major Ġ= Ġ 3 Ċ val Ġversion Minor Ġ= Ġ 0 Ċ val Ġversion Patch Ġ= Ġ 0 Ċ var Ġversion Ġ= Ġ"" Ċ Ċ val Ġdev Release Task Ġ= Ġ" assemble dev Release " Ċ val Ġprod Release Task Ġ= Ġ" assemble prod Release " Ċ val Ġprod Release Task Studio Ġ= Ġ" assemble Prod Release " Ċ val Ġprod Release Task Bundle Ġ= Ġ" bundle Prod Release " Ċ val Ġprod Release Task Bundle 2 Ġ= Ġ" bundle prod Release " Ċ val Ġdev Release Task Studio Ġ= Ġ" assemble Dev Release " Ċ val Ġgeneric Release Ġ= Ġ" assemble Release " Ċ Ċ if Ġ( version Props File . can Read ()) Ġ{ ĊĠĠĠ Ġval Ġversion Props Ġ= ĠProperties () ĊĠĠĠ Ġversion Props . load ( FileInputStream ( version Props File )) ĊĠĠĠ Ġval Ġrun Tasks Ġ= Ġgradle . start Parameter . task Names ĊĠĠĠ Ġvar Ġis Release Ġ= Ġfalse ĊĠĠĠ Ġfor Ġ( item Ġin Ġrun Tasks ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( item . contains ( dev Release Task ) Ġ|| Ġitem . contains ( prod Release Task ) Ġ|| Ġitem . contains ( generic Release ) Ġ|| ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġitem . contains ( dev Release Task Studio ) Ġ|| Ġitem . contains ( prod Release Task Studio ) Ġ|| ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġitem . contains ( prod Release Task Bundle ) Ġ|| Ġitem . contains ( prod Release Task Bundle 2 )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Release Ġ= Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbreak ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġcode Ġ= Ġversion Props . getProperty (" VERSION _ CODE "). toInt () ĊĠĠĠ Ġvar Ġversion Build Ġ= Ġversion Props . getProperty (" VERSION _ BUILD "). toInt () ĊĠĠĠ Ġversion Ġ= Ġversion Props . getProperty (" VERSION _ NAME ") ĊĠĠĠ Ġif Ġ( is Release ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcode ++ ĊĠĠĠĠĠĠĠ Ġversion Build ++ ĊĠĠĠĠĠĠĠ Ġversion Props . setProperty (" VERSION _ CODE ", Ġcode . toString ()) ĊĠĠĠĠĠĠĠ Ġversion Props . setProperty (" VERSION _ BUILD ", Ġversion Build . toString ()) ĊĠĠĠĠĠĠĠ Ġversion Ġ= ĠStringBuilder (). append ( version Major ). append (". "). append ( version Minor ). append (". "). append ( version Patch ). append (". "). append ( version Build ). toString () ĊĠĠĠĠĠĠĠ Ġversion Props . setProperty (" VERSION _ NAME ", Ġversion ) ĊĠĠĠĠĠĠĠ Ġversion Props . store ( version Props File . writer (), Ġnull ) ĊĠĠĠ Ġ} Ċ } Ġelse Ġ{ ĊĠĠĠ Ġthrow ĠGradle Exception (" Could Ġnot Ġread Ġversion . properties !") Ċ } Ċ Ċ extra . apply Ġ{ ĊĠĠĠ Ġset (" version Code ", Ġcode ) ĊĠĠĠ Ġset (" version Name ", Ġversion ) Ċ } Ċ