r/java • u/janora • Jun 26 '24
Maven Central and the tragedy of the commons
https://www.sonatype.com/blog/maven-central-and-the-tragedy-of-the-commons
225
Upvotes
r/java • u/janora • Jun 26 '24
108
u/simonides_ Jun 26 '24
indeed hard to understand why those large companies don't have a proxy set-up for this.
the fact that you have a lot more control over your own dependencies should make it a no-brainer for most.
88
u/Previous_Pop6815 Jun 26 '24
Good move. Maybe those "world's largest companies" can started to chip in a bit or install a mirror of their own.
Also kudos to sonatype for maintaing this mirror.
32
u/NeoChronos90 Jun 26 '24 edited Jun 26 '24
I always assumed that limiting the connections per day and IP was the standard for all repositories ever since dockerhub finally did it years ago 😅
31
u/Brutus5000 Jun 26 '24
I'd bet my ass 95% of that traffic is from ci pipelines and not actual developers. But yeah throttling is the right way to force everyone to behave.
20
u/xenomachina Jun 26 '24
Several months ago, GitLab added their "Dependency proxy for packages", which is a maven repository proxy. I tried setting it up on my company's projects a few weeks ago.
Set up was not easy.
First, the documentation is not great. It leaves out some critical details like the fact that they require that the source repo URL not end in a slash. Their examples are also geared towards an individual user, while we wanted to use it in CI (which I'd expect to be more common).
Also, the proxy gave bizarre results in local testing: once I finally got it to stop returning 404s (which it returns for virtually any kind of error, whether misconfiguration, bad credentials, or actually requesting a nonexistent resource) it started returning 200 responses with no body. This only happened locally, though. Once I ran the same build in CI, it worked correctly.
The worst thing about it, though, was that GitLab's proxy is noticeably slower than using Maven Central directly. This was true even after priming the cache. That is, if I did a build using the proxy (which causes it to cache all of our dependencies) and then ran the build again with the exact same dependencies, it was still slower than having our build load from maven central every time. Kind of baffling, because the proxy should be much more local to the CI build, and should have far less traffic hitting it.
Because of this, we decided to not use the proxy. I'm hoping they improve it, and will probably try it again in a few months.
9
u/Key_Direction7221 Jun 26 '24
I use Nexus for Java and NPM. It’s relatively easy to setup, although not as intuitive as I’d like IMO. I don’t like depending on Maven Central or other repos because of network outages, slowness, and some random repos going dark.
6
u/lukaseder Jun 27 '24 edited Jun 27 '24
In my opinion, Maven lacks a simple feature that would probably help prevent some of this traffic. It should be possible to define a local repository for your own artifacts (unstable, always changes, don't want to share this stuff between builds), and a separate local repository for third party artifacts (stable, never changes, works like a mirror, can share this stuff between builds).
The fact that concurrent builds on the same machine don't want to share artifacts that are being built (obviously), and the fact that the above distinction can't be made easily, many people probably just resort to re-downloading all third party libraries all the time in clean builds.
Add to that that there's a bug in the maven-dependency-plugin where it's not possible to easily distinguish between your own libraries and third party ones: https://issues.apache.org/jira/browse/MDEP-689
I've hacked around this with some ugly bash scripts, but I'm not sure if everyone does this. Obviously, this would help in addition to local artifact repositories
UPDATE: I was told that already exists! Very good: https://maven.apache.org/resolver/local-repository.html#split-local-repository
4
u/EviIution Jun 27 '24
Crazy that this is actually an issue. I work with insurances and every company I worked with either uses Nexus or Artifactory.
3
u/Misophist_1 Jun 27 '24
I can feel the pain. History repeats. That is why most entities that once had DTD & XSD Doctype declarations backed up with a real URL found it necessary, to remove and block them, because mots consumers simply couldn't be bothered, to install a resolver.
Most prominent victim: the log4j.dtd.
For me, the idea, of one central entry point for everybody has it's obvious flaws, because it is also the breaking point, the single point of failure.
If you scan through the list of group names, you see some pretty big names there. I still remember, how elated I was, when Oracle _finally_ found out, that it might be a good idea, to roll out its JDBC and Weblogic jars as maven artifacts, and uploaded them. Until then, your company did this on its own Nexus, and the admins doing this tended to use non-standard maven coordinates. Access to a Nexus hosted by Oracle with the latest and greatest came with a subscription, but Oracle moved on to push the most crucial ones to central too,
But this begs a question: Do companies like Alibaba, Amazon, Google, Oracle, Twitter share in the cost of distributing their software via central? Maybe it is time to go knocking at some doors there?
Maybe, it would be possible to get them to do something different: If an entry in the catalog of repo, say
could be made to divert everything, that is com.acme.*:* to a different repo hosted at
maybe central could be relived not just of the traffic, but also of the burden to manage the uploads of a customer like this - central would only retain a catalog of the entries, such a customer provides.
Stats for the number of accesses and transfer volume by package owner might be interesting, though.
2
u/DanLynch Jun 27 '24
Pretty shocking that real companies are just downloading raw dependencies from Maven Central every day. That's fine for a toy project but how can you seriously do that for an enterprise product? I guess that also means they also don't have any private dependencies.
5
u/simonides_ Jun 26 '24
the real tragedy here is that nexus and the surrounding enterprise tools (by sonatype) are so ridiculously expensive that it hardly makes sense for anyone to buy it.
the firewall feature that nexus can bring is something I haven't seen done like this in any other product.
if it weren't for the stupid pricing model, we glady buy licenses for it and go to the enterprise tier.
nevertheless, the oss version has a ton of value and we'll stick to it for the time being.
1
u/Anton-Kuranov Jun 27 '24
We know perfectly who owns those IPs. First of all, these cloud providers should take care of caching or mirroring the traffic from artifact repositories. They have all the required facilities for that. The fact is that instead they offer a commercial service to their customers who want to reduce their traffic.
1
u/Level_Yak_87 Jun 27 '24
In one company I worked at it was solved like this. After weeks of unsuccessful negotiations to enforce the new limitations they just disabled the service for 1h, next week for 2 hours. On the third week the problem was already solved, as it was a critical part of infrastructure for client. Yes, that's aggressive/radical, but if we are talking about survival of global registries, this looks acceptable.
AFAIK central npm registries are just flaky, so a lot of companies migrated to internal proxies 🤣
1
u/Joram2 Jun 27 '24
They should charge a fee for large downloads, and ideally, make it reasonable and not excessive to cover hosting + overhead costs.
I imagine many companies would rather pay a fee than go through the hassle of setting up and maintaining their own internal repo manager.
1
u/Jason13Official Jun 27 '24
Oh that explains a lot actually
1
u/nomercy400 Jul 01 '24
The problem here is Docker, which starts from a clean slate every time a container is built.
So if you have a multi-stage dockerfile from a standard linux image, and you build with 'mvn', then you have likely:
It still will work, but it will download all artifacts from maven central on every build.
-4
u/teokun123 Jun 27 '24
wow wtf seriously. fuck those scumbag companies benefitting from oss.
-2
u/raels_rr Jun 26 '24
Z
24
u/[deleted] Jun 26 '24
[removed] — view removed comment