{"id":"69861d567955f830","repo":"spring-projects/spring-boot","slug":"invalid-docker-registry-configuration-either-t","errorCode":null,"errorMessage":"Invalid Docker {} registry configuration, either token or username/password must be provided","messagePattern":"Invalid Docker (.+?) registry configuration, either token or username/password must be provided","errorType":"validation","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java","lineNumber":171,"sourceCode":"\tprivate BuilderDockerConfiguration customizePublishAuthentication(BuilderDockerConfiguration dockerConfiguration) {\n\t\treturn dockerConfiguration\n\t\t\t.withPublishRegistryAuthentication(getRegistryAuthentication(\"publish\", this.publishRegistry,\n\t\t\t\t\tDockerRegistryAuthentication.configuration(DockerRegistryAuthentication.EMPTY_USER)));\n\t}\n\n\tprivate DockerRegistryAuthentication getRegistryAuthentication(String type, @Nullable DockerRegistrySpec registry,\n\t\t\tDockerRegistryAuthentication fallback) {\n\t\tif (registry == null || registry.hasEmptyAuth()) {\n\t\t\treturn fallback;\n\t\t}\n\t\tif (registry.hasTokenAuth() && !registry.hasUserAuth()) {\n\t\t\treturn DockerRegistryAuthentication.token(registry.getToken().get());\n\t\t}\n\t\tif (registry.hasUserAuth() && !registry.hasTokenAuth()) {\n\t\t\treturn DockerRegistryAuthentication.user(registry.getUsername().get(), registry.getPassword().get(),\n\t\t\t\t\tregistry.getUrl().getOrNull(), registry.getEmail().getOrNull());\n\t\t}\n\t\tthrow new GradleException(\"Invalid Docker \" + type\n\t\t\t\t+ \" registry configuration, either token or username/password must be provided\");\n\t}\n\n\t/**\n\t * Encapsulates Docker registry authentication configuration options.\n\t */\n\tpublic abstract static class DockerRegistrySpec {\n\n\t\t/**\n\t\t * Returns the username to use when authenticating to the Docker registry.\n\t\t * @return the registry username\n\t\t */\n\t\t@Input\n\t\t@Optional\n\t\tpublic abstract Property<String> getUsername();\n\n\t\t/**\n\t\t * Returns the password to use when authenticating to the Docker registry.","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/DockerSpec.java#L153-L189","documentation":"Thrown by DockerSpec.getRegistryAuthentication() when a builder or publish registry has some auth fields set but neither a complete username/password pair (both username AND password) nor a token alone. The type ('builder' or 'publish') is interpolated into the message. It is a GradleException raised during asDockerConfiguration().","triggerScenarios":"builderRegistry/publishRegistry has hasEmptyAuth()==false and (hasTokenAuth()==hasUserAuth() (both true: token mixed with partial creds) or both false: e.g. username without password, or only url/email set) — line 171 throws.","commonSituations":"Setting username but forgetting password (or vice versa); providing a token and also a username; setting only url/email; credentials supplied via environment that partially populated the properties.","solutions":["For user auth, always set both username and password: builderRegistry { username='...'; password='...' }.","For token auth, set only token and nothing else: builderRegistry { token='...' }.","Remove any partial credentials (e.g., a stray url or email) when using token auth.","Inject credentials from environment/secret managers so both fields are populated atomically."],"exampleFix":"// before: username only -> throws\nbootBuildImage {\n    docker {\n        publishRegistry {\n            username = System.getenv('REG_USER')\n            // password missing\n        }\n    }\n}\n// after: complete credentials\nbootBuildImage {\n    docker {\n        publishRegistry {\n            username = System.getenv('REG_USER')\n            password = System.getenv('REG_PASS')\n            url = 'https://registry.example.com'\n        }\n    }\n}\n","handlingStrategy":"validation","validationCode":"fun validateRegistry(user: String?, pass: String?, token: String?) {\n    val hasUser = !user.isNullOrBlank() && !pass.isNullOrBlank()\n    val hasToken = !token.isNullOrBlank()\n    check(hasUser xor hasToken) {\n        \"Provide either token, or username+password (not both, not partial)\"\n    }\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inject registry credentials from a secret manager/env so username and password are set together.","When using token auth, leave username/password/url/email unset.","Validate registry configuration in a helper before bootBuildImage runs."],"tags":["gradle","boot-build-image","docker","registry","authentication","validation"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}