{"record":{"id":"e25302817ef8064b","repo":"gradle/gradle","slug":"publication-name-publicationname-is-not-valid","errorCode":null,"errorMessage":"Publication name '${publicationName}' is not valid for publication. Must match regex [A-Za-z0-9_\\-.]+.","messagePattern":"Publication name '(.+?)' is not valid for publication\\. Must match regex \\[A-Za-z0-9_\\\\-\\.\\]\\+\\.","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"platforms/software/publish/src/main/java/org/gradle/api/publish/plugins/PublishingPlugin.java","lineNumber":107,"sourceCode":"        extension.getPublications().all(publication -> {\n            PublicationInternal<?> internalPublication = Cast.uncheckedNonnullCast(publication);\n            projectPublicationRegistry.registerPublication(projectIdentity, internalPublication);\n        });\n        validatePublishingModelWhenComplete(project, extension);\n    }\n\n    private void validatePublishingModelWhenComplete(Project project, PublishingExtension extension) {\n        project.afterEvaluate(projectAfterEvaluate -> {\n            for (ArtifactRepository repository : extension.getRepositories()) {\n                String repositoryName = repository.getName();\n                if (!repositoryName.matches(VALID_NAME_REGEX)) {\n                    throw new InvalidUserDataException(\"Repository name '\" + repositoryName + \"' is not valid for publication. Must match regex \" + VALID_NAME_REGEX + \".\");\n                }\n            }\n            for (Publication publication : extension.getPublications()) {\n                String publicationName = publication.getName();\n                if (!publicationName.matches(VALID_NAME_REGEX)) {\n                    throw new InvalidUserDataException(\"Publication name '\" + publicationName + \"' is not valid for publication. Must match regex \" + VALID_NAME_REGEX + \".\");\n                }\n            }\n        });\n    }\n\n}\n","sourceCodeStart":89,"sourceCodeEnd":114,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/software/publish/src/main/java/org/gradle/api/publish/plugins/PublishingPlugin.java#L89-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublishing {\n    publications {\n        'lib publication'(MavenPublication) {\n            from components.java\n        }\n    }\n}\n\n// after\npublishing {\n    publications {\n        lib(MavenPublication) {\n            from components.java\n        }\n    }\n}","handlingStrategy":"validation","validationCode":"// fail fast on illegal publication names\npublishing.publications.all { pub ->\n    if (!(pub.name ==~ /[A-Za-z0-9_\\-.]+/)) {\n        throw new GradleException(\"Publication name '${pub.name}' will fail validation; use [A-Za-z0-9_\\-.] only\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["gradle","publishing","publications","naming","validation"],"backgroundTag":"invalid-name-configuration","analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}