can u compile it?
# announcements
q
can u compile it?
h
No
Error:(2, 7) Kotlin: Unresolved reference: DependsOn
To see yourself @Czar @qwert_ukg just add
compile 'com.github.holgerbrandl:kscript-annotations:1.1'
to a project and add a
@file:DependsOn("de.mpicbg.scicomp:kutils:0.4")
somewhere before a
package
statement.
Maybe it’s a compiler bug?
c
How is DependsOn defined?
Its target should be
AnnotationTarget.FILE
, check here: https://kotlinlang.org/docs/reference/annotations.html
The problem actually can be reproduced more easily by creating a annotation containing class in the toplevel of a project.
To prove that point I’ve created a small test-repo under https://github.com/holgerbrandl/file_target_annotations
@Czar What do you think?
c
Oh, you have the annotation in different package than your file, you just need to import, and by the way it is really bad idea to use default package. To fix specifically your example add
import MyAnno
after package declaration.
You're right that IJ has some problem here though, it should've suggested to import the annotation. Although if you ask me I'd leave this bug unreported to dissuade people from putting stuff in root package 😄
h
Thanks a lot for the nice explanation. I incorrectly assumed that the default package would be inferred from the source root directory structure, but in fact kotlin assumes the root package as default, if no package is specified. That’s why the
import MyAnno
is not need without the package statement.
I agree about avoiding the root package for the annotations implementation.
c
You're welcome, you can look up Kotlin docs on the matter here: https://kotlinlang.org/docs/reference/packages.html It's quite brief, so won't take much time.
h
Still the import should work imho so https://youtrack.jetbrains.com/issue/KT-21630
👍 1