{"record":{"id":"3a82a5baf9bf2bff","repo":"microsoft/aspire","slug":"java-application-resource-name-cannot-be-published-because-3a82a5","errorCode":null,"errorMessage":"Java application '{resource.Name}' cannot be published because there is no {defaultWrapperName} in '{appDirectory}'. Aspire builds the image with the project's own wrapper so the container uses the tool version the repository pins. Generate one with {JavaHostingExtensions.GenerateWrapperCommand(tool)}, or point at an existing wrapper with WithWrapperPath.","messagePattern":"Java application '(.+?)' cannot be published because there is no (.+?) in '(.+?)'\\. Aspire builds the image with the project's own wrapper so the container uses the tool version the repository pins\\. Generate one with (.+?), or point at an existing wrapper with WithWrapperPath\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs","lineNumber":1062,"sourceCode":"            {\n                throw new DistributedApplicationException(\n                    $\"Java application '{resource.Name}' cannot be published because its wrapper \" +\n                    $\"'{resolvedWrapperPath}' is outside the build context '{appDirectory}'. \" +\n                    \"Move the wrapper into the application directory, or set the build context to a \" +\n                    \"directory that contains both.\");\n            }\n\n            if (!File.Exists(resolvedWrapperPath))\n            {\n                if (isConfigured)\n                {\n                    throw new DistributedApplicationException(\n                        $\"Java application '{resource.Name}' cannot be published because the wrapper \" +\n                        $\"configured with WithWrapperPath was not found at '{resolvedWrapperPath}'.\");\n                }\n\n                var defaultWrapperName = JavaBuildToolResolver.GetDefaultWrapperName(tool, isWindows: false);\n                throw new DistributedApplicationException(\n                    $\"Java application '{resource.Name}' cannot be published because there is no \" +\n                    $\"{defaultWrapperName} in '{appDirectory}'. Aspire builds the image with the project's \" +\n                    $\"own wrapper so the container uses the tool version the repository pins. Generate one \" +\n                    $\"with {JavaHostingExtensions.GenerateWrapperCommand(tool)}, or point at an existing \" +\n                    \"wrapper with WithWrapperPath.\");\n            }\n\n            // The build stage is Linux, so a Windows batch wrapper cannot run there even though it is\n            // the right choice on the developer's machine. Maven and Gradle ship the POSIX script\n            // alongside the batch one under the same base name, so prefer that sibling and only fail\n            // when it is genuinely absent.\n            // https://maven.apache.org/wrapper/ and https://docs.gradle.org/current/userguide/gradle_wrapper.html\n            if (Path.GetExtension(relative) is \".cmd\" or \".bat\")\n            {\n                var posixSibling = relative[..^Path.GetExtension(relative).Length];\n\n                if (!File.Exists(Path.Combine(appDirectory, posixSibling.Replace('/', Path.DirectorySeparatorChar))))\n                {","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Java/JavaDockerfileGenerator.cs#L1044-L1080","documentation":"When no wrapper was explicitly configured, Aspire expects the project's own default wrapper (mvnw or gradlew, non-Windows name) inside the build context directory and throws if it is absent. Aspire deliberately builds the image with the repository-pinned wrapper so the container uses the same tool version the repo pins. The error tells you how to generate the wrapper or override with an existing one.","triggerScenarios":"Publishing an AddJavaApp resource without WithWrapperPath where the app directory contains pom.xml/build.gradle but no mvnw/gradlew script (and its sibling files).","commonSituations":"Fresh Maven/Gradle projects created without 'mvn wrapper:wrapper' or 'gradle wrapper'; wrapper files stripped by .gitignore; template-generated projects that only commit build files; CI checkouts that exclude wrapper jars/scripts.","solutions":["Run the tool's wrapper generation command (JavaHostingExtensions.GenerateWrapperCommand(tool), e.g. 'mvn wrapper:wrapper' or 'gradle wrapper') in the app directory and commit the result.","Call WithWrapperPath to point at an existing wrapper inside the app directory.","Copy an existing mvnw/gradlew (plus .mvn/ or gradle/wrapper supporting files) into the app directory."],"exampleFix":"// before\nbuilder.AddJavaApp(\"api\", \"src/Api\"); // no mvnw in src/Api\n// after\n// cd src/Api && mvn wrapper:wrapper\nbuilder.AddJavaApp(\"api\", \"src/Api\"); // mvnw now present","handlingStrategy":"validation","validationCode":"var dir = \"src/Api\";\nif (!File.Exists(Path.Combine(dir, \"mvnw\")) && !File.Exists(Path.Combine(dir, \"gradlew\")))\n    Console.WriteLine(\"Generate a wrapper: mvn wrapper:wrapper or gradle wrapper\");","typeGuard":null,"tryCatchPattern":"try { /* publish */ }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"there is no\"))\n{ /* run mvn wrapper:wrapper / gradle wrapper, then republish */ }","preventionTips":["Run 'mvn wrapper:wrapper' or 'gradle wrapper' when creating a new project","Do not gitignore mvnw/gradlew or their support directories","Adopt the wrapper as the standard build entry point for the repo"],"tags":["java","wrapper","publish","missing-file"],"backgroundTag":"file-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}