Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jooby-apt and Lombok processing #1866

Closed
kliushnichenko opened this issue Jul 20, 2020 · 4 comments · Fixed by #1875
Closed

jooby-apt and Lombok processing #1866

kliushnichenko opened this issue Jul 20, 2020 · 4 comments · Fixed by #1875
Milestone

Comments

@kliushnichenko
Copy link
Contributor

Lombok is a well-known and widely used project which is served to eliminate a lot of java boilerplate code.

As you probably know Lombok does its stuff at build time thus its code doesn't need at runtime.
I believe it is a common approach to remove it from uber jar. And usually, it works great(with jooby1 also) but
jooby-apt generate sources which reference some Lombok classes directly.

For example for the code:

import io.jooby.annotations.GET;
import io.jooby.annotations.Path;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import javax.inject.Inject;

@Path("/")
@RequiredArgsConstructor(onConstructor = @__(@Inject))
public class PetsController {

  private final @NonNull PetsService petsService;

  @GET
  @Path("/ping")
  public String ping() {
    petsService.ping();
    return "Welcome to Jooby!";
  }
}

Next lines will be generated by the jooby-apt

        var2.attribute("RequiredArgsConstructor.staticName", "");
        var2.attribute("RequiredArgsConstructor.access", AccessLevel.PUBLIC);

so if we remove Lombok jar from uber jar we will catch

Caused by: java.lang.ClassNotFoundException: lombok.AccessLevel

Don't know if there is any good solution for this, but at least should be known.
Maybe we can add some configuration to jooby-apt, to mark annotations(packages) which jooby-apt should ignore.

@jknack jknack added this to the 2.9.0 milestone Jul 20, 2020
@imeszaros
Copy link
Member

Since I was in the flow with jooby-apt, I created a possible solution but it builds on some of the changes within #1861.

You can pass a comma separated list of annotation or package names to jooby.skipAttributeAnnotations: imeszaros@6be2dea

Let me know if it's useful and I'll create a PR.

@jknack
Copy link
Member

jknack commented Jul 21, 2020

@imeszaros Ideally we should check for current usage of annotation and in addition to a skip list, we should check if the annotation has a non-runtime retention and ignore them (not sure if possible)

@imeszaros
Copy link
Member

I added filtering on the retention policy, had to modify the tests though to pass it: imeszaros@13c605d

What do you mean by

we should check for current usage of annotation

?

@jknack
Copy link
Member

jknack commented Jul 22, 2020

What do you mean by

Bad English I guess 😄

Your code looks good, waiting for a PR. Can you add test case with non-runtime annotation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants