Search code examples
eclipsem2eclipse

Eclipse m2e plugin issue for cyclic dependent projects


I have an issue with m2e plugin for cyclic dependent projects.

First of all, I know that circular dependencies are bad , maven also does not permit it, they should be avoided and etc. but our legacy projects were mavenized without project structure change (circular dependencies were continued).

Previously, adding each project to other projects build path and setting circular dependencies build path problem to warning was the workaround solution. That way, I could make changes in one project and see the effect in the other immediately.

Now that projects are mavenized, I want to achieve the same workspace environment by enabling m2e workspace resolution (by checking "Resolve dependencies from workspace projects" option).

In eclipse neon (Version: Neon.3 Release (4.6.3) Build id: 20170314-1500) with m2e version 1.7.0.20160603-1933 this is possible. Corresponding maven dependency is resolved from workspace project although there is cycle in build path.

However, in eclipse 2019-09 R (Version: 2019-09 R (4.13.0) Build id: 20190917-1200 with m2e version 1.13.0.20190716-1624) and later releases, build results in infinite loop. For two cyclic projects MY PROJECT A and MY PROJECT B with maven artifact ids MYPROJECTAARTIFACTID, MYPROJECTBARTIFACTID respectively, below is the m2e log for infinite build from 2019-09 R version (I could not gather logs from neon version).

To repeat, I know that maven itself does not allow cyclic project setup but in general eclipse does allow it even for projects with maven nature.

How can I achieve the same in latest eclipse releases?

