Fork me on GitHub
#polylith
<
2021-10-07
>
seancorfield04:10:09

A heads up for folks using either depstar or tools.build with Polylith for building library JAR files: external deps from bricks will not show up in the generated pom.xml that ends up in the JAR file, only the deps from the project itself. I'm working on some tools.build stuff for Polylith so I'll have a better story for this soon... how many folks are building deployable libraries from Polylith projects, as opposed to application uberjars?

imre06:10:13

We aren't yet but once we finish migration we will need to

seancorfield06:10:31

Hopefully, I'll have a nice, generic solution by then 🙂

1
👏 3
🙏 2
imre06:10:48

Thank you for spending time on this!

seancorfield21:10:41

io.github.seancorfield/build-clj {:git/tag "v0.5.1" :git/sha "dc121d6"} addresses this by adding a :transitive true option to the jar task.

🙌 1
1
metal 2
kendall.buchanan22:10:13

@U04V70XH6 We’re deploying a library to S3 from Polylith using tools.build and slipset/deps-deploy. The only irritating thing so far has been that we’ve had to add our component dependency list to build.clj (`:src-dirs`) rather than the deps.edn located in the project directory.

kendall.buchanan22:10:22

(That could be ignorance on my part, though.)

seancorfield22:10:35

@U0HJA5ZQT If you use my build-clj wrapper for tools.build, you will have a simpler build.clj file and you can just pass :transitive true to the jar task (in build-clj).

seancorfield22:10:55

How are you building your pom.xml for the library?

seancorfield22:10:19

That's something else tools.build gets "wrong" by default for Polylith-based libraries.

kendall.buchanan22:10:11

@U04V70XH6

(defn jar [_]
  (println "Writing pom.xml")
  (b/write-pom {:class-dir class-dir
                :lib       lib
                :version   version
                :basis     basis
                :src-dirs  src-dirs})
  (println "Copying src dirs")
  (b/copy-dir {:src-dirs   src-dirs
               :target-dir class-dir})
  (println "Creating the jar")
  (b/jar {:class-dir class-dir
          :jar-file  jar-file})
  (record-version))

seancorfield22:10:10

How are you computing that basis? Do your libraries have external dependencies declared in the components's deps.edn files?

seancorfield22:10:47

The issue I raised is that by default the pom.xml generated that way will not have the top-level library dependencies from the components -- only the top-level library dependencies from the projects... But you should not need to specify library dependencies in projects's deps.edn if the components's deps.edn files already contain those (unless you are deliberately overriding them with different versions).

seancorfield22:10:57

And you're having to maintain that list of src-dirs yourself, right? My wrapper with the :transitive true option takes care of that automatically for you: it figures out the sources to include, based on the dependencies in the projects's deps.edn file.

kendall.buchanan22:10:01

Mmm, gotcha. Yeah, I’m including them in the project deps.

seancorfield22:10:25

Right, so you're duplicating a bunch of stuff and having to maintain that manually. You don't need to.

seancorfield22:10:03

For us, that's all automatic now.

kendall.buchanan22:10:51

Okay, I gotcha. Cool! Yeah, I hadn’t looked at that in a bit, and you’re right—I must have duplicated it to include the deps.

kendall.buchanan22:10:36

But will that resolve this?

kendall.buchanan22:10:41

(def src-dirs ["../../components/utils-cast/src"
               "../../components/bahtml/src"
               "../../components/string/src"
               "../../components/beta/src"
               "../../components/beta/resources"])

kendall.buchanan22:10:01

I’m actually confused by tools.build’s use of src-dirs: it appears to only include one in the POM, but needs the rest for the JAR. I’d prefer I not even need these references, even in the project’s deps.edn.

seancorfield22:10:02

For write-pom, you should just use the projects source dir (if any).

seancorfield22:10:14

But the basis for write-pom needs the top-level transitive deps from the components (in addition to the project) -- but you shouldn't need to duplicate any library deps and they should be in the components, if the components rely on a library (other components do not belong in components deps.edn files, just libraries).

seancorfield22:10:20

If you use build-clj, your entire jar task would become (bb/jar {:lib lib :version version :transitive true}) followed by your call to (record-versions)

seancorfield22:10:19

(that's not a Polylith project but :transitive true would be the only difference)

seancorfield22:10:24

Here's Polylith's build.clj (on the shell branch): https://github.com/polyfy/polylith/blob/shell/build.clj#L107 -- showing how it builds libraries.

seancorfield22:10:36

(it only copies the pom.xml out because it wants to delete the classes folder so things are cleaned up during the build -- to match the legacy deployer behavior)

kendall.buchanan16:10:47

@U04V70XH6 That is all super helpful. I’m looking forward to more of the community adopting tools.build—the docs are so slim!