@@ -117,7 +117,7 @@ fun main(args: Array<String>) {
117117    //   Optionally enter interactive mode
118118    if  (docopt.getBoolean(" interactive"  )) {
119119        System .err.println (" Creating REPL from ${scriptFile} "  )
120-         System .err.println (" kotlinc ${kotlinOpts}  -classpath '${classpath} '"  )
120+         //          System.err.println("kotlinc ${kotlinOpts} -classpath '${classpath}'")
121121
122122        println (" kotlinc ${kotlinOpts}  -classpath ${classpath} "  )
123123        exitProcess(0 )
@@ -221,13 +221,31 @@ fun main(args: Array<String>) {
221221}
222222
223223fun  collectDependencies (scriptText :  List <String >): List <String > {
224-     return  scriptText
224+     val  deps  =  scriptText
225225            .filter { it.startsWith(" //DEPS "  ) }
226226            .flatMap { it.split(" [ ;,]+"  .toRegex()).drop(1 ) }
227227            .map(String ::trim)
228+ 
229+     val  annotatonPrefix =  " @file:DependsOn(" 
230+     var  annotDeps =  scriptText
231+             .filter { it.startsWith(annotatonPrefix) }
232+             .map { it.replaceFirst(annotatonPrefix, " "  ).split(" )"  )[0 ] }
233+             .flatMap { it.split(" ,"  ) }
234+             .map { it.trim('  '  , ' "'  ) }
235+ 
236+     //  if annotations are used add dependency
237+     if  (scriptText.any { containsKscriptAnnotation(it) }) {
238+         annotDeps + =  " com.github.holgerbrandl:kscript-annotations:1.0" 
239+     }
240+ 
241+     return  (deps +  annotDeps).distinct()
228242}
229243
230244
245+ fun  containsKscriptAnnotation (line :  String ) = 
246+         listOf (" DependsOn"  , " KotlinOpts"  , " Include"  , " EntryPoint"  ).any { line.startsWith(" @file:${it} ("  ) }
247+ 
248+ 
231249fun  collectRuntimeOptions (scriptText :  List <String >): String  {
232250    val  koptsPrefix =  " //KOTLIN_OPTS " 
233251
@@ -305,7 +323,7 @@ fun prepareScript(scriptResource: String, enableSupportApi: Boolean): File {
305323            var  script =  scriptResource.trim()
306324
307325            // auto-prefix one-liners with kscript-support api
308- //             if (numLines(script) == 1 && (script.startsWith("lines") || script.startsWith("stdin"))) {
326+              //             if (numLines(script) == 1 && (script.startsWith("lines") || script.startsWith("stdin"))) {
309327            if  (enableSupportApi) {
310328                val  prefix =  """ 
311329                //DEPS com.github.holgerbrandl:kscript:1.2.2 
0 commit comments