Gradle无法解决Maven配置文件依赖性 [英] Gradle unable to resolve maven profile dependency

查看:1160
本文介绍了Gradle无法解决Maven配置文件依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目A,其中的配置文件为:

I have a maven project A that has profiles in it as:

<properties>
<bigquery.version>0.0.1</bigquery.version>
</properties>
.
.
<profiles>
<profile>
  <id>dev</id>
  <activation></activation>
  <properties>
    <build.version>${bigquery.version}</build.version>
  </properties>
</profile>
<profile>
  <id>screwdriver-v3</id>
  <activation>
    <activeByDefault>true</activeByDefault>
    <property>
      <name>screwdriver3</name>
    </property>
  </activation>
  <properties>
    <buildtype>release</buildtype>
    <build.version>${bigquery.version}.${maven.build.timestamp}</build.version>
  </properties>
</profile>

我在以下位置创建了A版本:0.0.1.20180424-0042

I have created a version of A at : 0.0.1.20180424-0042

我还有另一个gradle项目B,我想将A作为依赖添加为:

I have another gradle project B that I want to add A as a dependency as:

compile group:'com.bq', name:'bigquery', version:'0.0.1.20180424-0042'

当我使用./gradlew clean build构建gradle时,它抱怨为:

When I build gradle with ./gradlew clean build, it is complaining as:

Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve com.bq:bigquery:0.0.1.20180424-0042.
Required by:
  project :
> Could not resolve com.bq:bigquery:0.0.1.20180424-0042.
  > inconsistent module metadata found. Descriptor: com.bq:bigquery:0.0.1.${maven.build.timestamp} Errors: bad version: expected='0.0.1.20180424-0042' found='0.0.1.${maven.build.timestamp}'

我该如何解决依赖关系?

How do I go about fixing the dependency?

推荐答案

使用这样的Maven配置文件被视为反模式,请进一步阅读此处

Using maven profiles like this is considered an anti-pattern, further reading here

Gradle不完全支持Maven配置文件激活.在此处阅读博客文章,以了解两个受支持的配置文件激活触发器是

Gradle does not have full support for maven profile activation. Read the blog post here to see that the two supported profile activation triggers are

  • 默认情况下处于活动状态的配置文件(适用于Gradle 1.12和更高版本)
  • 缺少系统属性时有效的配置文件(适用于Gradle 2.0及更高版本)
  • Profiles that are active by default (available with Gradle 1.12 and higher)
  • Profiles that are active on the absence of a system property (available with Gradle 2.0 and higher)

作为解决方法,您可以执行以下操作:

As a workaround, you could do the following:

  1. 使用本地文件夹作为被入侵的Maven存储库
  2. 首先订购本地文件夹存储库,使其优先于远程存储库
  3. 在本地文件存储库中复制/粘贴/调整pom,以便对其进行硬编码
  4. 请勿将工件(例如jar)复制到本地文件夹存储库中

然后gradle应该从本地存储库中提取pom,从远程存储库中提取jars

Then gradle should take the pom from the local repo and the jars etc from the remote repository

例如:

repositories {
    maven {
        url = file('local-repo')
    }
    mavenCentral()
}

然后您将已调整"的pom放在

You would then put the "tweaked" pom at

$projectDir/local-repo/$group.replace('.','/')/$artifact/$version/$artifactId-$version.pom

这篇关于Gradle无法解决Maven配置文件依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