Search code examples
javaeclipsemavendependenciesparent-pom

Can I add maven dependencies that are packed as anything other than .jar?


I just produced my first parent-module project with maven, and successfully installed it. Can I add this project as a dependency in another project, only by referring to the parent? My Eclipse IDE complains that it can't find the parent.jar, but that is not a surprise, as it is packaged as parent.pom.

Question: So is it possible to add a parent (.pom) dependency, and get all transitive dependencies for free, or do I have to add .jar's.

Bonus Question: Is it possible to add dependencies to other packaging formats as well, like a war? I can't really figure out how that would work, or why I would need that at this point though. Just curious.

Disclaimer: I'm still learning maven, and find the philosophy and theory of it to be great. However, there are so many pits and reefs that seems to pop out, and more than once, I struggle to see if I'm trying to do something impossible, or if there is another mistake in configurations I.E. Right now Eclipse says it can't find any of my .m2 referenced dependencies in this one particular project. I have no idea why, as other projects works fine. I am in other words trying to find the error, by checking one area at the time...


Solution

  • Answer: Yes, you can add different types such as pom, test-jar and so on. Jar is just the default

    Bonus Answer: Yes, you can specify type war as well

    The Maven-Guide defines the following types: "The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par."

    Here is a example on how a POM is included:

    <dependencies>
      <dependency>
       <groupId>com.my</groupId>
       <artifactId>comm-group</artifactId>
       <type>pom</type>
      </dependency>
    </dependencies>
    

    This (the pom of comm-group) is oftenly used to group certain dependencies and include all of them using the type-pom.

    Here is additional information on grouping: http://blog.sonatype.com/2009/10/maven-tips-and-tricks-grouping-dependencies/#.VFC7LR_JY8c Note that there are similar behaviours you could create using polymorphism.

    I had my issues with maven when we migrated from Ant and i still have certain concernes on it (like were is the advantage of maven if 80% of our SWEs apply wrong scopes, types and so on leading to a massive drawback if they just 'need to add a fcking jar' as well as to refactorings lead by "maven gurus").

    BUT: I can guarantee you that if you go throught http://maven.apache.org/pom.html completely you will aquire statisfieing results compared to ANT over time.

    Update: I just ran into the case where my pom could not be included on the remote build server while it worked building it from inside Intellij Idea/ Eclipse. Type definition in my case had to be lowercase (e.g. 'pom' instead of 'POM').