How to say in Maven that one module depends on another?

2

I have two modules and each one depends on the other.

How to say this in dependencies in Maven?

    
asked by anonymous 07.04.2014 / 15:31

2 answers

3

Cyclic dependence? This is project failure, because how will you compile project A if it depends on project B and vice versa? The correct in this case is to separate the common features in a new project C so that A and B will only depend on C.

    
07.04.2014 / 15:52
2

As you mentioned that you can not change the structure, I will give you three ideas to circumvent the situation:

Including the sources

In one of the projects include the necessary sources of the other using Build Helper Maven Plugin . Note that it will not have a direct dependency.

After compiling, you can exclude compiled classes that are not part of this project in jar or war .

The other project can depend on the first one without problems, as long as the build order is respected. Or you can apply this solution for both projects.

Including classes

The above solution can be implemented by directly including the compiled classes of a project in classpath of the other. This can be done, for example, with the Maven Antrun Plugin .

Note that in this workaround and in the previous work, both projects are considered to be available on the local file system. If projects are compiled on a server, you can still use another plugin to download the required files from your file versioner.

Creating a dependency fake

With the simplest design, manually create a jar with only the required classes and interfaces. Add this jar to your local repository, your company's Artifactory or Nexus.

So make the more complex project dependent on this new jar at scope provided , that is, it will be used at compile time but not running.

In this way, compilation of the most complex project will occur without problems, since at least the "shell" of the required classes exists in classpath . And the simpler design may depend directly on the complex project, which will already be compiled.

    
07.04.2014 / 20:33