{"id":"b24ccb1544026874","repo":"spring-projects/spring-boot","slug":"invalid-value-for-option-environment-expected","errorCode":null,"errorMessage":"Invalid value for option '--environment'. Expected 'NAME=VALUE' but got '{}'.","messagePattern":"Invalid value for option '--environment'\\. Expected 'NAME=VALUE' but got '(.+?)'\\.","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java","lineNumber":119,"sourceCode":"\t\tgetCleanCache().convention(false);\n\t\tgetVerboseLogging().convention(false);\n\t\tgetPublish().convention(false);\n\t\tthis.buildWorkspace = getProject().getObjects().newInstance(LocalCacheSpec.class);\n\t\tthis.buildCache = getProject().getObjects().newInstance(CacheSpec.class);\n\t\tthis.launchCache = getProject().getObjects().newInstance(LocalCacheSpec.class);\n\t\tthis.docker = getProject().getObjects().newInstance(DockerSpec.class);\n\t\tthis.pullPolicy = getProject().getObjects().property(PullPolicy.class);\n\t\tgetSecurityOptions().convention((Iterable<? extends String>) null);\n\t\tgetEffectiveEnvironment().putAll(getEnvironment());\n\t\tgetEffectiveEnvironment().putAll(getEnvironmentFromCommandLine().map(BootBuildImage::asMap));\n\t}\n\n\tprivate static Map<String, String> asMap(List<String> variables) {\n\t\tMap<String, String> environment = new LinkedHashMap<>();\n\t\tfor (String variable : variables) {\n\t\t\tint index = variable.indexOf('=');\n\t\t\tif (index <= 0) {\n\t\t\t\tthrow new InvalidUserDataException(\n\t\t\t\t\t\t\"Invalid value for option '--environment'. Expected 'NAME=VALUE' but got '\" + variable + \"'.\");\n\t\t\t}\n\t\t\tString name = variable.substring(0, index);\n\t\t\tString value = variable.substring(index + 1);\n\t\t\tenvironment.put(name, value);\n\t\t}\n\t\treturn environment;\n\t}\n\n\t/**\n\t * Returns the property for the archive file from which the image will be built.\n\t * @return the archive file property\n\t */\n\t@InputFile\n\t@PathSensitive(PathSensitivity.RELATIVE)\n\tpublic abstract RegularFileProperty getArchiveFile();\n\n\t/**","sourceCodeStart":101,"sourceCodeEnd":137,"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/BootBuildImage.java#L101-L137","documentation":"Thrown by BootBuildImage.asMap() while parsing values passed via the --environment command-line option (getEnvironmentFromCommandLine). Each value must be NAME=VALUE; if there is no '=' or it appears at index 0 (empty name), an InvalidUserDataException is raised. The check is indexOf('=') <= 0.","triggerScenarios":"Invoking bootBuildImage (or bootBuildImagePoll) with --environment FOO or --environment =VALUE (or any token where '=' is missing or at position 0) hits the failing branch at line 119.","commonSituations":"Typos in CLI args (missing '='), copy-paste of 'FOO BAR', shell-quoting that strips '=', passing a bare variable name, or scripts that build the flag dynamically without the separator.","solutions":["Provide the value as NAME=VALUE, e.g. ./gradlew bootBuildImage --environment=BP_JVM_VERSION=21.","If the value may be empty, still include the '=': --environment=BP_DEBUG_ENABLED=.","Quote the whole token in shell to prevent splitting: --environment=\"BP_DEBUG_ENABLED=true\".","For multiple variables, repeat the flag once per NAME=VALUE pair."],"exampleFix":"// before:\n//   ./gradlew bootBuildImage --environment=BP_JVM_VERSION 21\n// after:\n//   ./gradlew bootBuildImage --environment=BP_JVM_VERSION=21\n","handlingStrategy":"validation","validationCode":"fun isValidEnvToken(token: String): Boolean {\n    val idx = token.indexOf('=')\n    return idx > 0 && token.substring(0, idx).isNotEmpty()\n}\n\nval tokens = listOf(\"BP_JVM_VERSION=21\")\nrequire(tokens.all { isValidEnvToken(it) }) {\n    \"All --environment values must be NAME=VALUE\"\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --environment=NAME=VALUE (never omit the '=' separator).","Quote the whole token in shell to prevent word-splitting.","Generate the flag programmatically with a helper that enforces the NAME=VALUE shape."],"tags":["gradle","boot-build-image","cli","validation","environment"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}