import Ġcom . v ann ik tech . maven . publish . Javadoc Jar . Javadoc Ċ import Ġcom . v ann ik tech . maven . publish . Kotlin Jvm Ċ import Ġcom . v ann ik tech . maven . publish . Maven Publish Base Extension Ċ import Ġorg . gradle . jvm . tasks . Jar Ċ import Ġorg . jetbrains . kotlin . gradle . plugin . Kotlin Compilation Ċ import Ġorg . jetbrains . kotlin . gradle . tasks . Kotlin Compile Ċ Ċ plugins Ġ{ ĊĠ Ġkotlin (" jvm ") ĊĠ Ġid (" com . v ann ik tech . maven . publish . base ") ĊĠ Ġid (" org . jetbrains . dok ka ") Ċ } Ċ Ċ val Ġmain Source Set Ġby Ġsource Sets . named (" main ") Ċ val Ġjava 1 6 : ĠSource Set Ġby Ġsource Sets . creating Ġ{ ĊĠ Ġjava Ġ{ ĊĠĠĠ Ġsrc Dir (" src / main / java 1 6 ") ĊĠ Ġ} Ċ } Ċ Ċ // ĠWe Ġuse ĠJDK Ġ 1 7 Ġfor Ġlatest Ġbut Ġtarget Ġ 1 6 Ġfor Ġmaximum Ġcompatibility Ċ val Ġservice Ġ= Ġproject . extensions . getBy Type < Java Tool chain Service >() Ċ val Ġcustom Launcher Ġ= Ġservice . launcher For Ġ{ ĊĠ Ġlanguage Version . set ( Java Language Version . of ( 1 7 )) Ċ } Ċ Ċ tasks . named < Kotlin Compile >(" compile Java 1 6 Kotlin ") Ġ{ ĊĠ Ġkotlin Java Tool chain . toolchain . use ( custom Launcher ) ĊĠ Ġkotlin Options . jvm Target Ġ= Ġ" 1 6 " Ċ } Ċ Ċ // ĠGrant Ġour Ġjava 1 6 Ġsources Ġaccess Ġto Ġinternal ĠAPIs Ġin Ġthe Ġmain Ġsource Ġset Ċ kotlin . target . comp il ations . run Ġ{ ĊĠ Ġget ByName (" java 1 6 ") ĊĠĠĠ Ġ. associate With ( get ByName ( Kotlin Compilation . MAIN _ COMPI L ATION _ NAME )) Ċ } Ċ Ċ // ĠPackage Ġour Ġactual ĠRecord Json Adapter Ġfrom Ġjava 1 6 Ġsources Ġin Ġand Ġden ote Ġit Ġas Ġan ĠMR JAR Ċ tasks . named < Jar >(" jar ") Ġ{ ĊĠ Ġfrom ( java 1 6 . output ) Ġ{ ĊĠĠĠ Ġinto (" META - INF / versions / 1 6 ") ĊĠ Ġ} ĊĠ Ġmanifest Ġ{ ĊĠĠĠ Ġattributes (" Multi - Release " Ġto Ġ" true ") ĊĠ Ġ} Ċ } Ċ Ċ configurations Ġ{ ĊĠ Ġ" java 1 6 Implementation " Ġ{ ĊĠĠĠ Ġextends From ( api . get ()) ĊĠĠĠ Ġextends From ( implementation . get ()) ĊĠ Ġ} Ċ } Ċ Ċ tasks . with Type < Test >(). configure Each Ġ{ ĊĠ Ġ// ĠExt ends Platform Class With Protected Field Ġtests Ġa Ġcase Ġwhere Ġwe Ġset Ġa Ġprotected ĠByteArrayOutputStream . buf Ġfield ĊĠ Ġj vm Args ("-- add - opens = java . base / java . io = ALL - UN NAMED ") Ċ } Ċ Ċ tasks . with Type < Kotlin Compile >() ĊĠ Ġ. configure Each Ġ{ ĊĠĠĠ Ġkotlin Options Ġ{ ĊĠĠĠĠĠ Ġval Ġto Add Ġ= Ġmutable ListOf ( ĊĠĠĠĠĠĠĠ Ġ"- X opt - in = kotlin . Requires Opt In ", ĊĠĠĠĠĠĠĠ Ġ"- X opt - in = kotlin . contracts . Experimental Contracts ", ĊĠĠĠĠĠĠĠ Ġ"- X jvm - default = enable " ĊĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġif Ġ( name . contains (" test ", Ġtrue )) Ġ{ ĊĠĠĠĠĠĠĠ Ġto Add Ġ+= Ġ"- X opt - in = kotlin . Experimental Std lib Api " ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ@ Suppress (" Sus pic ious Collection Re assignment ") Ġ// ĠIt 's Ġnot Ġsus pic ious ĊĠĠĠĠĠ Ġfree Compiler Args Ġ+= Ġto Add ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ Ċ dependencies Ġ{ ĊĠ Ġ// ĠSo Ġthe Ġj 1 6 Ġsource Ġset Ġcan Ġ" see " Ġmain ĠM oshi Ġsources ĊĠ Ġ" java 1 6 Implementation "( main Source Set . output ) ĊĠ Ġcompile Only ( libs . js r 3 0 5 ) ĊĠ Ġapi ( libs . ok io ) ĊĊĠ Ġtest Compile Only ( libs . js r 3 0 5 ) ĊĠ Ġtest Implementation ( libs . junit ) ĊĠ Ġtest Implementation ( libs . truth ) Ċ } Ċ Ċ tasks . with Type < Jar >(). configure Each Ġ{ ĊĠ Ġmanifest Ġ{ ĊĠĠĠ Ġattributes (" Automatic - Module - Name " Ġto Ġ" com . squareup . mos hi ") ĊĠ Ġ} Ċ } Ċ Ċ configure < Maven Publish Base Extension > Ġ{ ĊĠ Ġconfigure ( Kotlin Jvm ( javadoc Jar Ġ= ĠJ avadoc ())) Ċ } Ċ