{"record":{"id":"c10ff1d373c428ff","repo":"microsoft/aspire","slug":"resource-builder-resource-name-is-already-configured-to-c10ff1","errorCode":null,"errorMessage":"Resource '{builder.Resource.Name}' is already configured to launch with {launchTool.Tool}. A Java application is built and launched by a single build tool.","messagePattern":"Resource '(.+?)' is already configured to launch with (.+?)\\. A Java application is built and launched by a single build tool\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Java/JavaHostingExtensions.cs","lineNumber":817,"sourceCode":"    private static IResourceBuilder<T> WithJavaBuildStep<T>(\n        this IResourceBuilder<T> builder,\n        JavaBuildTool tool,\n        string buildResourceName,\n        string[] buildArgs)\n        where T : JavaAppResource\n    {\n        // Building with both tools would produce two artifacts and leave the container build with no way\n        // to choose between them, so it is rejected the same way conflicting launch modes are.\n        if (builder.Resource.TryGetLastAnnotation<JavaBuildStepAnnotation>(out var existing) && existing.Tool != tool)\n        {\n            throw new InvalidOperationException(\n                $\"Resource '{builder.Resource.Name}' is already configured to build with {existing.Tool}. \" +\n                $\"Call either WithMavenBuild or WithGradleBuild, not both.\");\n        }\n\n        if (builder.Resource.TryGetLastAnnotation<JavaBuildToolAnnotation>(out var launchTool) && launchTool.Tool != tool)\n        {\n            throw new InvalidOperationException(\n                $\"Resource '{builder.Resource.Name}' is already configured to launch with {launchTool.Tool}. \" +\n                \"A Java application is built and launched by a single build tool.\");\n        }\n\n        // A launch goal such as spring-boot:run or bootRun compiles the application on its way to running\n        // it, so a build resource in front of it would only repeat work. That holds only while the launch\n        // goal is what actually starts the application and nothing else needs the build's output first.\n        var createRunResource = builder.ApplicationBuilder.ExecutionContext.IsRunMode\n            && (RequiresBuildBeforeLaunch(builder)\n                || launchTool is null && !builder.Resource.HasAnnotationOfType<JavaDetectedBuildToolAnnotation>());\n\n        // Recorded in every execution context: in publish mode there is no build-step resource, but the\n        // generated Dockerfile still runs this tool and these arguments to produce the deployable JAR.\n        builder.WithAnnotation(\n            new JavaBuildStepAnnotation(\n                createRunResource ? buildResourceName : null,\n                tool,\n                buildArgs),","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Java/JavaHostingExtensions.cs#L799-L835","documentation":"Build and launch must be driven by the same build tool. WithJavaBuildStep throws when the resource already has a JavaBuildToolAnnotation (set by WithMavenGoal/WithGradleTask) for a tool different from the one being configured for the build step.","triggerScenarios":"Calling WithMavenBuild on a resource whose launch was configured with WithGradleTask (or the Maven/Gradle reverse combination).","commonSituations":"Configuring the build step from one example and the launch goal from another that used a different build tool; partial migration between Maven and Gradle.","solutions":["Match the build step to the launch tool (e.g. call WithGradleBuild when the launch is WithGradleTask)","Remove the launch call and reconfigure both build and launch with the same tool","Decide on one build tool for the resource and use only its With* APIs"],"exampleFix":"// before\nvar java = builder.AddJavaApp(\"app\", dir).WithGradleTask(\"bootRun\").WithMavenBuild(\"package\");\n// after\nvar java = builder.AddJavaApp(\"app\", dir).WithGradleTask(\"bootRun\").WithGradleBuild(\"build\");","handlingStrategy":"validation","validationCode":"if (builder.Resource.TryGetLastAnnotation<JavaBuildToolAnnotation>(out var launch) && launch.Tool != JavaBuildTool.Maven)\n{\n    throw new InvalidOperationException(\"Build step tool must match the configured launch tool.\");\n}","typeGuard":"builder.Resource.TryGetLastAnnotation<JavaBuildToolAnnotation>(out var launchTool)","tryCatchPattern":"try { java.WithMavenBuild(\"package\"); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"already configured to launch with\"))\n{\n    // use the build-step API for the same tool as the launch\n}","preventionTips":["Always pair build-step and launch calls from the same tool family","When copying examples, keep them from the same build tool","Document per-resource which build tool owns build and launch"],"tags":["java","aspire-hosting","build-tool","conflicting-configuration"],"backgroundTag":"conflicting-config-options","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"}