Hi, is there a best practice on how to do "cross c...
# general
b
Hi, is there a best practice on how to do "cross compiling" with 2 different sets of dependencies? I have a BUILD that produces a fatjar with a whole tree of dependencies under it. At various parts of the tree it needs
libx=1.1
. I'd like to build the fatjar once with
libx=1.1
and once with
libx=1.2
. I can think of 2 ways to do it: a) At the top fatjar, exclude all libx dependencies, and then include the version I want b) At every point in the tree, pass some flag (env variable?) so that it can switch between 1.1 and 1.2 And of course, I'd like to avoid the solution that requires a copy of all the
BUILD
files. Thanks for any pointers.
e
To make sure I'm on the same page: what is "fatjar" is this the output of Pants v1
./pants binary
?
b
yep pants binary
e
Ok. Can you just duplicate the jvm_binary target and pin the desired dep as a top-level dependency in each?
b
yep, thats my approach (a). but I also need to exclude the unwanted depenency right? i guess i dont know the details of how exclude works...will it look at the entire tree below and make sure no instance of that library shows up?
e
Well. Before going there. Is it true that besides for these jvm_binary targets no other code actually cares which version of this library? (Hopefully true since you want to unconditinally set it to one or the other for the same set of jvm_binary classes!)
b
Right, the API hasnt changed between 1.1 and 1.2, just implementation
e
Then the core dep should probably be a version range to reflect that and the jvm_binaries can just pin.
No excludes needed and reality reflected.
b
Ah ok, so the lower level of the tree says ">= 1.1" and the top jvm_binary says "==1.2"?
and that guarnatees the fatjar will never end up with 1.1 in it?
e
Yup. This lets the resolving algorithm in ivy / coursier do its thing and it'll just pick one value.
You might want the lower level to >= 1.1, <2 to be safe. That's not jvm syntax though. IIRC its something like
[1.1,2)
for inclusive lower bound, exclusive upper? Looking ....
Trying to find better docs, but that was the Ivy syntax too for ranges.
b
interesting, if i do the interval, that means all my top level jvm_binaries must specify the version. else its just gonna pick the latest one
i guess thats ok, i do want to be very explicit
e
Yup, that's how it will work. Ideally we'd have lockfile support for binaries. Pants v1 does not, but Pants v2 will be supporting lock files for all languages that support version ranges. We've started the python design work for this.
The best docs on the jvm range format I found are actually at Ivy: http://ant.apache.org/ivy/history/2.1.0/ivyfile/dependency.html
But that should be the same for Coursier.
b
Ok got it, thanks
e
Pants always supported version ranges for jvm but I think ~no one in the jvm world uses them. Everyone in the python world and ... most other worlds I know of does.