Thomas
Thomas

Reputation: 45

Maven deploy and versions of dependencies

When I run mvn deploy on a project where the version of a dependency in the child pom is defined as a property in the parent pom, the version number is not expanded in the deployed artifact.

In this example ${spring.version} is not expanded. Can I make maven expand the version property?

Parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>test</module>
</modules>

<properties>
    <spring.version>3.2.2.RELEASE</spring.version>
</properties>

<distributionManagement>
    <snapshotRepository>
        <id>dips_snapshot</id>
        <url>http://mavenrepo.dips.local/repository/dips_snapshot</url>
    </snapshotRepository>
</distributionManagement>
</project>

Child pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>TestProject</groupId>
<artifactId>subproject</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>TestProject</groupId>
    <artifactId>TestProject</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
</dependencies>

Deployed pom:

<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>TestProject</groupId>
<artifactId>subproject</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>

Upvotes: 0

Views: 1238

Answers (2)

Nicola Musatti
Nicola Musatti

Reputation: 18218

I prefer a different project organization, where parenthood and aggregation are separated. I use an aggregator project which contains my plain projects as modules and a parent project which is also a module of my aggregator project. This parent project is shared between all the plain projects and the aggregator. My parent and plain projects are stored in subdirectories of the aggregator project directory and the relativePath of each parent element is set accordingly.

This organization better separates concerns and ensures that inter-project dependencies are handled correctly, as long as you perform your builds from the aggregator project directory.

Upvotes: 1

ben75
ben75

Reputation: 28706

It seems you need to install locally (or even deploy) the parent pom. To do so you can simply run:

mvn clean install -N

in your parent project directory. The -N option is not mandatory, it only stop the recursion (so it will be very fast since only your parent pom will installed)

Upvotes: 1

Related Questions