2020-05-22 21:19:26,588 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.builder.MavenBuilder - Building project MY PROJECT B
2020-05-22 21:19:26,683 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\MAVEN_REPONEW
2020-05-22 21:19:26,697 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.ProjectRegistryManager - Refreshing: [L/MY PROJECT B/pom.xml]
2020-05-22 21:19:26,709 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\MAVEN_REPONEW
2020-05-22 21:19:26,712 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Reading 1 Maven project(s): [D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml]
2020-05-22 21:19:26,764 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultUpdatePolicyAnalyzer - Skipped remote request for ...
2020-05-22 21:19:26,868 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Read 1 Maven project(s) in 156 ms
2020-05-22 21:19:27,036 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.m.MavenMarkerManager - Created marker 'GroupId is duplicate of parent groupId' on resource '/MY PROJECT B/pom.xml'.
2020-05-22 21:19:27,043 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\MAVEN_REPONEW
2020-05-22 21:19:27,086 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loading lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:27,670 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.c.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=637200, ConflictMarker.markTime=709300, ConflictMarker.nodeCount=118, ConflictIdSorter.graphTime=487300, ConflictIdSorter.topsortTime=290200, ConflictIdSorter.conflictIdCount=45, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=3881500, ConflictResolver.conflictItemCount=72, DefaultDependencyCollector.collectTime=398895400, DefaultDependencyCollector.transformTime=7801200}
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] INFO  o.e.m.c.i.l.LifecycleMappingFactory - Using org.eclipse.m2e.jdt.JarLifecycleMapping lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loaded lifecycle mapping in 699 ms for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - MY PROJECT B is configured by :
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.jdt.javaConfigurator
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.java.unsupportedDependencyTypeConfigurator
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jpa.configurator.jdt
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.utility.configurator
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.webfragment.configurator
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.sonatype.m2e.mavenarchiver.jararchiverconfigurator
2020-05-22 21:19:27,785 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jaxrs.configurator
2020-05-22 21:19:27,786 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.DefaultMavenDependencyResolver - Resolving dependencies for P/MY PROJECT B: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT
2020-05-22 21:19:27,786 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Reading Maven project: D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml
2020-05-22 21:19:27,790 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultUpdatePolicyAnalyzer - Skipped remote request for com.my.company:... locally cached metadata up-to-date.
2020-05-22 21:19:28,529 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.c.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=925200, ConflictMarker.markTime=269600, ConflictMarker.nodeCount=328, ConflictIdSorter.graphTime=1694200, ConflictIdSorter.topsortTime=470600, ConflictIdSorter.conflictIdCount=88, ConflictIdSorter.conflictIdCycleCount=48, ConflictResolver.totalTime=7407900, ConflictResolver.conflictItemCount=309, DefaultDependencyCollector.collectTime=730670400, DefaultDependencyCollector.transformTime=10784800}
2020-05-22 21:19:28,539 [Worker-7: Building Workspace] INFO  o.e.m.c.i.p.WorkspaceClassifierResolverManager - Resolving P/MY PROJECT A: com.my.company:MYPROJECTAARTIFACTID:1.0.1-SNAPSHOT with classifier  to /MY PROJECT A/target/classes
2020-05-22 21:19:28,598 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Read Maven project: D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml in 812 ms
2020-05-22 21:19:28,598 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.DefaultMavenDependencyResolver - Resolved dependencies for P/MY PROJECT B: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT in 812 ms
2020-05-22 21:19:28,600 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\MAVEN_REPONEW
2020-05-22 21:19:28,601 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loading lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,607 [Worker-1: Decoration Calculation] DEBUG o.e.j.i.storage.file.FileSnapshot - file=C:\Program Files\Git\etc\gitconfig, isRacyClean=false, read=2020-05-22 21:18:57.612000000, lastModified=2020-04-28 20:51:11.602527000, delta=2075266009473000 ns, racy<=2500000000 ns
2020-05-22 21:19:28,607 [Worker-1: Decoration Calculation] DEBUG o.e.j.i.storage.file.FileSnapshot - file=C:\Program Files\Git\etc\gitconfig, is unmodified
.......
2020-05-22 21:19:28,677 [Worker-7: Building Workspace] INFO  o.e.m.c.i.l.LifecycleMappingFactory - Using org.eclipse.m2e.jdt.JarLifecycleMapping lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loaded lifecycle mapping in 77 ms for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - MY PROJECT B is configured by :
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.jdt.javaConfigurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.java.unsupportedDependencyTypeConfigurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jpa.configurator.jdt
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.utility.configurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.webfragment.configurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.sonatype.m2e.mavenarchiver.jararchiverconfigurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jaxrs.configurator
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.DefaultMavenDependencyResolver - Resolving dependencies for P/MY PROJECT B: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT
2020-05-22 21:19:28,678 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Reading Maven project: D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml
2020-05-22 21:19:28,689 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.c.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=288800, ConflictMarker.markTime=102300, ConflictMarker.nodeCount=328, ConflictIdSorter.graphTime=336300, ConflictIdSorter.topsortTime=260900, ConflictIdSorter.conflictIdCount=88, ConflictIdSorter.conflictIdCycleCount=48, ConflictResolver.totalTime=3849800, ConflictResolver.conflictItemCount=309, DefaultDependencyCollector.collectTime=5078800, DefaultDependencyCollector.transformTime=4849700}
2020-05-22 21:19:28,697 [Worker-7: Building Workspace] INFO  o.e.m.c.i.p.WorkspaceClassifierResolverManager - Resolving P/MY PROJECT A: com.my.company:MYPROJECTAARTIFACTID:1.0.1-SNAPSHOT with classifier  to /MY PROJECT A/target/classes
2020-05-22 21:19:28,739 [Worker-7: Building Workspace] DEBUG o.e.m.c.internal.embedder.MavenImpl - Read Maven project: D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml in 61 ms
2020-05-22 21:19:28,739 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.DefaultMavenDependencyResolver - Resolved dependencies for P/MY PROJECT B: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT in 61 ms
2020-05-22 21:19:28,740 [Worker-7: Building Workspace] DEBUG o.e.a.i.i.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:\MAVEN_REPONEW
2020-05-22 21:19:28,741 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loading lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] INFO  o.e.m.c.i.l.LifecycleMappingFactory - Using org.eclipse.m2e.jdt.JarLifecycleMapping lifecycle mapping for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - Loaded lifecycle mapping in 63 ms for MavenProject: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT @ D:\LOCALGITREPOS\CYCLE_2019\MYPROJECTBARTIFACTID\MY PROJECT B\pom.xml.
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory - MY PROJECT B is configured by :
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.jdt.javaConfigurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.java.unsupportedDependencyTypeConfigurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jpa.configurator.jdt
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.utility.configurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.maven.ide.eclipse.configuration.wtp.webfragment.configurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.sonatype.m2e.mavenarchiver.jararchiverconfigurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.l.LifecycleMappingFactory -  - org.eclipse.m2e.wtp.jaxrs.configurator
2020-05-22 21:19:28,804 [Worker-7: Building Workspace] DEBUG o.e.m.c.i.p.r.DefaultMavenDependencyResolver - Resolving dependencies for P/MY PROJECT B: com.my.company:MYPROJECTBARTIFACTID:1.0.1-SNAPSHOT
................

-----------------------------EDIT 1--------------------------

Sample project added to github ( https://github.com/simpleusr/eclipseproblem ) for reproducing the issue. It also fails with latest eclipse Version: 2020-03 (4.15.0) Build id: 20200313-1211


Solution

  • Eclipse allows the compilation of multiple projects with circular dependencies. But here, resolving the Maven dependencies leads to the infinite loop, which is a different thing. To resolve and download the dependencies, Eclipse uses the embedded Maven, that is shipped with the Eclipse IDE.

    Since Maven does not allow cyclic dependencies, you can't build this from command line either. In Eclipse, it would work without the invalid Maven dependencies to the other project in the pom.xml files, by adding the other project in the Java Build Path manually and allowing circular dependencies for the Java Compiler. But these manually settings will be overwritten on Maven > Update Project....

    If you want to use Maven to build your projects, you have two options:

    • Put everything into a single Maven project, maybe with multiple source folders. You can split the built JAR into several JARs in a post-processing step. This has the same disadvantage as with multiple circular interdependent projects: stuff may be missing at runtime if not the entire code with all dependencies is on the classpath.
    • Eliminate the cycles. Based on my experience, this is what I would recommend, since the time invested (probably weeks) pays off in the long run (and it's more fun to have modularized code than spaghetti code).