ThomasH
ThomasH

Reputation: 23536

Vaadin20: Scan Java code from Pom dependency

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

Is it possible at all?

Upvotes: 1

Views: 190

Answers (2)

mmlopez
mmlopez

Reputation: 106

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.

Upvotes: 5

Erik Lumme
Erik Lumme

Reputation: 5342

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.

Upvotes: 2

Related Questions