OpenLiberty / ci.maven

Maven plugins for managing Liberty profile servers #devops
Apache License 2.0
125 stars 90 forks source link

Dev mode does not recompile/redeploy when adding upstream src/main/java #1202

Open ericglau opened 3 years ago

ericglau commented 3 years ago
  1. Use this project: https://github.com/OpenLiberty/guide-maven-multimodules/tree/master/finish
  2. Delete jar/src and war/src/main/java
  3. Run mvn install to install the project to ~/.m2 (no compilation errors occur because there is no Java code in the source of any modules)
  4. Run mvn io.openliberty.tools:liberty-maven-plugin:3.3.5-M3-SNAPSHOT:dev
  5. After dev mode starts up, restore the files from step 2. Dev mode does not recompile (yet) *
  6. Make a change in jar/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java. Dev mode DOES recompile the jar and war modules, but the following compilation error occurs **
    /Users/eric/git/guide-maven-multimodules/finish/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java:50: error: package io.openliberty.guides.multimodules.lib does not exist
        this.feet = io.openliberty.guides.multimodules.lib.Converter.getFeet(cm);
                                                          ^
    /Users/eric/git/guide-maven-multimodules/finish/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java:61: error: package io.openliberty.guides.multimodules.lib does not exist
        this.inches = io.openliberty.guides.multimodules.lib.Converter.getInches(cm);
                                                            ^
    2 errors
  7. Notice the loose application was not redeployed so the jar and war target classes directories are not in ear/target/liberty/wlp/usr/servers/defaultServer/apps/guide-maven-multimodules-ear.ear.xml ***

In summary, 3 related problems here denoted by , , and above.

kathrynkodama commented 3 years ago

Addressing the second issue stated above (step 6):

/Users/eric/git/guide-maven-multimodules/finish/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java:50: error: package io.openliberty.guides.multimodules.lib does not exist
        this.feet = io.openliberty.guides.multimodules.lib.Converter.getFeet(cm);
                                                          ^
/Users/eric/git/guide-maven-multimodules/finish/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java:61: error: package io.openliberty.guides.multimodules.lib does not exist
        this.inches = io.openliberty.guides.multimodules.lib.Converter.getInches(cm);
                                                            ^
2 errors

This is due to how Maven resolves classpath elements for multi module builds. When the jar/src directory exists, thanks to the Maven reactor the war module's classpath has the following entry for the jar module: /Users/kathrynkodama/devex/sampleProjects/guide-maven-multimodules/finish/jar/target/classes Maven uses the reactor to add target directories of upstream modules to the current modules classpath.

When dev mode starts without the jar/src/ directory, the war module's compile classpath elements has the following entry for the jar module: /Users/kathrynkodama/.m2/repository/io/openliberty/guides/guide-maven-multimodules-jar/1.0-SNAPSHOT/guide-maven-multimodules-jar-1.0-SNAPSHOT.jar Since the jar module is not being installed to the local repo, the war module cannot resolve the jar module's dependency even after the jar/src directory is added.

One workaround would be to call mvn compile from the top-level pom in order to trigger the reactor and have the /guide-maven-multimodules/finish/jar/target/classes directory added to the classpath. This would also require updating the artifact paths for all of the modules.

ericglau commented 3 years ago

We can document this as a limitation for now (as part of OpenLiberty/ci.maven#1199) that dev mode must be started with an existing src/main/java dir with existing Java file(s).

scottkurz commented 2 years ago

Just looking over this, I think we could close this.

We have a very clear warning explaining what's going on. I also believe we have other limitations in dev mode where we are unable to watch new directories (e.g. I think we might not be able to act to a new resource directory being added, IIRC).

Maybe the next pass we take through the issues backlog we could consider closing.