2

Is it possible to use an aggregating module (pom that aggregates modules for building purposes) as a dependency that transitively includes its modules as dependencies? Considering it must declare those dependencies that correspond to its submodules, otherwise if you declare it as a dependency, it hasn't own dependencies, so that no transitive deps are included.

I already tried it but I got a cyclic dependency error.

Otherwise I would have to create an extra module (say my_module_deps) that just declares all those dependencies, so I could use it as a dependency that transitively includes its dependencies. I don't like having maven modules that do not have any specific purpose except for being a dependency bulk.

This is the desired state, so I can use it for both module aggregation and a dependency to be used for getting its transitive dependencies :

<project>
    <artifactId>aggregationModule</artifactId>
    <modules>
        <module>a</module>
        <module>b</module>
        <module>c</module>
    </modules>
    <dependencies>
        <dependency>
            <artifactId>a</artifactId>
        </dependency>
        <dependency>
            <artifactId>b</artifactId>
        </dependency>
        <dependency>
            <artifactId>c</artifactId>
        </dependency>
    </dependencies>
</project>
lisak
  • 21,611
  • 40
  • 152
  • 243

2 Answers2

0

Do any of the sub-modules have that aggregating project defined as its parent? If so, this cannot work, since for being parent the project must be build first. But if the parent itself defines the modules as dependencies at the same time, the modules must be build first, so you created your cyclic dependency error.

xor_eq
  • 3,933
  • 1
  • 29
  • 33
  • They do not, I have a separate pom for aggregation and for inheritance. Despite of that I'm getting the cyclic dep error. – lisak Jan 10 '13 at 18:03
  • In that case you should try to break your poms down to an example that demonstrates the problem and add it as a code example to your question. – xor_eq Jan 10 '13 at 20:16
-1

You cannot declare a dependency to a project with packaging type "pom". If you do so maven will show the same error as when you declare a dependency to a jar module which does not exists in your local repository and could not be downloaded from your repository list.

Maybe some of the alternatives proposed to this question could help you.

Community
  • 1
  • 1
joragupra
  • 692
  • 1
  • 12
  • 23
  • You totally CAN declare a dependency to a module with packaging type "pom" ! – lisak Jan 10 '13 at 15:17
  • This answer is just wrong. You can have lots of dependencies in a project with packaging pom. I have a project like this which was transitioned from an ant-build. By using packaging pom, you can more or less define everything in the lifecycle exactly as you need it since almost nothing is bound to any phase of the lifecycle by default. You can build a full webapp ear including compiling and creating the .jar assembly with the assembly-plugin in a single pom-packaging maven project. (But I wouldn't necessarily recommend doing that). – xor_eq Jan 10 '13 at 17:24
  • Of course you can define dependencies in a project with packaging pom. That was not my answer. The answer was dependencies declared to modules with packaging pom will not be resolved. At least, that is what I got with the example projects I've just created -see comment above. – joragupra Jan 10 '13 at 17:37
  • 1
    Oh, I'm sorry, I misread that. But it's still wrong, you just have to add pom to the dependency definition then. A dependency to a project with packaging pom won't give you the cyclic dependency error the OP described but instead it gives a "Could not transfer artifact" since it tries to load the artifact with the default type/packaging which is "jar". – xor_eq Jan 10 '13 at 20:15