简体   繁体   English

gradle 不能从我在 build.gradle 中指定的库中的依赖版本中的父属性中解析占位符

[英]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.我有一个关于通过 gradle 解决依赖版本的有趣问题。 Here is my situation.这是我的情况。 I deployed my libraries to nexus.我将我的库部署到了 nexus。 In this process I used the flatten-maven-plugin and resolveCiFriendliesOnly flattenMode.在这个过程中,我使用了 flatten-maven-plugin 和 resolveCiFriendliesOnly flattenMode。 As result I have parent pom file and child pom files in nexus.结果我在nexus中有父pom文件和子pom文件。

parent pom file from source:来自源的父 pom 文件:

<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来自源的子 pom 文件

<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来自nexus的父pom文件

<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来自nexus的子pom文件

<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.之后,我尝试使用 gradle 构建 java 应用程序。 In build.gradle file of this application I have such line:在此应用程序的 build.gradle 文件中,我有这样的行:

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 不能解析子项目依赖的占位符?

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 . gradle似乎没有评估${example-child-dependency.version}并且您可能必须使用mvn构建才能为 gradle 生成消耗品/静态*.pom gradle I mean, most likely mvn would evaluate *.pom , while gradle doesn't.我的意思是,很可能mvn会评估*.pom ,而gradle不会。

And that might rather be:那可能是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 依赖版本未从 ext 块 build.gradle 解析 - Dependency version not resolved from ext block build.gradle 即使在 build.gradle 中指定,也无法解析符号“EnableJpaRespositories” - Cannot resolve symbol 'EnableJpaRespositories' even though specified in build.gradle 与依赖项冲突:build.gradle - Conflict with dependency : build.gradle 在build.gradle中使用Gradle属性 - The use Gradle properties in build.gradle Android-阅读类内部的build.gradle属性 - Android - Read build.gradle properties inside class 如何从另一个 build.gradle 调用 build.gradle - How to call build.gradle from another build.gradle 未指定 compileSdkVersion。 请将它添加到 build.gradle:即使我在我的 build.gradle 文件中定义了它 - compileSdkVersion is not specified. Please add it to build.gradle: even though I have it defined in my build.gradle file 尽管引用了 eclipse 中的库并在 build.gradle 中指定了依赖关系,为什么我得到“java.lang.NoClassDefFoundError”? - Why am I getting "java.lang.NoClassDefFoundError" despite referencing the library in eclipse and specifying the dependency in build.gradle? IntelliJ IDEA使用Gradle构建文件中指定的JavaScript“版本”依赖项吗? - IntelliJ IDEA using JavaScript “version” of dependency specified in Gradle build file? Gradle构建无法解析aar库依赖项(trnql sdk) - Gradle build failed to resolve aar library dependency (trnql sdk)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM