/* Ċ Ġ* ĠCopyright Ġ 2 0 1 8 Ġthe Ġoriginal Ġauthor Ġor Ġauthors . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . gradle . gradle build . packaging Ċ Ċ import Ġaccessors . base Ċ import Ġorg . gradle . api . Plugin Ċ import Ġorg . gradle . api . Project Ċ import Ġorg . gradle . api . artifacts . Configuration Ċ import Ġorg . gradle . api . attributes . Usage Ċ import Ġorg . gradle . api . model . ObjectFactory Ċ import Ġorg . gradle . api . tasks . Copy Ċ import Ġorg . gradle . api . tasks . Task Provider Ċ import Ġorg . gradle . api . tasks . bund ling . Jar Ċ import Ġorg . gradle . gradle build . packaging . Attributes . artifact Type Ċ import Ġorg . gradle . gradle build . packaging . Attributes . min ified Ċ import Ġorg . gradle . kotlin . dsl .* Ċ import Ġjava . io . File ĊĊ Ċ private Ċ const Ġval Ġre located Classes And Analysis Type Ġ= Ġ" re located Classes And Analysis " ĊĊ Ċ private Ċ const Ġval Ġre located Classes Type Ġ= Ġ" re located Classes " ĊĊ Ċ private Ċ const Ġval Ġentry Points Type Ġ= Ġ" entry Points " ĊĊ Ċ private Ċ const Ġval Ġclass Trees Type Ġ= Ġ" class Trees " ĊĊ Ċ private Ċ const Ġval Ġmanifest sType Ġ= Ġ" manifest s " ĊĊ Ċ /** Ċ Ġ* ĠCreates Ġa Ġsh aded Ġjar Ġof Ġthe Ġpublication Ġof Ġthe Ġcurrent Ġproject . Ċ Ġ* Ċ Ġ* ĠThe Ġsh aded Ġjar Ġis Ġadded Ġas Ġan Ġartifact Ġto Ġthe Ġ{@ code Ġpublish Runtime } Ġconfiguration . Ċ Ġ*/ Ċ open Ġclass ĠSh aded Jar Plugin Ġ: ĠPlugin < Project > Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġapply ( project : ĠProject ): ĠUnit Ġ= Ġproject . run Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsh aded Jar Extension Ġ= Ġcreate Sh aded Jar Extension ( create Configuration To Shade ()) ĊĊĠĠĠĠĠĠĠ Ġregister Transforms ( sh aded Jar Extension ) ĊĊĠĠĠĠĠĠĠ Ġval Ġsh aded Jar Task Ġ= Ġadd Sh aded Jar Task ( sh aded Jar Extension ) ĊĊĠĠĠĠĠĠĠ Ġadd Install Sh aded Jar Task ( sh aded Jar Task ) ĊĊĠĠĠĠĠĠĠ Ġplugins . with Id (" gradle build . publish - public - libraries ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Sh aded Jar Artifact ( sh aded Jar Task ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . create Sh aded Jar Extension ( configuration To Shade : ĠConfiguration ) Ġ= ĊĠĠĠĠĠĠĠ Ġextensions . create < Sh aded Jar Extension >(" sh aded Jar ", Ġobjects , Ġconfiguration To Shade ) ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . register Transforms ( sh aded Jar Extension : ĠSh aded Jar Extension ) Ġ{ ĊĠĠĠĠĠĠĠ Ġafter Evaluate Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdependencies Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġregister Transform ( Shade Classes :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfrom ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. attribute ( artifact Type , Ġ" jar ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. attribute ( min ified , Ġtrue ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġto . attribute ( artifact Type , Ġre located Classes And Analysis Type ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġparameters Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġshadow Package Ġ= Ġ" org . gradle . internal . impl dep " ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġkeep Packages Ġ= Ġsh aded Jar Extension . keep Packages . get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġun sh aded Packages Ġ= Ġsh aded Jar Extension . un sh aded Packages . get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġignored Packages Ġ= Ġsh aded Jar Extension . ignored Packages . get () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġdependencies Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġregister Transform ( Find Re located Classes :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfrom . attribute ( artifact Type , Ġre located Classes And Analysis Type ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġto . attribute ( artifact Type , Ġre located Classes Type ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġregister Transform ( Find Entry Points :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfrom . attribute ( artifact Type , Ġre located Classes And Analysis Type ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġto . attribute ( artifact Type , Ġentry Points Type ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġregister Transform ( Find Class Trees :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfrom . attribute ( artifact Type , Ġre located Classes And Analysis Type ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġto . attribute ( artifact Type , Ġclass Trees Type ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġregister Transform ( Find Manifest s :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfrom . attribute ( artifact Type , Ġre located Classes And Analysis Type ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġto . attribute ( artifact Type , Ġmanifest sType ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . create Configuration To Shade (): ĠConfiguration Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Name Ġ= Ġ" j ars To Shade " ĊĠĠĠĠĠĠĠ Ġafter Evaluate Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdependencies . add ( configuration Name , Ġproject ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġconfigurations . create ( configuration Name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġattributes . attribute ( Usage . USAGE _ ATTRIBUTE , Ġobjects . named ( Usage . JAVA _ RUNTIME )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Can Be Resolved Ġ= Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Can Be Cons umed Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . add Sh aded Jar Task ( sh aded Jar Extension : ĠSh aded Jar Extension ): ĠTask Provider < Sh aded Jar > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġconfiguration To Shade Ġ= Ġsh aded Jar Extension . sh aded Configuration ĊĠĠĠĠĠĠĠ Ġval Ġjar : ĠTask Provider < Jar > Ġ= Ġtasks . with Type ( Jar :: class ). named (" jar ") ĊĊĠĠĠĠĠĠĠ Ġreturn Ġtasks . register ("${ project . name } Sh aded Jar ", ĠSh aded Jar :: class ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdepends On ( jar ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġjar File . set ( layout . build Directory . file (" sh aded - jar /${ base . archives Base Name }- sh aded -${ root Project . extra [" base Version "] }. jar ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġclass Trees Configuration . from ( configuration To Shade . artifact View ForType ( class Trees Type )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġentry Points Configuration . from ( configuration To Shade . artifact View ForType ( entry Points Type )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġre located Classes Configuration . from ( configuration To Shade . artifact View ForType ( re located Classes Type )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmanifest s . from ( configuration To Shade . artifact View ForType ( manifest sType )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbuild Receipt File . set ( sh aded Jar Extension . build Receipt File ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . add Install Sh aded Jar Task ( sh aded Jar Task : ĠTask Provider < Sh aded Jar >) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġinstall Path Property Ġ= Ġ"${ project . name } Sh aded Jar Install Path " ĊĠĠĠĠĠĠĠ Ġfun Ġtarget File (): ĠFile Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġfile Ġ= Ġfind Property ( install Path Property )?. let Ġ{ ĠFile ( find Property ( install Path Property ) Ġas ĠString ) Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( true Ġ== Ġfile ?. is Absolute ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġfile ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalArgumentException (" Property Ġ$ install Path Property Ġis Ġrequired Ġand Ġmust Ġbe Ġabsolute !") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtasks . register < Copy >(" install ${ project . name . capitalize ()} Sh aded Jar ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdepends On ( sh aded Jar Task ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfrom ( sh aded Jar Task . map Ġ{ Ġit . jar File Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinto ( deferred Ġ{ Ġtarget File (). parent File Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrename Ġ{ Ġtarget File (). name Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠProject . add Sh aded Jar Artifact ( sh aded Jar Task : ĠTask Provider < Sh aded Jar >) Ġ{ ĊĠĠĠĠĠĠĠ Ġartifacts . add (" publish Runtime ", Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" file " Ġto Ġsh aded Jar Task . get (). jar File . get (). as File , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" name " Ġto Ġbase . archives Base Name , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" type " Ġto Ġ" jar ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" built By " Ġto Ġsh aded Jar Task ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate ĊĠĠĠ Ġfun ĠConfiguration . artifact View ForType ( artifact TypeName : ĠString ) Ġ= Ġincoming . artifact View Ġ{ ĊĠĠĠĠĠĠĠ Ġattributes . attribute ( artifact Type , Ġartifact TypeName ) ĊĠĠĠ Ġ}. files Ċ } ĊĊ Ċ open Ġclass ĠSh aded Jar Extension ( objects : ĠObject Factory , Ġval Ġsh aded Configuration : ĠConfiguration ) Ġ{ ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠThe Ġbuild Ġreceipt Ġproperties Ġfile . ĊĠĠĠĠ Ġ* ĊĠĠĠĠ Ġ* ĠThe Ġfile Ġwill Ġbe Ġincluded Ġin Ġthe Ġsh aded Ġjar Ġunder Ġ{@ code Ġ/ org / gradle / build - receipt . properties }. ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġval Ġbuild Receipt File Ġ= Ġobjects . file Property () ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠRet ain Ġonly Ġthose Ġclasses Ġin Ġthe Ġkeep Ġpackage Ġh ierarch ies , Ġplus Ġany Ġclasses Ġthat Ġare Ġreachable Ġfrom Ġthese Ġclasses . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġval Ġkeep Packages Ġ= Ġobjects . setProperty ( String :: class ) ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠDo Ġnot Ġrename Ġclasses Ġin Ġthe Ġun sh aded Ġpackage Ġh ierarch ies . ĠAlways Ġincludes Ġ' java '. ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġval Ġun sh aded Packages Ġ= Ġobjects . setProperty ( String :: class ) ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠDo Ġnot Ġretain Ġclasses Ġin Ġthe Ġignore Ġpackages Ġh ierarch ies , Ġunless Ġreachable Ġfrom Ġsome Ġother Ġretained Ġclass . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġval Ġignored Packages Ġ= Ġobjects . setProperty ( String :: class ) Ċ } Ċ