How does m2e store the module-to-project references? Sibling projects. Parent/aggregate #1487
Replies: 4 comments 1 reply
-
I have read elsewhere that the code to manage this is DefaultMavenDependencyResolver and ProjectRegistryManager. I plan to look at it. I really would like to know how this works because it is the number one thing that breaks. And it breaks a lot. Save a java file with a compile error and sometimes the whole edifice crumbles; compile errors everywhere, and busted knowledge of the other modules. (Aside: I always work with jars intentionally not built in the local repository, so we don't quietly fall back to using them when the eclipse module links break.) I have been sitting at my desk all day studying a particular occurrence. I know all the maven links are correct because it worked just previously. Now a sibling module cannot be found. Whether I run maven from the root of the sub-module or from the root of the parent-module. And then it started working again! Two things might have made a difference: First, when I ran maven compile from the sub-module, maven-4 was complaining that it could not find the root module (missing .mvn folder or set root="true" in the pom file). But I DO have a .mvn folder there! (Aside: Maven-3 also loses the module and does not issue that warning.) So I added a blank settings.xml file in the .mvn folder and the missing root warning went away. But it did not solve the lost sibling module problem. Then, in the module that could not be found, I added a version element that is a duplicate of the parent version element. So now I have a warning in the pom: "Version is duplicate of parent pom". But suddenly the module was found. Was it because the code is looking for the child module explicitly? Or was it just that the change to the pom file triggered some event that caused eclipse/m2e to refresh somehow that fixed the broken reference? Answer: The latter. Eclipse->Project->Clean on the lost module does not fix the problem. Just like we have a Maven->Update Project command, it would be useful to have a "Maven -> Rebuild Module References" command. Beats rebooting eclipse. |
Beta Was this translation helpful? Give feedback.
-
I finally had a good reproducible case and I was able to throw away everything but the problem (I work in a 150 maven module repo, so this is not easy.) And I learned something I really should have known: Setup: Multi-module eclipse project. Parent is both parent and aggregate. One sub-module (child_2) depends on the other (child_1). Nothing deployed to the local repository. Using either maven-3 or maven-4. In eclipse, if you build a launcher in child_2 root directory that calls "mvn compile", it will fail. Even though there is sufficient information to walk from the child to the parent then to all children, the tool does not do this. See launcher named "child-compile-failure" and the failure console below: If you build a launcher in the parent that calls "mvn compile", then it works. See launcher named 'parent-compile-success.launch" and the successful console below. Successful compile:
Unsuccessful compile:
So the lesson is: Build your maven launchers rooted to the parent directory. |
Beta Was this translation helpful? Give feedback.
-
Can you please open a bug report with your reproducer? |
Beta Was this translation helpful? Give feedback.
-
Issue filed at #1523 |
Beta Was this translation helpful? Give feedback.
-
I use sibling projects in all cases. Nothing is nested.
I have been combining the parent and aggregate into a single module. By following the child pom.xml to the parent, the aggregate module is eventually discovered. And the module elements contain the relative path to the sibling modules, so everything can be walked locally (in eclipse projects, not the local .m2 repository). This has been working.
I am trying to build site reports of the aggregated unit and integration test results. That led me to the problem of: Parents are constructed before children, therefore you cannot construct the aggregated test results in the same maven goal as constructing the child test results. See this and that.
One solution is to run the test aggregation report in a subsequent step.
Another solution is to separate the parent and aggregate into two separate modules. That sounded better so I tried that.
But now I don't see how m2e can "find" the sibling modules in the eclipse project. And sure enough, m2e cannot find them reliably. A child module can point to its parent but it cannot point to its aggregate.
I can see that m2e caches the association between open eclipse projects and maven modules on startup. Is that the mechanism, i.e., to consult a cache? Or is there some other system?
Beta Was this translation helpful? Give feedback.
All reactions