Class WatchMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
All Implemented Interfaces:
CdsMojoLogger, org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
AutoBuildMojo

@Mojo(name="watch", defaultPhase=NONE, aggregator=true) public class WatchMojo extends BuildMojo
Starts a CAP Java application and watches for changes in the CDS model. If changes are detected, a cds:build is performed and the application is automatically restarted. Call mvn cds:watch or mvn com.sap.cds:cds-maven-plugin:watch to start the CAP Java application.

With Spring Boot Developer Tools
In order to get even faster development cycles locally, add an optional dependency to the Spring Boot Developer Tools in the pom.xml:
 
 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
   <optional>true</optional>
 </dependency>
 
In this case the watch goal leaves the restart of the application to the Developer Tools, which is faster. The CAP Java application is started with a trigger file configured, used to signal the restart: --spring.devtools.restart.trigger-file=.reloadtrigger. The watch goal touches this trigger file after the cds:build is finished to signal the Spring Boot Developer Tools a safe application restart.
The trigger file is also touched, if any other file in the project has changed and no cds:build is performed. This behaviour ensures that the application is restarted, if a Java source file was changed in an IDE and a restart makes sense to test the changes.

Without Spring Boot Developer Tools
Without a dependency to the Spring Boot Developer Tools, this goal recognises all changes of included files and fully rebuilds and restarts the application.

Start test application
By default, this goal uses spring-boot:run to start the application, but it also supports running an optional test-application. This behaviour can be enabled by setting the property -DtestRun or -DtestRun=true at the Maven command line.

Note: This goal can only be executed from the command line.

Since:
1.17.0
  • Constructor Details

    • WatchMojo

      public WatchMojo()
    • WatchMojo

      protected WatchMojo(boolean noStart)
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Specified by:
      execute in interface org.apache.maven.plugin.Mojo
      Overrides:
      execute in class BuildMojo
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • createRequest

      protected org.apache.maven.shared.invoker.InvocationRequest createRequest(List<String> goals, String... optionalProperties)
    • executeMojo

      protected void executeMojo(org.apache.maven.model.Plugin plugin, String goal, org.apache.maven.model.PluginExecution pluginExec) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • executeMaven

      protected Process executeMaven(org.apache.maven.shared.invoker.InvocationRequest request) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • getMojoDescriptor

      protected org.apache.maven.plugin.descriptor.MojoDescriptor getMojoDescriptor(org.apache.maven.model.Plugin plugin, String goal) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException