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

Fix snapshot version support for leiningen #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JohnnyJayJay
Copy link
Contributor

It's me again, fixing Leiningen stuff as I encounter it.

The current code doesn't support the use of snapshot version from Leiningen, due to the caching being implemented via missing-mvn-deps. Here's the error you encounter if you try, for reference:

Error
{:clojure.main/message
 "Execution error (AssertionError) at cljnix.utils/mvn-repo-info (utils.clj:134).\nAssert failed: (if (snapshot? path) (not (nil? exact-version)) true)\n",
 :clojure.main/triage
 {:clojure.error/class java.lang.AssertionError,
  :clojure.error/line 134,
  :clojure.error/cause
  "Assert failed: (if (snapshot? path) (not (nil? exact-version)) true)",
  :clojure.error/symbol cljnix.utils/mvn-repo-info,
  :clojure.error/source "utils.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.lang.AssertionError,
    :message
    "Assert failed: (if (snapshot? path) (not (nil? exact-version)) true)",
    :at [cljnix.utils$mvn_repo_info invokeStatic "utils.clj" 134]}],
  :trace
  [[cljnix.utils$mvn_repo_info invokeStatic "utils.clj" 134]
   [cljnix.utils$mvn_repo_info doInvoke "utils.clj" 134]
   [clojure.lang.RestFn invoke "RestFn.java" 423]
   [cljnix.core$missing_mvn_deps$fn__22429 invoke "core.clj" 176]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2759]
   [clojure.core$filter$fn__5958$fn__5959 invoke "core.clj" 2823]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2759]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2759]
   [clojure.core$filter$fn__5958$fn__5959 invoke "core.clj" 2823]
   [clojure.lang.PersistentVector reduce "PersistentVector.java" 343]
   [clojure.core$transduce invokeStatic "core.clj" 6947]
   [clojure.core$into invokeStatic "core.clj" 6963]
   [clojure.core$into invoke "core.clj" 6951]
   [cljnix.core$missing_mvn_deps invokeStatic "core.clj" 168]
   [cljnix.core$missing_mvn_deps invoke "core.clj" 160]
   [cljnix.core$lock_file$fn__22521 invoke "core.clj" 398]
   [clojure.core$completing$fn__8528 invoke "core.clj" 6931]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2757]
   [clojure.core$cat$fn__8851 invoke "core.clj" 7696]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2757]
   [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2757]
   [clojure.core$transduce invokeStatic "core.clj" 6949]
   [clojure.core$transduce invoke "core.clj" 6934]
   [cljnix.core$lock_file invokeStatic "core.clj" 381]
   [cljnix.core$lock_file invoke "core.clj" 372]
   [cljnix.core$_main invokeStatic "core.clj" 508]
   [cljnix.core$_main doInvoke "core.clj" 503]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 514]
   [clojure.main$main_opt invoke "main.clj" 510]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause
  "Assert failed: (if (snapshot? path) (not (nil? exact-version)) true)"}}

I've spent some time debugging and trying to understand the logic of mvn-repo-info, and while I'm not entirely sure I get it, I found that simply setting the :exact-version of any "missing dep" to "SNAPSHOT" would circumvent the issue because it results in the desired behaviour.

I realise that this might be a hack. Let me know if there is a flaw in what I've done here or if you see other ways to mitigate the issue.

@jlesquembre
Copy link
Owner

Reviewing that logic again, I guess the :pre check in mvn-repo-info was added only for debugging purposes and was committed by mistake. We can remove it, which should fix the issue in Leiningen.

Maybe we can remove the need for the exact-version argument, but I prefer to wait to do that.

@JohnnyJayJay
Copy link
Contributor Author

Reviewing that logic again, I guess the :pre check in mvn-repo-info was added only for debugging purposes and was committed by mistake. We can remove it, which should fix the issue in Leiningen.

Maybe we can remove the need for the exact-version argument, but I prefer to wait to do that.

I see... yeah, as I said, I don't really understand the purpose of :exact-version.

Do you want me to remove the assertion?

@jlesquembre
Copy link
Owner

I see... yeah, as I said, I don't really understand the purpose of :exact-version.

Definitely I need to document that. In short, it is because foo-SNAPSHOT is expanded to something like foo-20220502.201054-5. I'll try to document it whenever I find some extra time

Do you want me to remove the assertion?

If you do it, I'll merge the PR, if not, I'll do that later today or tomorrow

@jlesquembre
Copy link
Owner

@JohnnyJayJay please let me know if #152 fixes it for you

@JohnnyJayJay
Copy link
Contributor Author

@JohnnyJayJay please let me know if #152 fixes it for you

It actually doesn't.

Result of running nix run github:jlesquembre/clj-nix#deps-lock -- --lein --lein-profiles uberjar in my project instant-poll:

