r/Clojure • • Jan 05 '18

Git Deps for Clojure

https://clojure.org/news/2018/01/05/git-deps
106 Upvotes

99 comments sorted by

View all comments

15

u/yogthos Jan 05 '18

I really hope this does not become standard practice for packaging Clojure dependencies. While it's good that dependencies are checked out using a specific revision, there are still plenty of things that can go wrong here.

Git repos are mutable, so you can do things like rebasing, squashing commits, and so on. The repo itself could just get deleted or moved as well. Git is not a dependency management system, and it should not be used as such in my opinion. The only case I can see this being used for is private repos that you control.

35

u/richhickey Jan 05 '18

Well, I certainly hope you'll reconsider that. If we consider maven 'a dependency management system', it's full of conventions and human dependencies. There's no inherent connection between an artifact and the originating source (how do you know what you're running?), name stability is completely dependent on the hosts (maven central, clojars) disallowing updates. One could for instance load completely different 1.2.3 versions to each. Content-based addressing and git parentage has none of those problems. If repos go away they can be restored by anyone with a clone (which will be every consumer in this tool's case). Many companies rehost any maven libs they use to ensure access and could do so similarly here (why? because stuff happens and no host is perfect). Neither system is secure, but git deps require substantially less convention and human correctness.

Let's not fearmonger. I think this is a superior system with substantial benefits. You may not see them yet, but they are there. Artifacts are a disconnect with authorship/source. Releases are friction. People 'mvn install' all kinds of crap to work around difficulties e.g. developing sibling libs in parallel or trying a speculative change when working with tools that only consume installed artifacts. And don't get me started on semantic versioning and 'resolution' based on strings :)

The bottom line is - software will be better when more people try interim versions and changes are more fine-grained, things that rarely happen with artifacts. We've been using this internally and it's game-changing. I certainly will be 'shipping' some of my work this way moving forward.

9

u/yogthos Jan 05 '18

I agree with the benefits of the approach, and as I already noted I don't see any problems with this being used internally where you do have control over the process. I'm also not arguing that Maven is the perfect system, and you're absolutely right that it can be abused as well. However, the way it's used in practice has proven to be pretty robust. Meanwhile, I've had quite poor experience with looser systems like NPM and Go package manager that incidentally uses Git.

If this is going to be the standard way Clojure libraries are packaged, it would be good to at least have some guidelines for people managing repositories to ensure stability of the ecosystem going forward.

14

u/richhickey Jan 05 '18

I think the Clojure community can do a good job of this - we'll see :)

9

u/yogthos Jan 05 '18

We have with most things so far in my experience, so I'm willing to give this a shot and see how it goes. :)

→ More replies (14)

6

u/swlkrV2 Jan 06 '18

Oh my gosh I didn’t even think about forking everything my projects depend on then I can be in control when upstream changes. This is freaking genius.

5

u/yogthos Jan 06 '18

If you look at lein deps :tree in a non-trivial project, you'll see 100s of dependencies there. Personally, I wouldn't want to be managing copies of all the projects that my project happens to depend on.

→ More replies (5)

5

u/billrobertson42 Jan 07 '18

Let's not fearmonger.

I think they're valid concerns, not fear mongering.

4

u/halgari Jan 05 '18

Not sure I understand? Are you saying its possible to change the code under a given rev of a given git repo? These deps are url + rev, which seems to be immutable enough. And even if it is possible to change something (delete a repo and recreate it somehow with a old sha) seems like the best way to avoid those problems is to "don't do that".

9

u/yogthos Jan 05 '18

I can entirely change a given rev in git using push -f, there's absolutely zero guarantees here. Relying on "don't do that" for dependency management seems frankly absurd to me. Maven exists for a reason, and it provides a stable and robust way to manage dependencies. Git is not a dependency management system, and doesn't provide any of the guarantees Maven repos do. I can't wait for the Clojure edition of the leftpad NPM fiasco.

5

u/royalaid Jan 05 '18

Wouldn't the SHA attached to the revision change at the point? It would make that resource unavailable but it wouldn't allow injection

4

u/yogthos Jan 05 '18

That still breaks your build. The concept of artifacts being immutable once published is core for any sane dependency management system in my opinion.

→ More replies (3)

4

u/yogthos Jan 05 '18

