luchiniatwork / cambada

Packager for Clojure based on deps.edn (AKA tools.deps). Supporting jar, uberjar and GraalVM's native-image.
MIT License
222 stars 28 forks source link

ArtifactNotFoundException for a pom artifact, when attempting to create uberjar #19

Open alza-bitz opened 6 years ago

alza-bitz commented 6 years ago

Hi there,

I'm trying to make an uberjar for a project that depends on metosin/spec-tools version 0.8.0, and I am getting the following error:

alex@deneb:/mnt/d/Projects/myproj$ clj -A:uberjar
Cleaning target
Creating target/classes
  Compiling myproj.core
Creating target/myproj-1.0.0-SNAPSHOT.jar
Updating pom.xml
Exception in thread "main" org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for com.fasterxml.jackson.core:jackson-databind:jar:2.9.7
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:323)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:192)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:253)
        at clojure.tools.deps.alpha.extensions.maven$eval2624$fn__2626.invoke(maven.clj:79)
        at clojure.lang.MultiFn.invoke(MultiFn.java:243)
        at clojure.tools.deps.alpha$expand_deps.invokeStatic(alpha.clj:170)
        at clojure.tools.deps.alpha$expand_deps.invoke(alpha.clj:152)
        at clojure.tools.deps.alpha$resolve_deps.invokeStatic(alpha.clj:215)
        at clojure.tools.deps.alpha$resolve_deps.invoke(alpha.clj:197)
        at cambada.uberjar$get_dep_jars.invokeStatic(uberjar.clj:109)
        at cambada.uberjar$get_dep_jars.invoke(uberjar.clj:107)
        at cambada.uberjar$apply_BANG_.invokeStatic(uberjar.clj:132)
        at cambada.uberjar$apply_BANG_.invoke(uberjar.clj:129)
        at cambada.cli$runner.invokeStatic(cli.clj:120)
        at cambada.cli$runner.invoke(cli.clj:115)
        at cambada.uberjar$_main.invokeStatic(uberjar.clj:142)
        at cambada.uberjar$_main.doInvoke(uberjar.clj:140)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:702)
        at clojure.core$apply.invokeStatic(core.clj:657)
        at clojure.main$main_opt.invokeStatic(main.clj:317)
        at clojure.main$main_opt.invoke(main.clj:313)
        at clojure.main$main.invokeStatic(main.clj:424)
        at clojure.main$main.doInvoke(main.clj:387)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:702)
        at clojure.main.main(main.java:37)
Caused by: org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact com.fasterxml.jackson:jackson-base:pom:2.9.7
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:178)
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:224)
        at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:1051)
        at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:829)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:331)
        at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:314)
        ... 26 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact com.fasterxml.jackson:jackson-base:pom:2.9.7
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:422)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:224)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:201)
        at org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:174)
        ... 31 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact com.fasterxml.jackson:jackson-base:pom:2.9.7
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:412)
        ... 34 more

Why is it unable to find this pom artifact? I can see com.fasterxml.jackson:jackson-base:pom:2.9.7 in my ~/.m2 directory.

My deps.edn:

{:deps {metosin/spec-tools {:mvn/version "0.8.0"}}
 :aliases {:uberjar
           {:extra-deps
            {luchiniatwork/cambada {:mvn/version "1.0.0"}}
            :main-opts ["-m" "cambada.uberjar"
                        "-m" "myproj.core"]}}}

The dependency tree:

alex@deneb:/mnt/d/Projects/myproj$ clj -Stree
org.clojure/clojure 1.9.0
  org.clojure/core.specs.alpha 0.1.24
metosin/spec-tools 0.8.0
  org.clojure/spec.alpha 0.2.176
  com.fasterxml.jackson.core/jackson-databind 2.9.7
    com.fasterxml.jackson.core/jackson-annotations 2.9.0
    com.fasterxml.jackson.core/jackson-core 2.9.7
DeLaGuardo commented 6 years ago

Looks like a missing maven repository I solve it by adding "central" {:url "https://repo1.maven.org/maven2/"} into :mvn/repos

DeLaGuardo commented 6 years ago

And I believe it is duplicate of https://github.com/luchiniatwork/cambada/issues/15

alza-bitz commented 6 years ago

Ah whoops I didn't realise this is a known issue!

Thanks for the tip - I solved by placing the following in my deps.edn map:

:mvn/repos {"central" {:url "https://repo1.maven.org/maven2/"}
            "clojars" {:url "https://repo.clojars.org/"}}

I needed clojars in addition, otherwise metosin/spec-tools could not be found.

I didn't think I even had a "system" deps.edn file, but then I found it: /usr/local/lib/clojure/deps.edn. I guess the Clojure installer puts it there!

maxp commented 5 years ago

I have an issue like that. Uberjar produced ok when I use cheshire 5.8.0, but falis with 5.8.1. The difference between 5.8.0 and 5.8.1 is Jaskson 2.9.0 and 2.9.6.

aviflax commented 5 years ago

I just encountered the same problem as @maxp. In this case it doesn’t seem to be related to the system deps.edn (although I’m not 100% sure).

I was able to work around this by forcing all Jackson artifacts to 2.9.8 by adding them to the root :deps map in my deps.edn:

com.fasterxml.jackson.core/jackson-core                   {:mvn/version "2.9.8"}
com.fasterxml.jackson.dataformat/jackson-dataformat-cbor  {:mvn/version "2.9.8"}
com.fasterxml.jackson.dataformat/jackson-dataformat-smile {:mvn/version "2.9.8"}

