Reputation: 337
I would like to have a "dependencies file" to be able to load this file into different maven poms. I have two poms in my project which are similar to some degree. I want the identical configuration in a third pom to be loaded by the working poms. Is this possible?
e.g. something like:
<project A>
<dependencies>
<file> "depend.xml" </file>
</dependencies>
...
<project B>
<dependencies>
<file> "depend.xml" </file>
</dependencies>
...
Upvotes: 1
Views: 2031
Reputation: 337
I was not used to the concept of "build lifecycle". I thought that I have to have different poms for different tasks. e.g. one for packaging and one for deployment. After I found out that I can assign the plugins execution to specific phases I'm able to get along with only one pom which eliminates my whole question.
Upvotes: -1
Reputation: 9498
You could create a hierarchical project making A and B a module of a common parent and manage your dependencies there.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Parent</name>
<modules>
<module>A</module>
<module>B</module>
</modules>
...
<dependencies>
....
</dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>A</artifactId>
<packaging>jar</packaging>
<name>A</name>
<parent>
<groupId>my.package</groupId>
<artifactId>parent/artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
You can also introduce variables to organize your versions using this pattern.
...
<properties>
<alib.version>4.7</alib.version>
<properties>
...
<dependencies>
<dependency>
<groupId>alib</groupId>
<artifactId>someArtifact</artifactId>
<version>${alib.version}</version>
</dependency>
</dependencies>
Upvotes: 1
Reputation: 1256
You can create a parent POM file, which all your projects inherit. By specifying dependencies, versions, etc. in the parent POM file, you don't need to respecify them in each project (unless you need to override them for whatever reason).
There's more information at: https://www.smartics.eu/confluence/display/BLOG/2013/07/22/Using+Aggregate+and+Parent+POMs
Upvotes: 2