Making progress in building my Scala projects, but...
# general
a
Making progress in building my Scala projects, but I’ve got a unique setup that I’m not sure how to get working with Pants TL;DR: Is it possible to have a target depend on another target that uses a different
resolve
? I’m getting a
NoCompatibleResolve
error In sbt I have a project called
predef
that defines an object with the full package path
example.Predef
. Every other project then gets an additional scalac arg:
Copy code
-Yimports:java.lang,scala,scala.Predef,example.Predef
This makes it so that everything defined in
example.Predef
is available without needing any imports I’m trying to mirror this in my Pants config. In
pants.toml
I have:
Copy code
[jvm.resolves]
jvm-default = "3rdparty/jvm/deps.lock"
uses-predef = "3rdparty/jvm/deps.lock"

[scala.version_for_resolve]
jvm-default = "3.7.3"
uses-predef = "3.7.3"

[scalac]
args = ["-deprecation", "-encoding", "utf8"]

[scalac.args_for_resolve]
uses-predef = ["-Yimports:java.lang,scala,scala.Predef,example.Predef"]
In
3rdparty/jvm/BUILD
I have:
Copy code
jvm_artifact(
  name = "jvm-default-org.scala-lang_scala3-library_3",
  group = "org.scala-lang",
  artifact = "scala3-library_3",
  version = "3.7.3",
  resolve = "jvm-default",
)

jvm_artifact(
  name = "uses-predef-org.scala-lang_scala3-library_3",
  # ...same group, artifact, and version as above...
  resolve = "uses-predef",
)
And in a target (
shared/src/main/scala/example/BUILD
) that should get the extra scalac arg I have:
Copy code
scala_sources(
  resolve = "uses-predef",
  dependencies = ["predef/src/main/scala/example"],
)
When I run
pants check ::
I get this error:
Copy code
NoCompatibleResolve: The selected targets did not have a resolve in common:

jvm-default:
  * 3rdparty/jvm:jvm-default-org.scala-lang_scala3-library_3
  * predef/src/main/scala/example/Predef.scala

uses-predef:
  * 3rdparty/jvm:uses-predef-org.scala-lang_scala3-library_3
  * shared/src/main/scala/example/Example.scala

Targets which will be merged onto the same classpath must share a resolve (from the [resolve](<https://www.pantsbuild.org/2.29/reference/targets/deploy_jar#resolve>) field).
Here’s a repo that demonstrates the issue: https://github.com/mrdziuban/pants-predef-test
h
To clarify, a "resolve" just means a lockfile. Why would you need two different resolves pointing to the same underlying lockfile, which looks like what you're trying to do?
a
That’s the only way I could see to have a separate set of scalac args. Is there a different way?
“That” being having separate resolves. They don’t have to point to the same lockfile, I just wanted to use
3rdparty/jvm/BUILD
to specify the dependencies for both
h
Ah, I see. Hmmm, that is a tricky one. The "args_for_resolve" mechanism abuses resolves to provide functionality that is not strictly dependent on them. And your use case is running afoul of this. Let me think about this one.
a
Sounds good, thanks for taking a look!
h
If you don't hear back in a couple of days, ping me here to remind me 🙂
I'm traveling, so am falling behind on some things
a
No worries and will do 👍
Hey @happy-kitchen-89482, just checking in to see if you had any new thoughts on this. No worries if not
h
Unfortunately I don't see a clean solution here. I'm assuming that adding
-Yimports:java.lang,scala,scala.Predef,example.Predef
when compiling Predef itself leads to error?
a
Yeah unfortunately it does
Copy code
error: bad preamble import example.Predef
h
Yeah, I would expect it to
I wonder if there is a way to compile it with a dummy Predef
let me think on that
hacky, but it might solve the problem