This also affects the workflow of people managing repositories. If people start consuming my repo via git, and I rebase I can break their builds, at which point I'm going to have to deal with issues from the users.

This approach also makes it more difficult to tell library versions, e5becca is not exactly descriptive or human readable. I'd much rather see something like org.clojure/clojure "1.8.0" in my dependencies as opposed to "https://github.com/clojure/clojure" :rev "e5becca".

16

u/richhickey Jan 05 '18

You can use the tag name "1.8.0" in the git :rev if you trust that we don't move them (and of course we don't). There are many trivial ways to avoid the problems you fear about unstable source repos, given shas, S3 and file copy etc. If freds-chaotic-repo is too unstable for you as a source then a) get fred to deliver artifacts, or b) use another lib. But presuming the worst of the world is a recipe for nothing good.

8

u/yogthos Jan 05 '18

As you noted in the other comment, many of the issues I highlighted are technically possible with Maven as well. So, perhaps it is a question of setting up good conventions from the start. Since this process is already used at Cognitect internally, perhaps you can publish some community guidelines based on your experience.

My concerns are mostly rooted in my experience with existing solutions like git package management in Go. Perhaps, Clojure community will entirely avoid these problems, but it seems like now would be the time to talk about them and identify solutions and best practices.

7

u/drewr Jan 05 '18 edited Jan 05 '18

My issues with Go using git-based package management have been:

  • No ability to pin version (yes, there are community tools to fix it)

  • The package name is tied to the repo name and file paths. This one is no end of frustration. Like, some of our GitHub org is named poorly simply because it has to be that way with Go.

Clojure's approach doesn't have either of these issues. It reminds me more of Cargo's or Stack's approaches (both of which work great) than Go.

6

u/yogthos Jan 05 '18

I'm willing to be convinced this is workable. :) I do think some best practices up front would go a long way here though.

→ More replies (4)

4

u/sunng Jan 06 '18

Most modern deps manager, which support git or semver range, now use a lock file (npm, cargo) to store actual verson/commit that you are using. To update it, you run a special command like cargo update to update the lock file. For a library, you leave the lock file in gitignore while for app repo should put it in repo to make build stable.

As we already have git dep in deps, can we expect the semver range support and verson lock?

8

u/richhickey Jan 06 '18

No. As far as I can tell, such lock files are just a way to put the information about what you are using in two places instead of one and I don't see the point. We have discussed tools that will update deps to later revs, but I'm skeptical of auto-magic. There's nothing modern about it :) As for semver, also no. See the Spec-ulation talk linked at the bottom of the post.

4

u/alexdmiller Jan 06 '18

No. The actual commit (or tag) is in the deps.edn file. You change it by editing the file.

4

u/emidln Jan 06 '18

One of the interesting things for tools authors is that you could compose this into something akin to lein-ancient if you have that itch. Converging on a state (arrived by iterating through single step changes to deps.edn) where a defined predicate (that maybe invokes your test-suite) passes is on the table. I wouldn't ever really expect that to be part of the core library, but the design of deps.edn makes this (and other tooling) pretty reasonable to attain.

3

u/sunng Jan 06 '18

I see. Currently deps.edn is just like the lock file in npm.

2

u/[deleted] Jan 08 '18

Eh? A git sha is not mutable. There's much less systematic guarantee that a maven artifact will stay the same, all you've got to rely on is that you're using maven central/clojars. If you're using private maven repos (as most semi-large orgs will be) you're hosed.

3

u/yogthos Jan 08 '18

It's mutable in a sense that it can be deleted, as is the case with a whole repository. It's also true, as Rich Hickey noted in his reply, that the reason maven ecosystem works is largely because of the conventions around it.

As things currently stand though, maven repos have pretty good guarantees around preserving artifacts. There are no such guarantees or conventions around repos hosted on GitHub.

I think that if Clojure community embraces this approach, we need to start thinking about such conventions early on. I also think it would be good to have some archiving service for published artifacts. Something as simple as a github org with rules about preserving tags would do in my opinion.

2

u/[deleted] Jan 08 '18

I can delete stuff off maven if I submit a DMCA takedown etc etc. All of the possibilities you describe seem to me to be things that if a team are doing you shouldn't be consuming their code, maven, git or whatever.

→ More replies (27)
→ More replies (4)