Hey guys, me again. I'm currently struggling to mi...
# general
b
Hey guys, me again. I'm currently struggling to migrate my private POC project to use pants v2. That POC projects uses most popular libs from Scala world. The problem is that managing dependencies in JVM world is kinda a headache (and it has always been a headache). For example if you run
cs resolve -t org.typelevel:log4cats-slf4j_2.13:2.5.0
for a small library
log4cats
it will already show you conflicts among transitive dependencies (and its a single lib, not a group of them). Conflicts resolution is very very important topic for every build tool that is used for Java/Scala project (if project is not
Hello world
of cause).... I'm pretty sure JVM community will be keen on adopting pants v2 if there was any support for conflict resolution strategy. For example doing something like this would be very helpful.
Copy code
versionReconciliation ++= Seq(
  "org.typelevel" %% "cats-core" % "relaxed",
  "*" % "*" % "strict"
)
https://www.scala-lang.org/2019/10/17/dependency-management.html Anyways thank u for great tool! Looking forward for new features (heard that
scala_library
is on its way....)
a
@brave-planet-28195 Hey, thanks for reaching out! This sounds interesting! We use Coursier under the hood to do maven fetching, which means that we can specify requirements as being
strict
— indeed, we use
strict
under the hood to implement lockfiles. Is being able to specify a particular artifact as
strict
sufficient for you, or do you need other reconciliation types? sdo you need anything other than
b
please checkout this discussion. https://pantsbuild.slack.com/archives/C046T6T9U/p1665011485085219?thread_ts=1665002687.080499&cid=C046T6T9U I think there are problems with
strict-include
...
Having strict would be good. also seen cursier resolution tree would be very helpful
cause now I need to manually run
coursier resolve ...
for every artifact that I specify in
3rdparty
folder
a
Out of interest, does manually specifying the conflicting dependency as a
jvm_artifact
help here?
b
I have project that uses
fs2
,
tapir
,
http4s
,
fs2-kafka
.
cats
,
neotypes
That creates a total mess if run in
strict
mode - this is general problem on conflicts resolution on JVM world - not related to pants. The way to workaround this problem is to provide sane
excludes
for jvm artifacts and compose them with proper versions
what is not fun is that I can't ask
pants
to show me the actual conflicts....
a
By excludes, you mean being able to specify which transitive dependencies to exclude for a given artifact?
Does Pants give you any error at all when you get conflicts?
b
for example
cats-core
is real pain... it causes conflicts all over the place. So what i do is this:
Copy code
jvm_artifact(
    name="cats-effect",
    group="org.typelevel",
    artifact="cats-effect_2.13",
    version="3.3.14",
    packages=["cats.effect.**"],
    excludes=[
        "org.typelevel:cats-core_2.13"
    ]
)
I exclude cats-core from cats-effect
and then just add it as another jvm artifact with proper version
Copy code
jvm_artifact(
    name="cats-core",
    group="org.typelevel",
    artifact="cats-core_2.13",
    version="2.8.0",
    packages=["cats.**"],
)
a
Yeah, that’s definitely how we envisaged it being used (in our initial, best-effort, first implementation)
Are you seeing any error at all when you encounter a conflict
b
in general resolving conflicts in codebase that uses alot of libs is hard.... there are few things that I picked up while switching from sbt to pants: 1. When pants (or rather coursier) finds a conflict it seems like the library under conflict will just be removed from classpath. That is done
silently
. Considering the fact that conflicts will happen in transitive dependencies - developer can see errors in runtime
ClassNotFound
. No compile time error.... nothing 2. That's why
conflict resolution
strategy is critical for JVM. For example sbt comes with several conflict resolution strategies. I understand that pants v2 is work in progress and what was already done is great. But for JVM community do adopt tool quicker it would be great to have at list 1 conflict resolution strategy (Strict). That would fail during
check
goal if there are conflicts and display coursier transitive dependencies tree
a
Right, I understand the need for conflict resolution, just trying to see what the current state of it is
So if there’s a conflict, it doesn’t resolve it at all, and you don’t see an error?
b
exactly
I created this simples example here https://github.com/ekravchenko/dependency_example
The program is not doing anything fancy - just printing "Hello world!"
now if I add dependency to
cats-core
(version 2.8,0) - that will create a dependency conflict
cause
cats-effect
has transitive dependency to cats-core 2.7.0
a
Would you be willing to commit the broken configuration to a branch? That way I can get an issue written up
b
My expectation is the following "Ok there could be a conflict in dependencies but my build tool will warn me"
a
I understand
b
Instead of warning or error - pants just removed lib under conflict from classpath
so what actually happens • source compiles just fine everything is green • runtime error ->
java.lang.NoClassDefFoundError: cats/kernel/Semigroup
Would you be willing to commit the broken configuration to a branch? That way I can get an issue written up
I can create and issue in pants to further discuss this....
a
That would be great
b
There is a way to workaround - but you need to be an expert in dependencies ... 😉
a
But if you can include a link to your repo, with the configuration that behaves incorrectly, that’d be great
b
that's repo with example that is broken
a
Right, does that have the dependency that causes the error?
b
yeap
a
ok, great
did you say you were going to write the issue?
b
yeah I can do that
a
Great, thank you!
b
a
Thank you for this!
👍 1