jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.68k stars 199 forks source link

jooby-apt: MVC generated controllers require `jakarta-inject` should be documented because of code generation. #3460

Closed agentgt closed 1 week ago

agentgt commented 2 weeks ago

Because we now generate the code for MVC controllers one has to make sure to add the jakarta inject dependency as scope compile/provided.

Alternatively we could make the io.jooby:jooby pom depend on it so it automatically gets pulled in but that may not go over well with folks that use the fluent api instead.

So at the minimum I'm thinking we just add it to the documentation that they need to add:

<dependency>
    <groupId>jakarta.inject</groupId>
    <artifactId>jakarta.inject-api</artifactId>
    <version>2.0.1</version>
</dependency>

Happy to do the changes on this or the previous bugs I filed recently to help out.


Also for the code generation maybe consider doing:

@SuppressWarnings("exports") // add this annotation
public OpsController_(jakarta.inject.Provider<OpsController> provider)

The above annotation will then make modular builds not show a warning if one does only:

requires jakarta.inject;

Otherwise they will have to do:

requires transitive jakarta.inject;

Because the constructor is public.

However it maybe required to use the transitive regardless if reflective access is used (this I'm unsure on and need to test).

If is required than we need to document it as well that one needs to add requires transitive.

jknack commented 2 weeks ago

will change to Supplier

agentgt commented 2 weeks ago

Well that is a much better solution and feel stupid for not recommending it 😆