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

  1. Pass the directory that contains pom.xml or a Gradle build/settings file to AddJavaApp.
  2. Fix the path (check for typos or extra nesting) so it points at the module root.
  3. 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

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


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)