Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ You can build the A2A Java SDK using `mvn`:
mvn clean install
```

### Regeneration of gRPC files
We copy https://github.com/a2aproject/A2A/blob/main/specification/grpc/a2a.proto to the [`spec-grpc/`](./spec-grpc) project, and adjust the `java_package` option to be as follows:
```
option java_package = "io.a2a.grpc";
```
Then build the `spec-grpc` module with `mvn clean install -Pproto-compile` to regenerate the gRPC classes in the `io.a2a.grpc` package.

## Examples

You can find an example of how to use the A2A Java SDK in the [a2a-samples repository](https://github.com/a2aproject/a2a-samples/tree/main/samples/multi_language/python_and_java_multiagent/weather_agent).
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<properties>
<grpc.version>1.73.0</grpc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
Expand All @@ -56,7 +57,9 @@
<mockito-core.version>5.17.0</mockito-core.version>
<mockserver.version>5.15.0</mockserver.version>
<mutiny-zero.version>1.1.1</mutiny-zero.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
<protobuf.version>4.31.1</protobuf.version>
<protobuf-maven-plugin.version>0.6.1</protobuf-maven-plugin.version>
<quarkus.platform.version>3.24.5</quarkus.platform.version>
<rest-assured.version>5.5.1</rest-assured.version>
<slf4j.version>2.0.17</slf4j.version>
Expand Down
85 changes: 84 additions & 1 deletion spec-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,89 @@
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
</dependency>

<!-- Annotation dependency for generated code -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>


<build>
<extensions>
<!--
Seems to be needed by the protobuf-maven-plugin.
Adding these extensions to the profile is not possible
-->
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin.version}</version>
</extension>
</extensions>
</build>

<profiles>
<profile>
<id>proto-compile</id>
<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
<executions>
<execution>
<id>remove-generated-files</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/java/io/a2a/grpc</directory>
<followSymlinks>false</followSymlinks>
<includes>
<include>*.java</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<!-- Protocol Buffers Compiler Plugin -->
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>${protobuf-maven-plugin.version}</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
<outputDirectory>src/main/java</outputDirectory>
<clearOutputDirectory>false</clearOutputDirectory>
Comment on lines +113 to +114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

It's great that you're setting up the protobuf compilation in the build. However, the current configuration has a couple of issues that could lead to problems down the line:

  1. Output Directory: Generating code directly into src/main/java mixes generated code with manually written source code. This is generally discouraged as it makes the project harder to navigate and maintain. A better practice is to generate code into a directory within target, for example ${project.build.directory}/generated-sources/protobuf/java. The protobuf-maven-plugin will automatically add this directory as a source root for compilation.

  2. Clearing Output Directory: clearOutputDirectory is set to false. This is risky because if you remove a message or a field from a .proto file, the old generated Java files won't be deleted. This can lead to stale code and hard-to-debug compilation or runtime errors. It's much safer to set this to true.

By making these changes, you also wouldn't need to check the generated Java files into source control, which is the standard practice. The build process would be responsible for generating them on-the-fly. This avoids merge conflicts in generated files and ensures they are always up-to-date with the .proto definitions.

                                <outputDirectory>${project.build.directory}/generated-sources/protobuf/java</outputDirectory>
                                <clearOutputDirectory>true</clearOutputDirectory>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin is quite flaky. I tried the suggestion, but it failed. Probably because clearOutputDirectory removes the files from the 'compile' goal before it does the 'compile-custom' goal.

So I think we should commit the files.

To work around the 'stale files' issue I added the maven-clean-plugin to the 'proto-compile' profile, and remove all the generated files before regenerating them.

</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</profile>
</profiles>
</project>
Loading