question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow passing custom classpath vars?

See original GitHub issue

Hi! I really am enjoying using kscript. However, one thing that I think is impossible at the moment is being able to pass a custom classpath. Running vanilla kotlinc allows this (obviously, as kscript ultimately pipes through to kotlinc after some other work), and so does the new jshell in Java 9. It’s useful to be able to add a local JAR to the classpath (both when quickly prototyping when you don’t want to deploy a JAR to a Maven repo, and maybe when you’re using kscript on some work project where your JAR isn’t published to a public repo).

In an ideal world, I’d be able to pass both a custom classpath and //DEPS and have them merged into one big classpath. ex: kscript --interactive "//DEPS com.googlecode.libphonenumber:libphonenumber:8.9.6" --classpath="path/to/my.jar", or similar.

Let me know if you think this is a welcome feature. I’d be happy to discuss possible other formats for the classpath arg as well (maybe it could be part of the // directives, so "//DEPS [gradle deps] //CLASSPATH [local deps]"). I would be happy to contribute a pull request as well if there’s interest.

Thanks for reading!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:20

github_iconTop GitHub Comments

1reaction
holgerbrandlcommented, Aug 21, 2019

With respect to the topic of this ticket, the question for me would be if we want to reuse DependsOn or introduce another annotation to allow for local non-maven dependencies? Clearly, this should be in sync with kotlin-scripting.

@ligee How are/would be local jar dependencies supported in kotlin-scripting?

1reaction
holgerbrandlcommented, Aug 19, 2019

Indeed @zhuker, it’s not as easy as I thought. The correct workaround is

//KOTLIN_OPTS -cp build/libs/jartester-1.0-SNAPSHOT.jar
//COMPILER_OPTS  -cp build/libs/jartester-1.0-SNAPSHOT.jar

Same with annotation config. See referenced commit for a regression test which I have added to prepare for a more solid support of local jars in DependsOn or a via a dedicated separate annotation.

The reason for the double declaration in the workaround is that the kotlinops are not passed to the compiler, and vice versa. I still think that this is the correct approach here because compiler and runtime options are typically different.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting the class path
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if...
Read more >
Java will -classpath option add or replace ... - Stack Overflow
Using the classpath variable it overrides the CLASSPATH of Environment variable but only for that session. If you restart the application ...
Read more >
How to set CLASSPATH in Java - HowToDoInJava
1. Setting CLASSPATH as Environment Variable · From the desktop, right click the Computer icon. · Choose Properties from the context menu. ·...
Read more >
5 ways to add multiple JAR in to Classpath in Java - Examples
5 ways to add multiple JARs in Classpath · 1. Include the JAR name in the CLASSPATH environment variable. · 2. Include the...
Read more >
How to Add JAR file to Classpath in Java? - GeeksforGeeks
In this case, CLASSPATH shell variable contains the list of Jar file which is required by the application. One of the best advantages...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found