Search code examples
kotlinkotlin-script

Why can't I use @file:Repository and @file:DependsOn in .kts kotlin script?


I see examples online where a .kts file begins with things like

@file:Repository(<some-maven-repo-url>)
@file:DependsOn(<some-dependency-identifier)

But I can't get it to work for my helloworld.kts file.

helloworld.kts:1:7: error: unresolved reference: Repository
@file:Repository(...)
      ^
helloworld.kts:2:7: error: unresolved reference: DependsOn
@file:DependsOn(...)
      ^

What am I doing wrong?


Solution

  • In order to make it work, the file name must end in .main.kts. For the OP example it would need to be helloworld.main.kts.