Error
{:clojure.main/message
 "Execution error (ExceptionInfo) at cljnix.utils/throw+ (utils.clj:26).\n\"Maven repo not found\" {:mvn-repos {\"central\" {:url \"https://repo1.maven.org/maven2/\"}, \"clojars\" {:url \"https://repo.clojars.org/\"}}, :repo-name nil, :file #object[sun.nio.fs.UnixPath 0x13879c47 \"/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom\"]}\n\n",
 :clojure.main/triage
 {:clojure.error/class clojure.lang.ExceptionInfo,
  :clojure.error/line 26,
  :clojure.error/cause
  "\"Maven repo not found\" {:mvn-repos {\"central\" {:url \"https://repo1.maven.org/maven2/\"}, \"clojars\" {:url \"https://repo.clojars.org/\"}}, :repo-name nil, :file #object[sun.nio.fs.UnixPath 0x13879c47 \"/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom\"]}\n",
  :clojure.error/symbol cljnix.utils/throw+,
  :clojure.error/source "utils.clj",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type clojure.lang.ExceptionInfo,
    :message
    "\"Maven repo not found\" {:mvn-repos {\"central\" {:url \"https://repo1.maven.org/maven2/\"}, \"clojars\" {:url \"https://repo.clojars.org/\"}}, :repo-name nil, :file #object[sun.nio.fs.UnixPath 0x13879c47 \"/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom\"]}\n",
    :data
    {:mvn-repos
     {"central" {:url "https://repo1.maven.org/maven2/"},
      "clojars" {:url "https://repo.clojars.org/"}},
     :repo-name nil,
     :file
     #object[sun.nio.fs.UnixPath 0x13879c47 "/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom"]},
    :at [cljnix.utils$throw_PLUS_ invokeStatic "utils.clj" 26]}],
  :trace
  [[cljnix.utils$throw_PLUS_ invokeStatic "utils.clj" 26]
   [cljnix.utils$throw_PLUS_ invoke "utils.clj" 24]
   [cljnix.utils$mvn_repo_info invokeStatic "utils.clj" 148]
   [cljnix.utils$mvn_repo_info doInvoke "utils.clj" 134]
   [clojure.lang.RestFn invoke "RestFn.java" 426]
   [cljnix.core$missing_mvn_deps$fn__22422 invoke "core.clj" 176]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2759]
   [clojure.core$filter$fn__5977$fn__5978 invoke "core.clj" 2823]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2759]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2759]
   [clojure.core$filter$fn__5977$fn__5978 invoke "core.clj" 2823]
   [clojure.lang.PersistentVector reduce "PersistentVector.java" 418]
   [clojure.core$transduce invokeStatic "core.clj" 7025]
   [clojure.core$into invokeStatic "core.clj" 7042]
   [clojure.core$into invoke "core.clj" 7029]
   [cljnix.core$missing_mvn_deps invokeStatic "core.clj" 168]
   [cljnix.core$missing_mvn_deps invoke "core.clj" 160]
   [cljnix.core$lock_file$fn__22514 invoke "core.clj" 398]
   [clojure.core$completing$fn__8558 invoke "core.clj" 7009]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2757]
   [clojure.core$cat$fn__8893 invoke "core.clj" 7819]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2757]
   [clojure.core$map$fn__5950$fn__5951 invoke "core.clj" 2757]
   [clojure.core$transduce invokeStatic "core.clj" 7027]
   [clojure.core$transduce invoke "core.clj" 7012]
   [cljnix.core$lock_file invokeStatic "core.clj" 381]
   [cljnix.core$lock_file invoke "core.clj" 372]
   [cljnix.core$_main invokeStatic "core.clj" 508]
   [cljnix.core$_main doInvoke "core.clj" 503]
   [clojure.lang.RestFn applyTo "RestFn.java" 140]
   [clojure.lang.Var applyTo "Var.java" 707]
   [clojure.core$apply invokeStatic "core.clj" 667]
   [clojure.main$main_opt invokeStatic "main.clj" 515]
   [clojure.main$main_opt invoke "main.clj" 511]
   [clojure.main$main invokeStatic "main.clj" 665]
   [clojure.main$main doInvoke "main.clj" 617]
   [clojure.lang.RestFn applyTo "RestFn.java" 140]
   [clojure.lang.Var applyTo "Var.java" 707]
   [clojure.main main "main.java" 40]],
  :cause
  "\"Maven repo not found\" {:mvn-repos {\"central\" {:url \"https://repo1.maven.org/maven2/\"}, \"clojars\" {:url \"https://repo.clojars.org/\"}}, :repo-name nil, :file #object[sun.nio.fs.UnixPath 0x13879c47 \"/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom\"]}\n",
  :data
  {:mvn-repos
   {"central" {:url "https://repo1.maven.org/maven2/"},
    "clojars" {:url "https://repo.clojars.org/"}},
   :repo-name nil,
   :file
   #object[sun.nio.fs.UnixPath 0x13879c47 "/tmp/clj-cache810067721318020057/mvn/com/github/johnnyjayjay/slash/0.5.0-SNAPSHOT/slash-0.5.0-SNAPSHOT.pom"]}}}

With my "fix" (on this PR), it works. I think it's because the :pre check isn't the only issue; :exact-version is part of an if later that influences the result. If it's nil at that point, it doesn't work.

Sorry for the late response. I think I even remember testing this 2 weeks ago.

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

Successfully merging this pull request may close these issues.

2 participants