gradle/gradle · error · InvalidUserDataException

Invalid model name '${name}': it must match the following re

Error message

Invalid model name '${name}': it must match the following regular expression: [a-z]([a-zA-Z0-9])+

What it means

Version catalog names in Gradle must match the pattern [a-z]([a-zA-Z0-9])+ : they must start with a lowercase letter followed by one or more letters or digits. DefaultVersionCatalogBuilderContainer.validateName enforces this whenever a catalog is created via dependencyResolutionManagement.versionCatalogs.create(name). The restriction exists because the name becomes the accessor for the generated type-safe catalog (e.g. myLibs.some.dependency), so it must be a valid identifier prefix.

Source

Thrown at platforms/software/dependency-management/src/main/java/org/gradle/internal/management/DefaultVersionCatalogBuilderContainer.java:64

    private final Supplier<DependencyResolutionServices> dependencyResolutionServices;
    private final ObjectFactory objects;
    private final UserCodeApplicationContext context;

    @Inject
    public DefaultVersionCatalogBuilderContainer(Instantiator instantiator,
                                                 CollectionCallbackActionDecorator callbackActionDecorator,
                                                 ObjectFactory objects,
                                                 UserCodeApplicationContext context,
                                                 Supplier<DependencyResolutionServices> dependencyResolutionServices) {
        super(VersionCatalogBuilder.class, instantiator, callbackActionDecorator);
        this.objects = objects;
        this.context = context;
        this.dependencyResolutionServices = dependencyResolutionServices;
    }

    private static void validateName(String name) {
        if (!VALID_EXTENSION_PATTERN.matcher(name).matches()) {
            throw new InvalidUserDataException("Invalid model name '" + name + "': it must match the following regular expression: " + VALID_EXTENSION_NAME);
        }
    }

    @Override
    public VersionCatalogBuilder create(String name, Action<? super VersionCatalogBuilder> configureAction) throws InvalidUserDataException {
        validateName(name);
        return super.create(name, model -> {
            UserCodeApplicationContext.Application current = context.current();
            DefaultVersionCatalogBuilder builder = (DefaultVersionCatalogBuilder) model;
            builder.withContext(current == null ? "Settings" : current.getSource().getDisplayName().getDisplayName(), () -> configureAction.execute(model));
        });
    }

    @Override
    protected VersionCatalogBuilder doCreate(String name) {
        return objects.newInstance(DefaultVersionCatalogBuilder.class, name, strings, versions, objects, dependencyResolutionServices);
    }

View on GitHub (pinned to 534f27719b)

Solutions

  1. Rename the catalog to match [a-z][a-zA-Z0-9]* — e.g. 'myLibs' instead of 'my-libs'
  2. Strip '-', '_', '.', spaces and leading digits when names come from user input or filenames
  3. If a plugin generates the name, upgrade it or pass a compliant name explicitly

Example fix

// before:
dependencyResolutionManagement {
    versionCatalogs {
        create('Platform-Libs') { from(files('gradle/libs.versions.toml')) }
    }
}
// after:
dependencyResolutionManagement {
    versionCatalogs {
        create('platformLibs') { from(files('gradle/libs.versions.toml')) }
    }
}
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidCatalogName(String name) {
    name != null && name ==~ /[a-z][a-zA-Z0-9]+/
}
// use before create:
assert isValidCatalogName(catalogName) : "catalog name '$catalogName' must match [a-z][a-zA-Z0-9]+"

Try / catch

try {
    dependencyResolutionManagement.versionCatalogs.create(name) { from(files('gradle/libs.versions.toml')) }
} catch (org.gradle.api.InvalidUserDataException e) {
    throw new GradleException("Catalog name '$name' is invalid: must match [a-z][a-zA-Z0-9]+", e)
}

Prevention

When it happens

Trigger: Calling dependencyManagement { versionCatalogs { create('My-Libs') { } } } or any create(name) where name contains '-', '_', '.', or whitespace, starts with an uppercase letter, or starts with a digit. Also hit when a platform plugin derives the catalog name from a filename or user input without sanitizing it.

Common situations: Naming catalogs after teams or platforms with hyphens ('platform-libs'), capitalizing the first letter, or passing dynamic/generated names that slip in invalid characters.

Related errors


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/ecb84d8c391cd037. Report an issue: GitHub.