(YMMV)

aviflax commented 5 years ago

If anyone has any idea whether this issue with Jackson 2.9.6 is rooted in Cheshire, Jackson, or tools.deps, I’d be happy to report it to the most likely candidate. I myself just have no idea.

DeLaGuardo commented 5 years ago

@maxp @aviflax the problem is in the way how cambada reads deps.edn. It doesn't know the location of system-level deps.edn so it can read only project-level file.

Solution is to include all :mvn/repos listed in global deps file into your project's deps.edn.

deps.edn

{:deps {metosin/spec-tools {:mvn/version "0.9.1"}}
 :aliases {:cambada
           {:extra-deps
            {luchiniatwork/cambada
             {:mvn/version "1.0.0"}}}}
 :mvn/repos {"central" {:url "http://central.maven.org/maven2/"}
             "clojars" {:url "https://repo.clojars.org/"}}
 :paths ["src"]}

main namespace

(ns min.core
  (:require [spec-tools.swagger.core :as swagger]
            [clojure.spec.alpha :as s])
  (:gen-class))

(s/def ::id string?)
(s/def ::name string?)
(s/def ::street string?)
(s/def ::city #{:tre :hki})
(s/def ::address (s/keys :req-un [::street ::city]))
(s/def ::user (s/keys :req-un [::id ::name ::address]))

(defn -main [& args]
  (println
   (swagger/swagger-spec
    {:swagger "2.0"
     :info {:version "1.0.0"
            :title "Sausages"
            :description "Sausage description"
            :termsOfService "http://helloreverb.com/terms/"
            :contact {:name "My API Team"
                      :email "foo@example.com"
                      :url "http://www.metosin.fi"}
            :license {:name "Eclipse Public License"
                      :url "http://www.eclipse.org/legal/epl-v10.html"}}
     :tags [{:name "user"
             :description "User stuff"}]
     :paths {"/api/ping" {:get {:responses {:default {:description ""}}}}
             "/user/:id" {:post {:summary "User Api"
                                 :description "User Api description"
                                 :tags ["user"]
                                 ::swagger/parameters {:path (s/keys :req [::id])
                                                       :body ::user}
                                 ::swagger/responses {200 {:schema ::user
                                                           :description "Found it!"}
                                                      404 {:description "Ohnoes."}}}}}})))

Output

personal/min [master●] » clj -R:cambada -m cambada.uberjar                         
Cleaning target
Creating target/classes
  Compiling min.core
Creating target/min-1.0.0-SNAPSHOT.jar
Updating pom.xml
Creating target/min-1.0.0-SNAPSHOT-standalone.jar
  Including min-1.0.0-SNAPSHOT.jar
  Including spec-tools-0.9.1.jar
  Including clojure-1.9.0.jar
  Including spec.alpha-0.2.176.jar
  Including jackson-databind-2.9.8.jar
  Including core.specs.alpha-0.1.24.jar
  Including jackson-annotations-2.9.0.jar
  Including jackson-core-2.9.8.jar
Done!
personal/min [master●] » java -cp target/min-1.0.0-SNAPSHOT-standalone.jar min.core
{:swagger 2.0, :info {:version 1.0.0, :title Sausages, :description Sausage description, :termsOfService http://helloreverb.com/terms/, :contact {:name My API Team, :email foo@example.com, :url http://www.metosin.fi}, :license {:name Eclipse Public License, :url http://www.eclipse.org/legal/epl-v10.html}}, :tags [{:name user, :description User stuff}], :paths {/api/ping {:get {:responses {:default {:description }}}}, /user/:id {:post {:summary User Api, :description User Api description, :tags [user], :parameters [{:in path, :name min.core/id, :description , :type string, :required true} {:in body, :name min.core/user, :description , :required true, :schema {:type object, :properties {id {:type string}, name {:type string}, address {:type object, :properties {street {:type string}, city {:enum [:tre :hki], :type string}}, :required [street city], :title min.core/address}}, :required [id name address], :title min.core/user}}], :responses {200 {:schema {:type object, :properties {id {:type string}, name {:type string}, address {:type object, :properties {street {:type string}, city {:enum [:tre :hki], :type string}}, :required [street city], :title min.core/address}}, :required [id name address], :title min.core/user}, :description Found it!}, 404 {:description Ohnoes.}}}}}}
aviflax commented 5 years ago

@delaguardo thank you! Very helpful!

🤔 I wonder if we should/could modify Cambada such that it checks whether deps.edn contains :mvn/repos — and if not, add in a default value. I think I like this idea, but it might violate the principle of least surprise. At the very least it seems we should add something to the docs to address this.

luchiniatwork commented 5 years ago

@aviflax I wonder if this is the behavior that the clojure script has under the hood because, even though cambada depends on tools.deps (which is what the clojure script should be using), this behaviour we are seeing on cambada is triggered by tools.deps

smogg commented 4 years ago

For me the error was:

Execution error (MetadataNotFoundException) at org.eclipse.aether.internal.impl.DefaultMetadataResolver/resolve (DefaultMetadataResolver.java:233).
Could not find metadata org.clojure:clojure/maven-metadata.xml in local (~/.m2/repository)

Adding :mvn/repos {"central" {:url "https://repo1.maven.org/maven2/"}} also solved it for me. Having the solution mentioned in the readme would have saved me some time.