Vaadin20: Scan Java code from Pom dependency

180 views Asked by At

I want to put a Java class in a Maven artifact that uses the Vaadin @Endpoint annotation (from com.vaadin.flow.server.connect.Endpoint), to use this class in multiple Vaadin projects.

Here is a simple example of such a class:

import com.vaadin.flow.server.connect.Endpoint;
import lombok.RequiredArgsConstructor;
import java.util.Optional;

@Endpoint
@RequiredArgsConstructor
public class SupportInfoEndpoint {

  public Optional<String> getSupportInfo(){
    return Optional.of("mailto:[email protected]");
  }
}

The Maven artifact includes the source code of the class. What do I have to do so this class is scanned in the using project, by the Vaadin build process, so that

  • the corresponding TypeScript code for the frontend is generated
  • the class is included in the Spring-Boot application (so the endpoint is actually available at run time)

Is it possible at all?

2

There are 2 answers

1
Erik Lumme On BEST ANSWER

Unfortunately it is not currently possible, but it will be once #9010 is implemented.

It is my understanding that it is one of the highest priority features to implement for the Fusion team.

6
mmlopez On

Like Erik said, it will be implemented with #9010.

But there is a workaround depending on some restrictions. If you have every class that the endpoint needs in the same jar, you could trigger the typescript generation in same the jar by calling the goal "build-frontend" of vaadin-maven-plugin, then the typescript is generated and it's just a matter of some maven magic to move them to META-INF/resources/frontend (something similar of what is being done here). Then you just can package the endpoints in the jar.

For registering the endpoint in the project, you need to do something similar to what this class is doing, basically a ServiceInitListener that will execute the method registerEndpoint of the EndpointRegistry by using reflection.