简体   繁体   中英

gradle doesn't resolve placeholder from parent properties in dependency version that is inside library that I specified in build.gradle

I have one interesting question about resolving dependencies versions by gradle. Here is my situation. I deployed my libraries to nexus. In this process I used the flatten-maven-plugin and resolveCiFriendliesOnly flattenMode. As result I have parent pom file and child pom files in nexus.

parent pom file from source:

<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>${revision}${changelist}</version>
<packaging>pom</packaging>

<properties>
    <revision>0.0.1</revision>
    <changelist>-SNAPSHOT</changelist>
    <version.base>${revision}${changelist}</version.base>
    <example-child.version>${version.base}</example-child.version>
    <example-child-dependency.version>${version.base}</example-child-dependency.version>
</properties>

child pom file from source

<parent>
    <groupId>ru.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>${revision}${changelist}</version>
    <relativePath>..</relativePath>
</parent>

<artifactId>example-child</artifactId>
<version>${example-child.version}</version>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>ru.example</groupId>
        <artifactId>example-child-dependency</artifactId>
        <version>${example-child-dependency.version}</version>
    </dependency>
</dependencies>

parent pom file from nexus

<groupId>ru.example</groupId>
<artifactId>example-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <version.base>0.0.1-SNAPSHOT</version.base>
    <revision>0.0.1</revision>
    <changelist>-SNAPSHOT</changelist>
    <example-child.version>${version.base}</example-child.version>
    <example-child-dependency.version>${version.base}</example-child-dependency.version>
<properties>

child pom file from nexus

<parent>
    <groupId>ru.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>..</relativePath>
</parent>

<groupId>ru.example</groupId>
<artifactId>example-child</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>ru.example</groupId>
        <artifactId>example-child-dependency</artifactId>
        <version>${example-child-dependency.version}</version>
    </dependency>
</dependencies>

After that I try to build java application with gradle. In build.gradle file of this application I have such line:

dependencies {
    implementation("ru.example:example-child:0.0.1-SNAPSHOT")
}

And build fails with error:

> Task :java_application:compileJava
Resolving global dependency management for project 'java_application'
Errors occurred while build effective model from /u01/jenkins_slave/.gradle/caches/modules- 
2/files-2.1/ru.example/example-child/0.0.1- 
SNAPSHOT/809129e53f76bfb7b6a141e9aeb8ffb1a692e76c/example-child-0.0.1-SNAPSHOT.pom:
'dependencies.dependency.version' for ru.example:example-child-dependency:jar must be a 
valid version but is '${example-child-dependency.version}'. in ru.example:example- 
child:0.0.1-SNAPSHOT

Why gradle doesn't resolve placeholder of child project dependency?

gradle appearently does not evaluate ${example-child-dependency.version} and you might have to build with mvn in order to produce consumable/static *.pom for gradle . I mean, most likely mvn would evaluate *.pom , while gradle doesn't.

And that might rather be:

<artifactId>example-child-dependency</artifactId>
<version>${version.base}</version>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM