gradle/gradle · error · InvalidUserDataException
Publication name '${publicationName}' is not valid for publi
Error message
Publication name '${publicationName}' is not valid for publication. Must match regex [A-Za-z0-9_\-.]+. What it means
After project evaluation, the publishing plugin validates that every publication name matches [A-Za-z0-9_\-.]+, throwing InvalidUserDataException otherwise. Publication names are used to build task names (publish<Pub>PublicationTo<Repo>, generateMetadataFileFor<Pub>Publication) and metadata file paths, so they must stay identifier-safe.
Source
Thrown at platforms/software/publish/src/main/java/org/gradle/api/publish/plugins/PublishingPlugin.java:107
extension.getPublications().all(publication -> {
PublicationInternal<?> internalPublication = Cast.uncheckedNonnullCast(publication);
projectPublicationRegistry.registerPublication(projectIdentity, internalPublication);
});
validatePublishingModelWhenComplete(project, extension);
}
private void validatePublishingModelWhenComplete(Project project, PublishingExtension extension) {
project.afterEvaluate(projectAfterEvaluate -> {
for (ArtifactRepository repository : extension.getRepositories()) {
String repositoryName = repository.getName();
if (!repositoryName.matches(VALID_NAME_REGEX)) {
throw new InvalidUserDataException("Repository name '" + repositoryName + "' is not valid for publication. Must match regex " + VALID_NAME_REGEX + ".");
}
}
for (Publication publication : extension.getPublications()) {
String publicationName = publication.getName();
if (!publicationName.matches(VALID_NAME_REGEX)) {
throw new InvalidUserDataException("Publication name '" + publicationName + "' is not valid for publication. Must match regex " + VALID_NAME_REGEX + ".");
}
}
});
}
}
View on GitHub (pinned to 534f27719b)
Solutions
- Rename the publication using only letters, digits, underscore, hyphen, and dot: publications { maven(MavenPublication) { ... } } or a sanitized container name.
- If names are generated, sanitize them: publicationName.replaceAll(/[^A-Za-z0-9_\-.]/, '-').
- Print publishing.publications.names in a helper task to catch bad names early.
Example fix
// before
publishing {
publications {
'lib publication'(MavenPublication) {
from components.java
}
}
}
// after
publishing {
publications {
lib(MavenPublication) {
from components.java
}
}
} Defensive patterns
Strategy: validation
Validate before calling
// fail fast on illegal publication names
publishing.publications.all { pub ->
if (!(pub.name ==~ /[A-Za-z0-9_\-.]+/)) {
throw new GradleException("Publication name '${pub.name}' will fail validation; use [A-Za-z0-9_\-.] only")
}
} Prevention
- Choose short stable identifiers for publications ('maven', 'mavenJava').
- Sanitize dynamically generated publication names with replaceAll(/[^A-Za-z0-9_\-.]/, '-').
- Remember the publication name becomes part of task names like generatePomFileFor<Name>Publication.
When it happens
Trigger: Creating a publication with an illegal name: publishing { publications { 'my pub'(MavenPublication) { ... } } }, or registering publications dynamically from strings containing spaces, slashes, or CI-generated labels.
Common situations: Dynamic publication creation per subproject/component where names come from project or environment values; copy-pasted publication blocks with descriptive labels; migrations that reuse display names as identifiers.
Related errors
- Repository name '${repositoryName}' is not valid for publica
- Invalid feature name '{}'. Must match [a-zA-Z0-9]+
- Invalid model name '${name}': it must match the following re
- Invalid ivy extra info element name: '%s'
- Cannot add an extra info element with null element name
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/e25302817ef8064b.
Report an issue: GitHub.