apple/pkl · error · InvalidUserDataException

No source modules specified.

Error message

No source modules specified.

What it means

ModulesTask (base for module-consuming Pkl Gradle tasks) requires at least one source module via the cliBaseOptions sourceModules property. When none are configured, runTask throws InvalidUserDataException with "No source modules specified." instead of invoking the Pkl CLI with an empty module list.

Source

Thrown at pkl-gradle/src/main/java/org/pkl/gradle/task/ModulesTask.java:137

  private Pair<List<File>, List<URI>> splitFilesAndUris(List<Object> modules) {
    var files = new ArrayList<File>();
    var uris = new ArrayList<URI>();
    for (var m : modules) {
      var parsed = PluginUtils.parseModuleNotation(m);
      if (parsed instanceof File file) {
        files.add(file);
      } else if (parsed instanceof URI uri) {
        uris.add(uri);
      }
    }
    return Pair.of(files, uris);
  }

  @TaskAction
  @Override
  public void runTask() {
    if (getCliBaseOptions().getNormalizedSourceModules().isEmpty()) {
      throw new InvalidUserDataException("No source modules specified.");
    }
    withFallbackTruffleRuntime(this::doRunTask);
  }

  @Internal
  @Override
  // See BasePklTask.getCliBaseOptions() for why caching is intentionally omitted.
  protected CliBaseOptions getCliBaseOptions() {
    return new CliBaseOptions(
        getSourceModulesAsUris(),
        patternsFromStrings(getAllowedModules().get()),
        patternsFromStrings(getAllowedResources().get()),
        getEnvironmentVariables().get(),
        getExternalProperties().get(),
        parseModulePath(),
        getWorkingDir().get().getAsFile().toPath(),
        mapAndGetOrNull(getEvalRootDirPath(), Paths::get),
        mapAndGetOrNull(getSettingsModule(), PluginUtils::parseModuleNotationToUri),

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Configure sourceModules on the task/extension, e.g. `sourceModules = listOf("dir/pkl.yaml", "...")` in the pkl block or task config.
  2. Point it at project files like pkl.yaml or .pkl module paths that exist.
  3. Check you configured the correct task/subproject that is actually failing.
  4. If no modules are intended, skip or disable the task (onlyIf / -x) instead of running it empty.

Example fix

// before
pkl { }
// after
pkl { sourceModules = listOf("pkl.yaml", "gen/pkl.yaml") }
Defensive patterns

Strategy: validation

Validate before calling

val modules = pklExtension.sourceModules.orEmpty()
require(modules.isNotEmpty()) { "Configure pkl.sourceModules before running ${tasks.withType<ModulesTask>().map { it.name }}" }

Type guard

fun ModulesTask.hasModules() = cliBaseOptions.normalizedSourceModules.isNotEmpty()

Try / catch

try { runTask() } catch (InvalidUserDataException e) { if (e.message == "No source modules specified.") logger.error("Add sourceModules to the pkl block"); throw e }

Prevention

When it happens

Trigger: Running a pkl ModulesTask (e.g. pkl test/eval/analyze style tasks) with `sourceModules` left empty in the task or extension configuration, or configuring it only in a different subproject.

Common situations: Forgetting to set sourceModules in build.gradle.kts; specifying modules under the wrong extension/task name; applying the plugin but never wiring the module paths; CI running the task before configuration is committed.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/a7c360a120875d19. Report an issue: GitHub.