heremaps / here-sbt-bom

SBT BOM is the plugin for SBT for dealing with Maven BOM in SBT projects
Other
19 stars 5 forks source link

Failed to resolve NormalizedArtifact #7

Closed gaeljw closed 7 months ago

gaeljw commented 9 months ago

Assuming #6 is fixed (I tried in a sbt 1.6.x project)

I'm now encountering the following issue:

[info] Resolving NormalizedArtifact(com.fasterxml.jackson,jackson-bom,2.16.0)
[warn]  module not found: com.fasterxml.jackson#jackson-bom;2.16.0
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.fasterxml.jackson#jackson-bom;2.16.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 1
[warn] unresolved dependency: com.fasterxml.jackson#jackson-bom;2.16.0: not found
java.lang.RuntimeException: Failed to resolve NormalizedArtifact(com.fasterxml.jackson,jackson-bom,2.16.0)
    at scala.sys.package$.error(package.scala:30)
    at com.here.bom.internal.BomReader.$anonfun$readPom$1(BomReader.scala:69)
    at scala.Option.getOrElse(Option.scala:189)
    at com.here.bom.internal.BomReader.readPom(BomReader.scala:69)
    at com.here.bom.internal.BomReader.go$1(BomReader.scala:202)
    at com.here.bom.internal.BomReader.buildParentsChain(BomReader.scala:226)
    at com.here.bom.internal.BomReader.readPomAndParents(BomReader.scala:165)
    at com.here.bom.internal.BomReader.extractRecursively$1(BomReader.scala:88)
    at com.here.bom.internal.BomReader.makeBom(BomReader.scala:112)
    at com.here.bom.Bom$.$anonfun$read$1(Bom.scala:53)
    at scala.Function1.$anonfun$compose$1(Function1.scala:49)
    at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:228)
    at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:170)
    at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:87)
    at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:99)
    at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:94)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:840)

When using:

// build.sbt
lazy val jacksonBom = Bom.read("com.fasterxml.jackson" % "jackson-bom" % "2.16.0")(bom => JacksonDependencies(bom))

lazy val root = (project in file("."))
 .settings(jacksonBom)

// project/Dependencies.scala
case class JacksonDependencies(bom: Bom)
molekyla commented 9 months ago

Hi @gaeljw. I've created MVP project to demonstrate plugin usage with sbt 1.6.2. Seems all works fine (see Github Actions tab). Please try to build provided project on your environment https://github.com/molekyla/sbt-bom-example-github

gaeljw commented 9 months ago

Thanks for helping @molekyla , will give it more time in the coming days. I guess there's partly my environment bringing issues indeed, I'll need to figure out which part.

gaeljw commented 9 months ago

@molekyla your example project works in my environment and my project on which I had the issue originally also works now. I guess it was related to something on my end then.

Sorry for the noise :neutral_face:

gaeljw commented 7 months ago

I'm having the issue again.

I was able to come up with a reproduction case in a container, to have a clean environment: https://github.com/gaeljw/issue-sbt-bom-resolve

If you execute podman build -f Dockerfile . or docker build -f Dockerfile ., you'll get the same error as originally:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.fasterxml.jackson#jackson-bom;2.16.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 1
[warn] unresolved dependency: com.fasterxml.jackson#jackson-bom;2.16.0: not found
java.lang.RuntimeException: Failed to resolve NormalizedArtifact(com.fasterxml.jackson,jackson-bom,2.16.0)
    at scala.sys.package$.error(package.scala:30)
    at com.here.bom.internal.BomReader.$anonfun$readPom$1(BomReader.scala:69)
    at scala.Option.getOrElse(Option.scala:189)
    at com.here.bom.internal.BomReader.readPom(BomReader.scala:69)
    at com.here.bom.internal.BomReader.go$1(BomReader.scala:209)
    at com.here.bom.internal.BomReader.buildParentsChain(BomReader.scala:233)
    at com.here.bom.internal.BomReader.readPomAndParents(BomReader.scala:172)
    at com.here.bom.internal.BomReader.extractRecursively$1(BomReader.scala:88)
    at com.here.bom.internal.BomReader.makeBom(BomReader.scala:112)
    at com.here.bom.Bom$.$anonfun$read$1(Bom.scala:53)
    at scala.Function1.$anonfun$compose$1(Function1.scala:49)
    at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:229)
    at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:171)
    at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:88)
    at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:100)
    at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:95)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
[error] Failed to resolve NormalizedArtifact(com.fasterxml.jackson,jackson-bom,2.16.0)

I wonder if the cases I've had it working was because I'm using Maven in parallel that had already downloaded some stuff.

gaeljw commented 7 months ago

Here's also a run to reproduce the issue on GHA: https://github.com/gaeljw/issue-sbt-bom-resolve/actions/runs/7901044714/job/21563826054

gaeljw commented 7 months ago

Okay, now that I compare with your repro project, I see the key difference is the resolvers:

The following is mandatory:

ThisBuild / resolvers := Resolver.DefaultMavenRepository +: resolvers.value

I'm surprised because I thought this was in the default resolvers already.

Then I've likely another issue because in my real environment, we use a private registry that acts as a proxy to Maven Central and the same should work but it doesn't.

I'm investigating...

gaeljw commented 7 months ago

Actually I'm wondering if the way the plugin fetches the BOMs is maybe not honoring the "global/environment" settings for repositories?

I think, the fact that we have to explicitly add the Resolver.DefaultMavenRepository is a good symptom of the issue in the 1st place: we shouldn't need it at all as it's included in the default repositories of sbt.

In my corporate use case, I've got my private registry that is configured in ~/.sbt/repositories and works fine for all regular dependencies/plugins but seem to not be used by the sbt-bom plugin (displays the errors given above).

But if I explicitly add my private registry via ThisBuild / resolvers := MavenRepository("somerandomname", "https://artifactory.mycompany.net/artifactory/external") +: resolvers.value (same URL as defined in ~/.sbt/repositories), it works fine.

gaeljw commented 7 months ago

Okay, I think I understand the root cause of the issue.

It's because of https://github.com/heremaps/here-sbt-bom/blob/1077445d575e1f99a3db8fe716f96110a00dae4c/plugin/src/main/scala/com/here/bom/Bom.scala#L45 where we only use update / resolvers as the list of resolvers, which is the list of explicitly added resolvers in the project. It ignores all the resolvers coming from default sbt or set via the environment (like in the ~/.sbt/repositories file).

fullResolvers would probably be better to use but it's not a "setting", it's "task". I'm not really familiar with these concepts but seems like a setting cannot depend on a task and for now the Bom methods were exposing "settings", not "tasks".

EDIT: appResolvers is a setting and seem to contain the same data.

gaeljw commented 7 months ago

Solved by #15 in v1.0.9.