Java hosting integration enhancements & Gradle support#1129
Java hosting integration enhancements & Gradle support#1129marshalhayes wants to merge 15 commits intoCommunityToolkit:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Java hosting integration by replacing options-based configuration with composable, fluent builder methods and adds Gradle support alongside the existing Maven support. The changes align with current Aspire patterns while maintaining backward compatibility through obsolete methods.
Changes:
- Introduces Gradle support with
WithGradleBuild()andWithGradleTask()methods that mirror Maven's functionality - Refactors API from options-based to fluent builder pattern with methods like
WithMavenGoal(),WithGradleTask(),WithJvmArgs(), andWithOtelAgent() - Adds new resource types (
MavenBuildResource,GradleBuildResource,JavaBuildToolAnnotation) to support build tool integration - Deprecates
AddSpringApp()in favor ofAddJavaApp()andAddJavaContainerApp(), and marks options classes as obsolete
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| ExecutableResourceCreationTests.cs | Updates tests to use new API, adds comprehensive tests for Maven/Gradle build and goal/task execution |
| ContainerResourceCreationTests.cs | Adds test for new AddJavaContainerApp API, wraps deprecated tests in pragma warnings |
| README.md | Complete rewrite with examples for Maven, Gradle, JAR execution, and JVM configuration |
| JavaAppHostingExtension.Executable.cs | Major refactor introducing new fluent API methods, BeforeStartEvent handling for build tool command switching |
| JavaAppHostingExtension.Container.cs | Adds AddJavaContainerApp method with cleaner API, deprecates old methods |
| JavaAppExecutableResource.cs | Adds new constructor and JarPath property to support flexible execution modes |
| MavenBuildResource.cs | New resource representing Maven build steps |
| GradleBuildResource.cs | New resource representing Gradle build steps |
| JavaBuildToolAnnotation.cs | Internal annotation for tracking build tool configuration |
| MavenOptions.cs | Marked as obsolete |
| JavaAppExecutableResourceOptions.cs | Marked as obsolete |
| JavaAppContainerResourceOptions.cs | Marked as obsolete |
| Program.cs (example) | Updated to demonstrate new API patterns |
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppExecutableResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Container.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Container.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Container.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/GradleBuildResource.cs
Outdated
Show resolved
Hide resolved
6699705 to
220fd04
Compare
…xecutable resources
- Make jarPath a required parameter in AddJavaApp - Remove jarPath from WithMavenBuild/WithGradleBuild - Simplify wrapper path resolution using ??= pattern - Inline ResolveWrapperCommand into callers - Restructure README to align with other integrations - Fix stale Obsolete messages to match current signatures Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rload - Add AddJavaApp(name, workingDirectory) overload without jarPath - Add WithJarPath() fluent method for explicit JAR path configuration - Add WithMavenGoal() and WithGradleTask() to run apps via build tools - Add JavaBuildToolAnnotation for build tool integration - Refactor existing AddJavaApp to delegate to new overload - Simplify Dockerfile generation for publish scenarios - Update README with new API patterns and examples - Update example app to use new API - Add new tests for the expanded API surface Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove PublishAsJavaDockerfile and JavaBuildAnnotation, which were new functionality not present in the existing integration. Auto-Dockerfile generation can be revisited as a separate feature. Fix deprecated AddSpringApp (container) obsolete message to point to AddJavaContainerApp instead of the also-deprecated AddJavaApp. Restore endpoint assertions in container resource tests. Update README publishing section to reflect manual PublishAsDockerFile. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove stray double quote characters after </param> tags and remove unnecessary blank lines in Container and Executable extensions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Follow C# naming conventions for constants by renaming JAVA_TOOL_OPTIONS to JavaToolOptions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ng with WithCommand
MavenBuildResource and GradleBuildResource now accept the resolved wrapper
script path in their constructors, eliminating the need to pass a placeholder
("mvnw"/"gradlew") and immediately override it with .WithCommand().
This aligns with the Aspire convention where ExecutableResource receives the
actual command at construction time (e.g. PythonAppResource, NodeAppResource).
Addresses PR review comments r2844673239 and r2844673316.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AddJavaContainerApp and the new AddJavaApp called WithOtelAgent() with no agentPath, which just delegates to WithOtlpExporter() anyway. Call WithOtlpExporter() directly to avoid implying an OTel agent is configured. Users who need the agent can chain WithOtelAgent(path). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Maven-specific default was misleading for Gradle users and unused by the WithMavenGoal/WithGradleTask code path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Show resolved
Hide resolved
| public static IResourceBuilder<JavaAppExecutableResource> AddJavaApp(this IDistributedApplicationBuilder builder, [ResourceName] string name, string workingDirectory, | ||
| string jarPath, string[]? args = null) | ||
| { |
There was a problem hiding this comment.
This PR introduces new/changed public APIs (e.g., new AddJavaApp overloads and the Gradle/Maven fluent methods), but the generated API baseline file (src/CommunityToolkit.Aspire.Hosting.Java/api/CommunityToolkit.Aspire.Hosting.Java.cs) still appears to reflect the pre-change surface area. If CI/packaging expects these api/*.cs files to be kept in sync (as other integrations do), please regenerate/update the Java one for this PR.
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Java/JavaAppHostingExtension.Executable.cs
Outdated
Show resolved
Hide resolved
- WithJvmArgs: remove params, require explicit string[] args with null check and empty-array early return - Fix XML docs: remove incorrect 'If null, falls back to current process directory' claim from workingDirectory params (non-nullable) - Obsolete WithMavenBuild(MavenOptions): pass Command as wrapperScript to preserve existing callers' custom wrapper commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
aaronpowell
left a comment
There was a problem hiding this comment.
Looking like a really solid overhaul of the Java integration - nice work!
I see we have some build failures, that's likely next to tackle before merging is to be tackled.
Closes #1128
This PR updates the Java hosting integration, replacing options-based configuration with composable, fluent builder methods that align with current Aspire patterns.
What's New
Gradle support
WithGradleTask()runs Gradle tasks (e.g.,bootRun) on Java app resources, automatically resolving the correct platform-specific wrapper (gradlew/gradlew.bat).WithGradleBuild()adds a pre-build lifecycle hook using the Gradle wrapper, modeled as a dependentGradleBuildResourcethat runs before the app starts.Composable builder methods
WithMavenGoal()— configures Maven to run a goal (e.g.,spring-boot:run) instead of executing a JAR directly.WithOtelAgent()— attaches the OpenTelemetry Java agent via-javaagentJVM arg.WithJvmArgs()— adds arbitrary JVM arguments (e.g.,-Xmx512m).Simplified entry points
AddJavaApp(name, workingDirectory)— creates an executable Java resource (optionally with a JAR path).AddJavaContainerApp(name, image)— creates a container-based Java resource.What's Changed
AddSpringApp()replaced in favor ofAddJavaApp()/AddJavaContainerApp()JavaAppContainerResourceOptionsandJavaAppExecutableResourceOptionsare marked[Obsolete]; the legacy overloads that accept them still work but delegate to the new API internally.JavaAppExecutableResourcenow implementsIResourceWithWaitSupportand defaults its command tojava, with arguments constructed dynamically viaCommandLineArgsCallbackAnnotation.JavaAppContainerResourcenow usesContainerMountAnnotationfor the OTel agent instead of an environment variable pointing to a directory.WithMavenBuild()now creates a dependentMavenBuildResource(lifecycle hook) instead of a dashboard rebuild command.WithMavenGoalthrows if a JAR path is already set).PR Checklist
Other information