Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate (possibly empty) build output dir (target/classes) with upstream projects rather than local m2 repository #1570

Merged

Conversation

scottkurz
Copy link
Member

…ile because compilation wasn't done

Signed-off-by: Scott Kurz skurz@us.ibm.com

Fixes #1569 (or at least starts the effort).

@scottkurz
Copy link
Member Author

scottkurz commented Aug 3, 2022

This approach simply tries to adjust for the fact that the CompilerMojo happens to not associate the "target/classes" dir with the dependency Artifact in the special case that there is no source to compile.... causing core Maven resolver function to resolve this Artifact against the local repo, (leading to the fix in #1207 we're now revisiting).

Not sure of the downside in my approach. Presumably there may be some (or if not we might imagine proposing a change in CompilerMojo , though my guess is the community wouldn't think it worth the risk). But within the more narrow dev mode usage it seems like adding our own custom behavior could be worth it.

I did try to understand why a multi-module mvn compile doesn't have the same exact issue as #1201. If I debugged correctly, it seems the reason is there is a special case in https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/ReactorReader.java via which, if we have a 'compile' phase, we will resolve to the output dir somehow. (IIUC).

TODO

  1. Is the 'classes' in 'target/classes' configurable? I'm not sure it is? I see in the maven-compiler doc the config for multi release builds. Not sure if we support them in dev mode.
  2. I suspect this test will fail IT since it looks like the change in Purge locally installed upstream modules when using loose app #1207 tests the implementation detail of purging from the local repo rather than just testing the original Dev mode does not show errors if upstream module already installed in .m2 #1201 external. We'd need to rework the tests.
  3. I see the run goal has a purge as well. I haven't looked at this.

@@ -1173,15 +1175,22 @@ protected void doExecute() throws Exception {
if (isEar) {
runMojo("org.apache.maven.plugins", "maven-ear-plugin", "generate-application-xml");
runMojo("org.apache.maven.plugins", "maven-resources-plugin", "resources");

installEmptyEarIfNotFound(project);
} else if (project.getPackaging().equals("pom")) {
log.debug("Skipping compile/resources on module with pom packaging type");
} else {
purgeLocalRepositoryArtifact();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need to purge the local repository?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops... bad rebase... I fixed it. Let me test again though , when I get a chance, to make sure I didn't mess this up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I could take this to the next step, which I forgot to mention and make sure the watcher compile fails as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By make sure the watcher compile fails as well, do you mean making sure the watcher compile has target/classes in its artifacts list to resolve against?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. I updated the PR for this just now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for taking a quick look. Sorry for the formatting changes that I see snuck in here.

@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch 4 times, most recently from 2ceb61f to e534881 Compare August 4, 2022 20:40
@scottkurz scottkurz changed the title Add target/classes File to upstream multi-module Artifact missing a F… Associate (possibly empty) build output dir (target/classes) with upstream projects rather than local m2 repository Aug 4, 2022
Copy link
Contributor

@kathrynkodama kathrynkodama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you @scottkurz (and thanks for fixing the formatting)

Should we disable this test for now - https://github.com/OpenLiberty/ci.maven/blob/main/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleM2InstalledTest.java (just add @Ignore) and we can rework it in a follow up issue

@scottkurz
Copy link
Member Author

Looks good to me, thank you @scottkurz (and thanks for fixing the formatting)

Should we disable this test for now - https://github.com/OpenLiberty/ci.maven/blob/main/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultiModuleM2InstalledTest.java (just add @Ignore) and we can rework it in a follow up issue

Thanks for taking a look. We could just disable the test ....
But we should at least look at the run goal before merging.

@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch 4 times, most recently from 27b34b6 to bf660a5 Compare August 9, 2022 18:37
@scottkurz
Copy link
Member Author

@kathrynkodama A note on the inability of the logs to capture the failing output.

There's a problem with a pattern like:

assertTrue(getLogTail(logFile), <condition> , timeout));

We're going to do the getLogTail() immediately, but there's no log yet.. the separate mvn liberty:dev process is just starting up.

It looks like this has been addressed in JUnit 5 by adding a Supplier to defer message calculation.
https://stackoverflow.com/a/63921478/1499766

I at least added a failure TestWatcher..... which might help a bit locally (the test afterXXX cleans up the logs) but won't help in say the GHA environment.

Signed-off-by: Scott Kurz <skurz@us.ibm.com>
@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch from bf660a5 to a73572a Compare August 10, 2022 13:15
@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch 2 times, most recently from 4893028 to b59866b Compare August 10, 2022 15:43
File outputDir = Paths.get(mavenProject.getBuild().getOutputDirectory()).toFile();
artifactToUpdate.setFile(outputDir);
try {
outputDir.createNewFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any concern with creating an output directory for modules without any src/main/java code, ie. for ear modules? I can't think of any downside to doing this and just having the empty directory...

@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch 4 times, most recently from fc94069 to 9bf566d Compare August 10, 2022 22:43
@scottkurz
Copy link
Member Author

scottkurz commented Aug 10, 2022

@kathrynkodama your comment jogged my memory that we were doing the install empty EAR thing.

So I went back and made a similar change in that path, so we can programmatically conjure up a "workspace" (i.e. reactor) EAR artifact without having to install one. So we can kind of avoid touching the local .m2 repo altogether it would seem.

I added a path to use 'target' rather than 'target/classes' in case that is a bit less weird.

I left the purge/install code in, just in case we need to resort to it in the case that there are some file permission issues with creating directories.

So this ends up fixing #1203 and providing an alternate solution to #1176

…ile because compilation wasn't done

Signed-off-by: Scott Kurz <skurz@us.ibm.com>
Signed-off-by: Scott Kurz <skurz@us.ibm.com>
@scottkurz scottkurz force-pushed the add-upstream-File-on-skipped-compilation branch from 9bf566d to a8870cf Compare August 10, 2022 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider alternative for missing upstream compile output besides purging from local repository
3 participants