Does .main.kts support resolving transitive depend...
# scripting
m
Does .main.kts support resolving transitive dependencies ? In
@file:DependsOn()
annotations ? I have some weird cases where it looks like it doesn't.
v
I hope, would be pretty useless otherwise imho. Maybe it would help if you tell what problems you have and maybe an MCVE. 😉
m
It might be something wrong with my publications, hence why I'm asking. I'll try to make a small reproducer
Not what I was looking for but I found another bug 😅
Or maybe it was because I deleted
~/.ivy2
...
Looks like it resolves
compile
but not
runtime
dependencies. I filed https://youtrack.jetbrains.com/issue/KT-44816
v
Oh, that's bad
a
Runtime dependencies are not resolved in principle, they must be provided by used on the runtime classpath.
v
Yeah, but why? It is nice to resolve only compile dependencies for compilation to increase chance for cache and reduce compile class path for faster compilation and so on, but for running it should use the runtime class path, otherwise it's pretty useless.
a
As far as I remember (I have not used maven for a while) the primary usage for runtime scope is to provide some kind of platform-specific drivers like jdbc. It does not make any sense to download them if they are to be provided manually.
v
You confuse
runtime
with
provided
provided
means "I need this, but you have to give it to me, I don't have a programmatic depencency in the pom on it"
runtime
means "I need this at runtime but I don't need it for compilation"
a
Indeed. But the common example is JDBC and you do not know in advance what JDBC driver will you use. It is provided manually. Maybe I am mistaken. I have never used this option myself.
v
The common example for what? JDBC drivers you would usually put to
provided
scope, because you expect that the user of the lib provides the correct JDBC driver for his database at runtime
l
.main.kts does not always resolve dependencies no matter what. A solution is to use an alternative script runner e.g., kts: https://github.com/markaren/kts kts is a drop in replacement for main.kts syntax highlighting will work in IntelliJ, but you need kts to run the script
The reason seems to be that main.kts uses ivy, which I guess is not so powerful as maven
m
How is
kts
different from
kscript
? https://github.com/holgerbrandl/kscript
l
I'm not super sure tbh. I made kts mostly for my own needs. Implementation wise it is quite simple and plays nice with main.kts. kscript also claims it is for *nix-based systems
👍 1
kts is basically just a few lines of code
a
kotlin scripting is not kscript, it took some inspiration form the project, but it is adifferent tool. Kscript is based on bash whereas kotlin-scripting is a fully kotlin approach with multiplatform support.
m
Sure thing, kscript is a script runner like kts though, from what I understand?
(kts as in https://github.com/markaren/kts, not the file extension)
a
ah, ok
l
Actually, kts is main.kts just with a different caching and resolution strategy. Once main.kts is updated to use the maven handler (which Jetbrains already supply as a library), kts will not be needed anymore
v
The reason seems to be that main.kts uses ivy, which I guess is not so powerful as maven
That's not really true. Actually Ivy is more powerful than Maven in many aspects.
l
Might be a poor choice of words. Maven is at least very easy to setup programmatically to fully resolve dependencies. I can't answer for ivy as I have not used it.
v
I c, that I cannot tell, only ever used it from Ant or command line
s
If I recall, the reason behind using ivy and not maven to resolve dependencies is because the ivy dependency is pretty more compact, the final main kts runner using ivy is like 2mb if I'm correctly