Mix.exs conditional code : application or included as a dependency

Is this in any way possible? I’m looking for the least hacky solution possible.

Project runs standalone (for hacking/testing) or as a dependency where you would get a shell on the running server and execute a processing run.

It’s open-source but I’d rather not get bogged down in the rationalle - is this possible?

I did have a snippet Keyword.get(Mix.Project.config(), :app) but it’s not working when placed in the mix.exs file

case Keyword.get(Mix.Project.config(), :app) do
      :ex_bench -> dependent_application()
      _ -> application(Mix.env())

I mean, in fairness, it does say in the mix documentation :

Do not use Mix.Project.config/0 to find the runtime configuration. Use it only to configure aspects of your project (like compilation directories) and not your application runtime.

I don’t want to find the runtime configuration though, I just want to find out if the project is being compiled and run as a dependency or compiled and run as a standalone project and start the appropriate applications for each environment.

How is running standalone different from usage as dependency?

It starts up webserver, plug, prometheus, for metrics scraping - as a dependency it just communicates metrics via telemetry, I might even remove that requirement.

So what about explicitly using config to determine what to do instead of relying on mix internals, which shouldn‘t be used at runtime?

Are you sure these aren’t two distinct applications? One library and a “standalone” application that depends on the library?

Nah it’s for iterative testing - a developer convenience - running metrics endpoints etc, as a dependency it only assumes ExPrometheus will be available.

Take a look at the startup behaviour matrix - feedback welcome.

Is that for users of the library or you as the developer of the library?

I’m thinking both - run as a standalone app for plugin development, deploy as dependency when testing live services.