Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the dependencies of IntelliJ Scratch files?

I have a scratch file using guava collections, and I get some weird errors that I have to assume is due to the editor and the actual run environment assuming different versions of the guava collections:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.google.common.collect.Range.<init>(Lcom/google/common/collect/Cut;Lcom/google/common/collect/Cut;)V from class 
com.google.common.collect.Ranges
    at com.google.common.collect.Ranges.create(Ranges.java:80)
    at com.google.common.collect.Ranges.closedOpen(Ranges.java:114)
    at Scratch.main(scratch_2.java:69)

Not that I can actually know that for sure because I also can't figure out how I'm supposed to see which version the scratch file is pulling in. I've removed guava from my project's deps ENTIRELY and the scratch file still works... WHY? Where is the library coming from??? The scratch run config is completely empty of anything that would dictate this:

scratch run config

And yet it still runs just fine. I discovered that if I delete the guava entries from my local ivy cache, it won't run anymore. If I then add guava back to my project's deps, it ends up in my ivy cache again, and then even if I remove guava from the project deps the scratch file is fine again. So does the scratch file just pick a random version or something? The ivy cache, which is at ~/.ivy2/cache/com.google.guava, looks like this:

ivy cache

But there's also that "jars" folder that has a guava-12.0 for some reason:

other folder in ivy cache

And again, I have no idea which version is being used, or why the cache has so many different versions of it. Any ideas?

like image 785
K. M Avatar asked Jul 04 '18 20:07

K. M


People also ask

Where does IntelliJ store scratch files?

Location of scratch files and buffers By default, IntelliJ IDEA stores scratch files and buffers in the IDE configuration directory under scratches. They are available from any IDE and project that uses this configuration directory.

Which directory is used for holding scratch files in Tomcat?

Tip: Scratch files and buffers are stored in the IDE configuration directory under scratches.


1 Answers

One way that proved to be the simplest to me was to select "use classpath of an existing project module" (which has dependencies configured) in the run configuration dialog. This is useful if you want to pull out a piece of functionality from your project to play with in isolation but still use the configured dependencies.

like image 123
Michal Filip Avatar answered Oct 02 '22 13:10

Michal Filip