Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 475 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kotlin: Kotlin-script (.kts) cannot use regular code?

#1
In my library's codebase, I have this package function: `fun sayHello() = println("Hello there!")`
The function is defined in the package `org.jire.pomade`

I would like to use this function in a _.kts_ file like so: `sayHello()`

Unfortunately I can't seem to get code apart from Kotlin's own stdlib to work in Kotlin-script files.

The entirety of my script:

import org.jire.pomade.sayHello

sayHello()

The result of running the script:

pomade.kts:1:12: error: unresolved reference: jire
import org.jire.pomade.sayHello
^
pomade.kts:3:1: error: unresolved reference: sayHello
sayHello()
^

Anybody know why this is happening? Thanks.
Reply

#2
I suggest to use [holgerbrandl/kscript][1] to manage dependencies of your script.


[1]:

[To see links please register here]

Reply

#3
This is a bug in the Kotlin plugin:

[To see links please register here]

Reply

#4
Alternative is using the Kotlin REPL instead.
Reply

#5
There is experimental support for maven imports in Kotlin scripts since 1.3.

Take a look at

[To see links please register here]

:

@file:Repository("https://jcenter.bintray.com")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.11")

import kotlinx.html.*
import kotlinx.html.stream.*

print(createHTML().html {
body {
h1 { +"Hello, World!" }
}
})

And here is the KEEP:

[To see links please register here]

.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through