Comments (4)
Hi! I seems to be a problem with kotlin-main-kts
dependency resolver. For a quick solution a would recommend using local jar of kotlin-shell
. So the scrript would look like:
//@file:Repository("https://dl.bintray.com/jakubriegel/kotlin-shell")
//@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
@file:DependsOn("kotlin-shell/kotlin-shell-core/build/libs/kotlin-shell-core-0.2.1.jar")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-io-jvm:0.1.11")
@file:DependsOn("org.zeroturnaround:zt-exec:1.11")
@file:DependsOn("org.slf4j:slf4j-nop:1.7.28")
@file:CompilerOptions("-Xopt-in=kotlin.RequiresOptIn")
@file:OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
import eu.jrie.jetbrains.kotlinshell.shell.*
import kotlin.system.exitProcess
shell {
val toUpper = stringLambda { it.toUpperCase() to "" }
pipeline { "curl https://uli-ifinder-demo.intrafind.net".process() pipe "grep Analyzer".process() pipe toUpper }
}
exitProcess(0)
To get the jar you can clone kotlin-shell
repo and run ./gradlew shadowJar
or download it from bintray.
Meanwhile I will try to investigate this problem further
from kotlin-shell.
test.main.kts:
#!/usr/bin/env kotlin
@file:Repository("https://jcenter.bintray.com")
//@file:Repository("https://dl.bintray.com/kotlin/kotlinx")
//@file:Repository("https://dl.bintray.com/jakubriegel/kotlin-shell")
//@file:Repository("central", "central", "https://dl.bintray.com")
@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
//@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2-dev")
//@file:DependsOn("kotlin-shell-core-0.2.1.jar")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
@file:DependsOn("io.ktor:ktor-http-jvm:1.3.1")
@file:DependsOn("org.jetbrains.kotlin:kotlin-test-junit5:1.3.72")
@file:DependsOn("org.zeroturnaround:zt-exec:1.11")
@file:DependsOn("org.slf4j:slf4j-nop:1.7.30")
@file:DependsOn("com.squareup.okhttp3:okhttp:4.5.0")
@file:CompilerOptions("-Xopt-in=kotlin.RequiresOptIn")
import eu.jrie.jetbrains.kotlinshell.shell.shell
import io.ktor.http.HttpStatusCode
import okhttp3.OkHttpClient
import okhttp3.Request
import kotlin.system.exitProcess
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
println("TENANT ${System.getenv("TENANT")}")
lateinit var targetUrl: String
println("args.size: ${args.size}")
if (args.isNotEmpty()) {
println("args: ${args.joinToString()}")
targetUrl = args[0]
} else {
println("targetUrl required")
exitProcess(2)
}
println("targetUrl $targetUrl")
@kotlinx.coroutines.ExperimentalCoroutinesApi
val httpClient = OkHttpClient.Builder()
.followRedirects(false)
.followSslRedirects(false)
.build()
val request = Request.Builder()
.url(targetUrl)
.build()
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
httpClient.newCall(request).execute().use { response ->
println(response.body?.contentLength())
println(response.code)
assertNotNull(response.code)
assertEquals(200, response.code)
assertEquals(HttpStatusCode.OK.value, response.code)
}
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
shell {
val toUpper = stringLambda { it.toUpperCase() to "" }
pipeline { "curl $targetUrl".process() pipe "grep Analyzer".process() pipe toUpper }
}
exitProcess(0)
Run this file locally
./test.main.kts https://example.com
...everything runs fine with Java 13.
To reproduce the issue, run
docker run -it -v /home/alex/Desktop:/srv loxal/kotlin-toolbox:1.4-M1-java13 ./test.main.kts
Kotlin v1.3.x prints the same error message as Kotlin v1.4-M1. Apparently the container environment creates the virgin environments that causes the problem.
cc @jakubriegel
from kotlin-shell.
Thanks a lot, your proposal solved my problem.
The curious fact is that the script runs fine with
@file:Repository("https://dl.bintray.com/jakubriegel/kotlin-shell")
@file:DependsOn("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
on my day-to-day notebook with Ubuntu 20.04 and a regular system user that has a quite full local ~/.gradle
repository.
However on my CI where the job is executed as root, I had to deploy your fix which worked fine. I hope, this info helps you fixing the issue.
from kotlin-shell.
Should now be fixed by #16
from kotlin-shell.
Related Issues (13)
- .process() substitute "\n\n" by "\n"? HOT 3
- bintray is being sunset HOT 4
- clarify license HOT 1
- publish to Maven central HOT 11
- Published package info is incorrect HOT 2
- Sensitive ENV info leaks on process 🚨
- Substitution / easily access stdout of Process? HOT 2
- Throw on errors ? HOT 2
- ::export with vararg HOT 2
- How can I get the output of a command? HOT 3
- Interpolation of Kotlin variables not working? HOT 3
- Running piped commands seems not to work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlin-shell.