Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polylith says I have $CLASSPATH set even though it is not #16

Closed
miridius opened this issue Nov 2, 2018 · 3 comments
Closed

Polylith says I have $CLASSPATH set even though it is not #16

miridius opened this issue Nov 2, 2018 · 3 comments
Assignees

Comments

@miridius
Copy link

miridius commented Nov 2, 2018

Describe the bug
Any time I run any polylith command in any project, it says "WARNING: You have $CLASSPATH set, probably by accident. It is strongly recommended to unset this before proceeding.", but I do not have this variable set.

To Reproduce

$ lein polylith create w example com.example
$ cd example
$ echo $CLASSPATH

$ lein polylith build

Changed components:
Changed bases:
Changed systems:

Compiling workspace interfaces
WARNING: You have $CLASSPATH set, probably by accident.
It is strongly recommended to unset this before proceeding.
Created /home/miridius/Projects/NutritionIvy/example/interfaces/target/interfaces-1.0.jar
Wrote /home/miridius/Projects/NutritionIvy/example/interfaces/pom.xml
Installed jar and pom into local repo.

Nothing to test
set :last-success in .polylith/time.edn

Execution time: 1.9 seconds

Expected behavior
The $CLASSPATH error does not show false positives, or, if something is actually wrong it explains the real issue.

Operating System (please complete the following information):

  • OS: Linux Mint
  • Version 19

Versions (please complete the following information):

  • Leiningen: 2.8.1
  • Java: 1.8.0_181
  • Polylith: 0.2.0 (also reproduceable on 0.1.1)
@furkan3ayraktar
Copy link
Collaborator

The warning mentioned in the issue is not printed by the Polylith plugin, it's printed by Leiningen itself as you can see here in its source code. You should see the same error if you try to run any other commands using Leiningen.

Leiningen prints this warning if you have an environment variable named $CLASSPATH. Try to see if you have it by running this command on your terminal:

echo $CLASSPATH

I'm closing this issue since it's not related to Polylith plugin.

@miridius
Copy link
Author

miridius commented Nov 9, 2018

Please take a look at the command log from my original post, I did exactly as you suggested and showed that it is not an issue with my classpath:

  1. echo $CLASSPATH returns nothing.
  2. Running other lein commands does not return this error.

Thanks for telling me that this comes from lein though! That makes understanding the problem a lot easier. I had a dig around in the lein-polylith source code and I figured out that the root cause is that you are calling lein compile in an external process by using clojure.java.shell, and that shell session inherits the environment of the parent process. Since lein polylith is running from within lein, it is getting the lein process' own classpath injected into the shell. So you are basically nesting lein A --> sh --> lein B and lein B is picking up on lein A's classpath.

I injected the following code into leiningen.polylith.cmd.compile to confirm this:

(defn print-inner-sh-classpath []
  (->> (shared/sh "env")
       (str/split-lines)
       (filter #(str/includes? % "CLASSPATH"))
       println))

And sure enough it prints the following:

(CLASSPATH=/home/miridius/.lein/self-installs/leiningen-2.8.1-standalone.jar)

This is the classpath that the lein script itself adds (the exact same script which complains when the classpath is already set). So running lein from within sh from within lein will always give this error. What surprises me is why it's not happening to other users of polylith, perhaps the Mac OS version of lein does not set its own CLASSPATH?

You can reproduce the issue really simply on Linux like this:

$ lein repl
nREPL server started on port 46861 on host 127.0.0.1 - nrepl://127.0.0.1:46861
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-1ubuntu0.18.04.1-b13
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (require '[clojure.java.shell :as shell])
nil
user=> (shell/sh "lein" "version")
{:exit 0, :out "WARNING: You have $CLASSPATH set, probably by accident.\nIt is strongly recommended to unset this before proceeding.\nLeiningen 2.8.1 on Java 1.8.0_181 OpenJDK 64-Bit Server VM\n", :err ""}

@furkan3ayraktar
Copy link
Collaborator

Thank you @miridius for investigating this more. Here are my thoughts on the issue after spending several hours on it.

I've tried it with several Linux versions and with different Oracle and OpenJDK versions, it seems to be like the issue happens on Linux regardless of distribution or JVM. I've also tried to find a clue why Leiningen does not include CLASSPATH on MacOS but I couldn't find.

Even though I still think this is not something we should solve within the Polylith plugin, since it is not a problem/bug caused by the plugin. Although, we need to handle the issue until the real issue is found either in Leiningen, JVM, or Clojure, or maybe somewhere else I can't think of now. I'm also hesitant about adding/fixing things within the code without knowing the exact reason of the problem. We might introduce more problems as well in the future.

P.S. I've also found an example about clojure.java.shell/sh function in the Clojure documentation, where the CLASSPATH variable is removed while calling the sh function within a Leiningen context. You can find the example here. This does not prove or show anything but it's good to see someone else doing the same thing for some reason :).

What do you think about this @tengstrand and @Misophistful? I would like to hear your thoughts about this particular issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants