microsoft/aspire · error · InvalidOperationException
Directory ' ' contains no pom.xml, build.gradle…
Error message
Directory '{workingDirectory}' contains no pom.xml, build.gradle, build.gradle.kts, settings.gradle, or settings.gradle.kts, so the build tool for resource '{resourceName}' cannot be detected. Check the path, or use AddJavaApp for an application laid out differently. What it means
At resource creation time (run mode), Aspire detects the Java build tool by looking for pom.xml or Gradle build/settings files in the working directory. JavaBuildToolResolver.Detect returned null, so RequireBuildTool throws an InvalidOperationException explaining which files it probes and suggesting AddJavaApp for different layouts. Unlike the publish errors, this fires when the resource is being configured, before any build or publish.
Solutions
- Pass the directory that contains pom.xml or a Gradle build/settings file to AddJavaApp.
- Fix the path (check for typos or extra nesting) so it points at the module root.
- Generate the build file (pom.xml/build.gradle.kts) in the directory if the project genuinely uses Maven/Gradle.
Example fix
// before
builder.AddJavaApp("api", "repo"); // build files in repo/server
// after
builder.AddJavaApp("api", "repo/server"); // pom.xml lives here Defensive patterns
Strategy: validation
Validate before calling
var dir = "repo/server";
string[] markers = ["pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts"];
if (!markers.Any(m => File.Exists(Path.Combine(dir, m))))
throw new DirectoryNotFoundException($"No Maven/Gradle build file in {dir}"); Try / catch
try { /* add Java app */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("build tool for resource"))
{ /* fix the path or add a build file and retry */ } Prevention
- Verify the working directory contains a build descriptor before calling AddJavaApp
- Point at the module directory in multi-module projects, not the repo root
- Keep pom.xml/gradle files at the project root per standard layout conventions
When it happens
Trigger: Calling an AddJavaApp overload (or a helper using TryResolveConfiguredBuildTool) with a workingDirectory containing none of pom.xml, build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts.
Common situations: Typo'd or wrong project path; pointing at a solution/repo root instead of the module directory; projects generated without build files; layouts where the build descriptor is in a nested folder.
Related errors
- The Java application
- The Java application
- ArgumentOutOfRangeException: Specified argument was out of…
- Directory ' ' contains both Maven and Gradle build files…
- cannot be used when a JAR path has been specified. Use…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/b1c218595a3d9b16.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Java/JavaHostingExtensions.cs:536
context.EnvironmentVariables[quarkusName] = value;
}
}
/// <summary>
/// Requires an application directory to declare a Maven or Gradle project.
/// </summary>
/// <remarks>
/// Detection is shared with publishing so the same project files cannot select different tools in each path.
/// </remarks>
/// <exception cref="InvalidOperationException">The directory has no build file, or has both Maven and Gradle files.</exception>
private static JavaBuildTool RequireBuildTool(string workingDirectory, string resourceName)
{
if (JavaBuildToolResolver.Detect(
workingDirectory,
resourceName,
static message => new InvalidOperationException(message)) is not { } tool)
{
throw new InvalidOperationException(
$"Directory '{workingDirectory}' contains no pom.xml, build.gradle, build.gradle.kts, settings.gradle, or settings.gradle.kts, " +
$"so the build tool for resource '{resourceName}' cannot be detected. " +
$"Check the path, or use AddJavaApp for an application laid out differently.");
}
return tool;
}
private static IResourceBuilder<T> WithDetectedBuildTool<T>(
this IResourceBuilder<T> builder,
string[] mavenBuildArgs,
string[] mavenLaunchArgs,
string[] gradleBuildArgs,
string[] gradleLaunchArgs)
where T : JavaAppResource
{
builder.WithAnnotation(
new JavaDetectedBuildToolAnnotation(View on GitHub (pinned to 25830f84bd)