Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven runtime scope and cyclic dependency

I have two module A and B. Actualy B is plugin to A.
B depends on A in compile time. A NOT depend on B. On A runtime I want to add B to classpath, so in A's pom.xml I add the following dependency

pom.xml

    <dependency>
        <groupId>my_group</groupId>
        <artifactId>my_Plugin</artifactId>
        <version>${project.version}</version>
        <scope>runtime</scope>
    </dependency> 

Maven process fail with cyclic dependency error

[ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='A'}' and 'Vertex{label='B'}' introduces to cycle in the graph B-->A-->B -> [Help 1]

[ERROR]

Why runtime dependency impact compile time ?

like image 636
user1500951 Avatar asked Jul 04 '12 08:07

user1500951


1 Answers

As suggested by Conan and if possible extract your common code into a separate module in order to resolve the cyclicity. Normally, in such cases one would extract common interfaces and the core classes into a separate module which is extended by both modules which cause the cyclic dependency. You would then remove the direct dependencies on the modules which were initially in a cyclic state. Sometimes this is very hard to solve, but modularizing the code helps you figure out how to refactor your code so that it is easily re-usable.

like image 69
carlspring Avatar answered Oct 14 '22 12:10

carlspring