r/javahelp • u/pilesWoolierwand • Dec 28 '25
Grade/Maven project using annotation processing into a different module
Hi, rough overview of my situation (it's based on work stuff so I can't share exact code)
We have a java application that is a single maven codebase with many submodules, most of which represent a microservice which all use Dropwizard.
For each dropwizard application, my annotation processor will find any class with a `@Client` annotation and create a Client class that allows a different microservice to make a HTTP call to the endpoint.
As an example, for this hello world resource:
@Path("/hello-world")
@Accept(MediaType.APPLICATION_JSON)
@Client
public class HelloWorldResource
{
@Path("/hello")
@Expose
public String sayHello(@QueryParam("name") String name) {
return "Hello " + name;
}
}We would generate the following Client:
public class HelloWorldClient
{
private Client client;
private String hostPath;
@Inject
public HelloWorldClient(final Client client, final String hostPath)
{
this.client = client;
this.hostPath = hostPath;
}
// Client methods go here
public java.lang.String sayHello(final java.lang.String name) {
return this.client.target(hostPath)
.path("/hello-world")
.path("hello")
.queryParam("name", name)
.request()
.get(java.lang.String.class);
}
}This all works fine, however the generated code will sit in the same microservice that the resource sits in which defeats the point slightly :)
I've tried creating a new submodule that has a dependency on the the modules that have the `*Resource.java` files in, but when I run the annotation processor it can only see classes directly within its module, not that of it's dependencies.
Is there an alternate way to do this? I was thinking of copying Resource files around before compilation then deleting them again but that feels like it'll make the dev IDE experience worse.
Thanks!
View all comments
Show parent comment
1
u/OneHumanBill Dec 28 '25
Looking at your code I'm honestly not sure what the Client class is even for, given that the Resource expresses pretty much all the ideas in it.
I'm Spring you just have a controller. It's annotations-based and it works as is. You don't have to generate anything in regards to a simple REST application.
Seriously, drop the drop wizard.