moditect / layrry

A Runner and API for Layered Java Applications
Apache License 2.0
328 stars 33 forks source link

Adopt MIMA #217

Open cstamas opened 1 year ago

cstamas commented 1 year ago

I'd like to propose for this library to adopt MIMA and delegate "maven like" behavior to it. Current landscape of libraries and apps using Aether/Resolver (without Maven but "as in Maven") is very rough, and almost all the apps retry to do the same thing: mimic Maven, and usually they do it wrongly. MIMA offers solution to this.

https://github.com/maveniverse/mima/tree/main

MIMA is Java 8 library, makes use of latest Resolver versions and makes available all the latest features of it (remote repository filtering, local repository locking, new transport that cuts request count in half and many more).

Basic usage in short: make MIMA context module compile time dependency and use it like this:

        ContextOverrides overrides = ... build it using ContextOverrides.Builder
        try (Context context = Runtimes.INSTANCE.getRuntime().create(overrides)) {
          // use resolver: context carries resolverSystem, resolverSystemSession, remoteRepositories
        }

To make it work, add any MIMA runtime as runtime-only dependencies you need (you don't need them compile time).

There are 3 runtimes:

Naturally, you only need one "standalone-*" runtime, no need for both, while "embedded-maven" may be always present, as it does not stir any water (does not have any transitive dependencies and "activates" itself ONLY when inside Maven).

As Resolver (not MIMA) uses SLF4J for logging, you also need to provide a back-end for it at runtime (at least noop, as you still have access to listeners).

By using that pattern above, your code is transportable between all use cases and is simply oblivious where it runs: it will run transparently inside or outside of Maven.