Maven and Gradle, at their cores, basically provide build “lifecycle” management, dependency management and a plugin system for plugins to inject their functionality.
Trying to think how, with Maven installed, one would give someone a jar or some such and instructions so they could compile and run the program.
What do you mean here? That doesn’t make much sense, because if you gave someone a jar, then the assumption is that this jar is executable (i.e. has a manifest entry of the main class to run) and already contains the compiled classes and resources needed. So, they’d merely have to execute
java -jar the.jar given a Java runtime environment.
There are, of course, plugins for Maven and Gradle that provide you a very easy way to generate a single executable jar (including all their transitive dependencies).
Google for “Maven Shadow plugin” or “Gradle shade plugin”.
This will give you an executable jar file (if you specified the proper declarations of course, such as which is the main class to run its main method).
It’s the same story with NPM. npm gives you dependency management and the ability to run scripts.
And if you end here, you get the same out of NPM as you get with Maven and Gradle: With npm it’s a bunch of files for which you need an execution environment to run them.
Same goes for Maven/Gradle: You need a Java runtime environment to run those and likewise the executable jar they can produce of your application.
If you want to take it a step further and not rely on the end user having to have an execution environment (like Node/Deno or a JRE), then you need to bundle that as well.
For Maven/Gradle the story is a bit more difficult, since you have things like classpath (pre-Java9) vs. modulepath. Basically, from here on it doesn’t matter anymore whether you use Maven/Gradle or not: You just need a way to turn an executable jar together with its runtime environment (JRE) into a native OS executable.