jabal
jabal

Reputation: 12367

Maven parent pom variables are not resolved

I have the following POM structure:

./foobar-common/pom.xml ./abc-window/pom.xml ./abc-datasource/pom.xml

Both abc-window pom.xml is as follows:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>hu.abc.ringcore</groupId>
    <artifactId>abc-window</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>abc-window</name>

    <parent>
        <relativePath>../foobar-common/pom.xml</relativePath>
        <groupId>hu.abc.ringcore</groupId>
        <artifactId>foobar-common</artifactId>
        <version>1.0</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>hu.abc.ringcore</groupId>
            <artifactId>abc-datasource</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

abc-datasource pom.xml is as follows:

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hu.abc.ringcore</groupId>
<artifactId>abc-datasource</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>abc-datasource</name>

<parent>
    <relativePath>../foobar-common/pom.xml</relativePath>
    <groupId>hu.abc.ringcore</groupId>
    <artifactId>foobar-common</artifactId>
    <version>1.0</version>
</parent>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
    </dependency>
    <dependency>
        <groupId>hu.abc.ringcore</groupId>
        <artifactId>abc-base</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>hu.abc.ringcore</groupId>
        <artifactId>abc-event</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>hu.abc.ringcore</groupId>
        <artifactId>abc-variable</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>hu.abc.ringcore</groupId>
        <artifactId>abc-variableintf</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>hu.foobar.ring</groupId>
        <artifactId>RateSorszamIntf</artifactId>
        <version>${ringcore-services.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
    </plugins>
</build>

The foobar-common pom.xml is as follows:

<project>
    <modelVersion>4.0.0</modelVersion>
    <name>Maven Default Project</name>
    <groupId>hu.foobar.ringcore</groupId>
    <artifactId>foobar-common</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>4.10</junit.version>
        <spring.version>3.1.2.RELEASE</spring.version>
        <spring-security.version>2.0.6.RELEASE</spring-security.version>
        <commons-logging.version>1.1.1</commons-logging.version>
        <dom4j.version>1.6.1</dom4j.version>
        <javaee-api.version>6.0</javaee-api.version>
        <mycila-event.version>3.0</mycila-event.version>
        <ringcore-services.version>1.3.4-SNAPSHOT</ringcore-services.version>
        <commons-lang3.version>3.1</commons-lang3.version>
    </properties>

</project>

My problem is that if I do an mvn install in abc-datasource the dependency versions are pulled from the parent pom properties as expected. However if I do mvn install from abc-window that references abc-datasource then the versions are not resolved, I get:

[ERROR] Failed to execute goal on project abc-window: Could not resolve dependencies for project hu.abc.ringcore:abc-window:jar:1.0-SNAPSHOT: Failed to collect dependencies for [junit:junit:jar:4.10 (test), hu.abc.ringcore:abc-datasource:jar:1.0-SNAPSHOT (compile)]: Failed to read artifact descriptor for org.apache.commons:commons-lang3:jar:${commons-lang3.version}: Could not transfer artifact org.apache.commons:commons-lang3:pom:${commons-lang3.version} from/to central (http://repo.maven.apache.org/maven2): IllegalArgumentException: Illegal character in path at index 70: http://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/${commons-lang3.version}/commons-lang3-${commons-lang3.version}.pom

Both project have the same parent pom, so why doesn't it work..?

Upvotes: 4

Views: 10370

Answers (2)

Ilya
Ilya

Reputation: 29703

Use dependencyManagment in parent pom

<dependencyManagement>
  <dependencies>
    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>${junit.version}</version>
    </dependency>
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
       <version>${commons-lang3.version}</version>
    </dependency>
    </dependencies>
  </dependencyManagement>  

add all versions in parent pom, and use dependencies without version in children

EDIT

/pom.xml                 <-parent pom
/abc-window/pom.xml     <-child module  
/abc-datasource/pom.xml <-child module  

and parent pom should contains

<project  
...  
   <properties>   
    ... 
   </properties>  
   <modules>  
      <module>abc-datasource</module>
      <module>abc-window</module>  
   </modules>   
   <build>
      <pluginManagment>   
       ...
      </pluginManagment>
   </build>
   <dependencyManagment>
    ...  
   </dependencyManagment>  
</project>

Upvotes: 5

cloudwalker
cloudwalker

Reputation: 2466

The parent in abc-window is listed as:

    <parent>
            <relativePath>../foobar-common/pom.xml</relativePath>
            <groupId>hu.abc.ringcore</groupId>
            <artifactId>foobar-common</artifactId>
            <version>1.0</version>
        </parent>

The parent in abc-datasource is listed as:

<parent>
    <relativePath>../foobar-common/pom.xml</relativePath>
    <groupId>hu.ratesoft.ringcore</groupId>
    <artifactId>foobar-common</artifactId>
    <version>1.0</version>
</parent>

So, they do not have the same groupId.

Upvotes: 1

Related Questions