redhat-developer / odo

odo - Developer-focused CLI for fast & iterative container-based application development on Podman and Kubernetes. Implementation of the open Devfile standard.
https://odo.dev
Apache License 2.0
795 stars 243 forks source link

hotReloadCapable:true doesn't work with java-springboot #6657

Closed kadel closed 1 year ago

kadel commented 1 year ago

/kind bug /priority high

  1. odo init --name java-springboot-starter --devfile java-springboot --starter springbootproject
  2. edit devfile and add hotReloadCapable: true to run exec command
  3. run odo dev
  4. edit source code
  5. odo should just sync files and application should automatically pick up changes, but this is not happening. When running locally with mvn spring-boot:run (the same command devfile uses) it works correctly.

When trying similar steps with nodejs, it works as expected.

  1. odo init --name test --devfile nodejs --starter nodejs-starter
  2. edit devfile and add hotReloadCapable: true to run exec command
  3. install nodemon to project npm install --save-dev nodemon
  4. modify package.json and use nodemon server.js as start script
  5. run odo dev
  6. edit source code
  7. right after file sync is done you can see changes in the application

Because it works in nodejs but doesn't with springboot it looks like this is specific to springboot container.

feloy commented 1 year ago

After some tests, I can see that files are correctly synced to the container, which are detected, and the rebuild is executed.

tools: [INFO] Scanning for projects...
tools: [INFO] 
tools: [INFO] --------------------------< com.example:demo >--------------------------
tools: [INFO] Building demo 0.0.1-SNAPSHOT
tools: [INFO] --------------------------------[ jar ]---------------------------------
tools: [INFO] 

