- Authors: Ben Sherman
- Status: accepted
- Deciders: Ben Sherman, Paolo Di Tommaso
- Date: 2026-06-25
- Tags: cli, modularization, build, architecture
Move the CLI code into a new nf-cli-v1 module, leaving nextflow as a pure runtime that knows nothing about the CLI. The split untangles circular dependencies, speeds up builds, lets library consumers depend on the runtime without dragging in the CLI, and paves the way for a future CLI v2.
The nextflow module mixed two distinct concerns:
- The CLI: the
Launcherentry point, argument parsing (JCommander), and theCmd*command classes (CmdRun,CmdConfig,CmdLog, themodulesubcommands, etc.). - The runtime: the dataflow engine, session, executors, config model, SCM/asset management, and everything required to actually execute a workflow.
Bundling them together caused several problems:
- Circular dependencies: CLI code reached into the runtime and runtime code reached back into CLI concerns (e.g.
ConfigBuildercarried CLI-specific logic), making the dependency graph hard to reason about. - Slow builds: editing a CLI class forced a rebuild of the entire module, including the runtime.
- Unwanted coupling for consumers: library consumers -- Seqera Platform, plugins -- that only need the runtime were forced to depend on the whole CLI surface.
- No room for a CLI v2: a redesigned CLI could not be introduced cleanly while the existing CLI was fused to the runtime.
In addition, several plugins (nf-console, nf-k8s, nf-tower, nf-wave) contribute CLI commands, so naively moving the CLI out risked coupling those plugins to the new CLI module instead of to the runtime.
- Separation of concerns: the CLI should depend on the runtime, never the reverse.
- Faster, more incremental builds: changing CLI code should not rebuild the runtime.
- Runtime reusable as a library: consumers (Platform, plugins) can depend on
nextflowalone, without the CLI. - Break circular dependencies: produce a clean, acyclic module graph.
- Keep plugins decoupled from the CLI: plugins that add commands should depend on the runtime, not on
nf-cli-v1, wherever feasible. - Enable a future CLI v2: make it possible to add an alternative CLI implementation alongside v1.
- Preserve user-facing behavior: the Nextflow CLI should continue to behave the same way.
- Redesigning the CLI: this is a structural move only; CLI v2 is explicitly future work. The module is named
nf-cli-v1to leave that door open. - Removing the
nf-cli-v1→nf-k8sbuild-time dependency:K8sDriverLaunchernow lives innf-cli-v1and pulls innf-k8sat build time (see below). Loadingnf-k8son demand instead -- so the CLI need not depend on it at build time -- is left to CLI v2. - Changing the packaging/distribution format: the produced
nextflowbinary is unchanged from the user's perspective.
Extract the CLI into a new nf-cli-v1 module that depends on the nextflow runtime, and relocate the shared interfaces and adapter classes needed to keep the dependency graph acyclic and plugins decoupled from the CLI.
nf-cli-v1 ──► nextflow (runtime) ──► nf-commons, nf-httpfs, nf-lang
│
├──► nf-k8s (via CmdKubeRun) ──► nextflow
└──► nf-lineage (via CmdLineage) ──► nextflow
nf-cli-v1contains theLauncherentry point,CliOptions/HubAware, and allCmd*classes (including themodulesubcommands). Itsapplicationmain class isnextflow.cli.Launcher, and it produces the shadow jar that becomes thenextflowdistribution.nextflowcontains the runtime only -- no CLI entry point, noCmd*classes.settings.gradleregisters the newnf-cli-v1module.packing.gradlenow packs from:nf-cli-v1:shadowJarinstead of:nextflow:shadowJar; the producednextflow-<version>-one.jar/-distartifacts are unchanged in name and behavior.
Several deliberate moves were required so that the runtime never depends on the CLI:
-
ConfigBuilder→ConfigCmdAdapter: the CLI-specific portions ofConfigBuilderwere extracted into a newConfigCmdAdapterclass innf-cli-v1, leaving the core config builder in the runtime. This also yields a cleaner separation of concerns. -
Command interfaces → runtime:
AuthCommandandLaunchCommandinterfaces were moved into the runtime. This letsnf-towerimplement these commands while depending only on the runtime and not the CLI.nf-lineagewas similarly reworked to depend onnextflowand be required bynf-cli-v1, removing the need for theLinCommandinterface (the lineage command usesLinCommandImpldirectly).One consequence is that prior versions of
nf-towerwill not loadauth/launchcorrectly if they are used with a newer Nextflow version. This is acceptable because there is no reason to do this -- core plugins are rebuilt at release. -
PluginExecAware→ runtime:PluginExecAwareandPluginAbstractExecwere moved into the runtime module -- keeping theirnextflow.clipackage -- so that plugins can declare CLI commands without depending onnf-cli-v1. Only theexec()method signature was changed, to remove the dependency onnextflow.cli.Launcher.
nf-console, nf-k8s, nf-tower, and nf-wave add CLI commands. The goal was to keep them depending on the runtime rather than the CLI:
-
nf-consolestill depends on:nf-cli-v1. -
nf-k8scompiles againstnextflowonly and references no CLI classes. To get there,K8sDriverLauncher(which usesCmdRun) was moved out ofnf-k8sand intonf-cli-v1. As a result,nf-cli-v1now depends onnf-k8sat build-time. BecauseCmdKubeRunnow instantiatesK8sDriverLauncherdirectly (rather than resolving it through the plugin extension point),nf-k8sis bundled into the distribution fat jar and still shipped as a plugin, sonextflow.k8sbecomes a split package loaded by both the application and plugin classloaders. This is accepted as a consequence of preservingkuberun; the CLI v2 will not need to do this if it does not preserve thekuberuncommand, as it can simply loadnf-k8sat runtime when using thek8sexecutor.Because the bundled copy lands in the distribution's
META-INF/extensions.idx,nextflow.k8s.K8sConfigandK8sExecutorregister as system extensions on every run. On a k8s run the plugin copy also loads (whether pulled in explicitly viaplugins { id 'nf-k8s' }or auto-loaded byprocess.executor = 'k8s'), so the samek8sconfig scope is contributed from both class loaders.ConfigValidatornow ignores a collision when both contributions are the same class -- suppressing the split-package noise while still warning when two different classes claim one scope name. Config resolution is unaffected either way, andK8sDriverLauncherstays within a single class loader, so no cross-classloaderClassCastExceptionarises. For executors, pf4j enumerates classpath extensions before plugin extensions, so the plugin copy wins and version pinning holds.With
NXF_PLUGINS_DEFAULT=false,process.executor = 'k8s'still resolves from the bundled application-classloader copy, where previously it would not have loaded at all. This is benign but is a behavior change worth noting. -
nf-towerandnf-wavewere decoupled by moving the relevant command interfaces into the runtime; both now compile againstnextflowonly.
PluginExecAware keeps its nextflow.cli package (see above), so already-published plugins still load. Only its exec() method signature changed, to remove the dependency on the CLI. Because the package is preserved, an old implementer loads fine and fails only if someone actually invokes nextflow plugin <id>:<cmd> -- a NoSuchMethodError at invocation (old PluginAbstractExec trait subclasses carry a baked-in helper call with the previous descriptor) rather than a load-time NoClassDefFoundError that would take down every command. The failure is narrow and loud. Third-party plugins that implement it should update the method signature:
// before
int exec(Launcher launcher, String pluginId, String cmd, List<String> args)
// after
int exec(String pluginId, String cmd, List<String> args)As a result, PluginAbstractExec (the base class used by most plugin commands) no longer loads the Nextflow configuration the way it used to -- previously it ran ConfigBuilder over the launcher options and config files. It now creates the Session from a minimal config derived from environment variables only:
workDirfromNXF_WORK(defaultwork)cloudcachefromNXF_CLOUDCACHE_PATH(when set)
There are two plugin commands among the core plugins that are affected:
-
CacheCommand(nf-tower, thecache-backup/cache-restorecommands) -- adapted to readNXF_CLOUDCACHE_PATHfrom the environment directly. Thecloudcacheentry in the minimal config exists specifically for this purpose. Thecache-backupcommand is used by Seqera Platform to upload logs to the cloudcache on exit. -
WaveCmdEntry(nf-wave) -- not adapted. These commands construct aWaveClientfromsession.config.wave,session.config.fusion, andsession.config.tower, which the minimal config no longer populates. As a result they now honor only environment variables and defaults, not settings fromnextflow.config. These commands are used only for debugging, so they are not critical, but may warrant further review.
Plugin commands that need configuration should load it explicitly rather than relying on PluginAbstractExec. This change is acceptable because plugin commands are quite rare in practice.