tools: [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
tools: [INFO] Deleting /projects/target
tools: [INFO] 
tools: [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
tools: [INFO] Using 'UTF-8' encoding to copy filtered resources.
tools: [INFO] Copying 1 resource
tools: [INFO] Copying 0 resource
tools: [INFO] 
tools: [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
tools: [INFO] Changes detected - recompiling the module!
tools: [INFO] Compiling 1 source file to /projects/target/classes
tools: [INFO] 
tools: [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
tools: [INFO] Not copying test resources
tools: [INFO] 
tools: [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
tools: [INFO] Not compiling test sources
tools: [INFO] 
tools: [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
tools: [INFO] Tests are skipped.
tools: [INFO] 
tools: [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ demo ---
tools: [INFO] Building jar: /projects/target/demo-0.0.1-SNAPSHOT.jar
tools: [INFO] 
tools: [INFO] --- spring-boot-maven-plugin:2.3.5.RELEASE:repackage (repackage) @ demo ---
tools: [INFO] Replacing main artifact with repackaged archive
tools: [INFO] ------------------------------------------------------------------------
tools: [INFO] BUILD SUCCESS
tools: [INFO] ------------------------------------------------------------------------
tools: [INFO] Total time:  1.773 s
tools: [INFO] Finished at: 2023-03-22T07:49:49Z
tools: [INFO] ------------------------------------------------------------------------

Adding this dependency to the project fixes the issue:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
rm3l commented 1 year ago

Separate issue: make the run command hotReloadCapable in the Devfile stack

kadel commented 1 year ago

I've tried adding spring-boot-devtools and it doesn't help

feloy commented 1 year ago

I had tested only on podman (odo dev --platform podman).

I can reproduce it on podman, but not on cluster.

After some research, I can see that the difference between both platforms is that, when you mark the Run command as hotReloadCapable, the Build command is executed after sources changes in Podman, but not on the cluster.

@kadel could you please double-check that you can reproduce on Podman?

feloy commented 1 year ago

As I understand:

springboot reload is done in 2 stages:

The first stage is done by the Build command, after the sources are synced, and the second stage is done by mvn spring-boot:run (with spring-boot-devtools) when a class changes.

On the other hand, node reload works only with the command npm start; the Build command does not need to be ran again after each source change.

feloy commented 1 year ago

I've created a related issue regarding running the build command when Run is hotReloadCapable: https://github.com/redhat-developer/odo/issues/6695

feloy commented 1 year ago

After some tests, I can see that files are correctly synced to the container, which are detected, and the rebuild is executed.

tools: [INFO] Scanning for projects...
tools: [INFO] 
tools: [INFO] --------------------------< com.example:demo >--------------------------
tools: [INFO] Building demo 0.0.1-SNAPSHOT
tools: [INFO] --------------------------------[ jar ]---------------------------------
tools: [INFO] 

tools: [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
tools: [INFO] Deleting /projects/target
tools: [INFO] 
tools: [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
tools: [INFO] Using 'UTF-8' encoding to copy filtered resources.
tools: [INFO] Copying 1 resource
tools: [INFO] Copying 0 resource
tools: [INFO] 
tools: [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
tools: [INFO] Changes detected - recompiling the module!
tools: [INFO] Compiling 1 source file to /projects/target/classes
tools: [INFO] 
tools: [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
tools: [INFO] Not copying test resources
tools: [INFO] 
tools: [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
tools: [INFO] Not compiling test sources
tools: [INFO] 
tools: [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
tools: [INFO] Tests are skipped.
tools: [INFO] 
tools: [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ demo ---
tools: [INFO] Building jar: /projects/target/demo-0.0.1-SNAPSHOT.jar
tools: [INFO] 
tools: [INFO] --- spring-boot-maven-plugin:2.3.5.RELEASE:repackage (repackage) @ demo ---
tools: [INFO] Replacing main artifact with repackaged archive
tools: [INFO] ------------------------------------------------------------------------
tools: [INFO] BUILD SUCCESS
tools: [INFO] ------------------------------------------------------------------------
tools: [INFO] Total time:  1.773 s
tools: [INFO] Finished at: 2023-03-22T07:49:49Z
tools: [INFO] ------------------------------------------------------------------------

Adding this dependency to the project fixes the issue:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

Fixed when adding this dependency with latest odo version

/close

openshift-ci[bot] commented 1 year ago

@feloy: Closing this issue.

In response to [this](https://github.com/redhat-developer/odo/issues/6657#issuecomment-1543535958): >> After some tests, I can see that files are correctly synced to the container, which are detected, and the rebuild is executed. >> >> ``` >> tools: [INFO] Scanning for projects... >> tools: [INFO] >> tools: [INFO] --------------------------< com.example:demo >-------------------------- >> tools: [INFO] Building demo 0.0.1-SNAPSHOT >> tools: [INFO] --------------------------------[ jar ]--------------------------------- >> tools: [INFO] >> >> >> tools: [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo --- >> tools: [INFO] Deleting /projects/target >> tools: [INFO] >> tools: [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo --- >> tools: [INFO] Using 'UTF-8' encoding to copy filtered resources. >> tools: [INFO] Copying 1 resource >> tools: [INFO] Copying 0 resource >> tools: [INFO] >> tools: [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo --- >> tools: [INFO] Changes detected - recompiling the module! >> tools: [INFO] Compiling 1 source file to /projects/target/classes >> tools: [INFO] >> tools: [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo --- >> tools: [INFO] Not copying test resources >> tools: [INFO] >> tools: [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo --- >> tools: [INFO] Not compiling test sources >> tools: [INFO] >> tools: [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo --- >> tools: [INFO] Tests are skipped. >> tools: [INFO] >> tools: [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ demo --- >> tools: [INFO] Building jar: /projects/target/demo-0.0.1-SNAPSHOT.jar >> tools: [INFO] >> tools: [INFO] --- spring-boot-maven-plugin:2.3.5.RELEASE:repackage (repackage) @ demo --- >> tools: [INFO] Replacing main artifact with repackaged archive >> tools: [INFO] ------------------------------------------------------------------------ >> tools: [INFO] BUILD SUCCESS >> tools: [INFO] ------------------------------------------------------------------------ >> tools: [INFO] Total time: 1.773 s >> tools: [INFO] Finished at: 2023-03-22T07:49:49Z >> tools: [INFO] ------------------------------------------------------------------------ >> ``` >> >> Adding this dependency to the project fixes the issue: >> >> ``` >> >> org.springframework.boot >> spring-boot-devtools >> true >> >> ``` > >Fixed when adding this dependency with latest odo version > >/close > Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.