gradle适配maven项目,Gradle无法解决Maven配置文件依赖性

本文介绍了一个关于Maven项目与Gradle项目之间的依赖问题,并提供了详细的解决方案。主要讨论了版本不一致导致的问题及如何通过本地仓库的hack方式来解决依赖版本冲突。

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

0.0.1

.

.

dev

${bigquery.version}

screwdriver-v3

true

screwdriver3

release

${bigquery.version}.${maven.build.timestamp}

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

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'

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?

解决方案

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

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

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:

Use a local folder as a hacked maven repository

Order the local folder repository first so it takes precedence over the remote repository

Copy / paste / tweak the pom in the local file repo so that it hard codes the version

Do not copy the artifact(s) (eg jar) to the local folder repository

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

Eg:

repositories {

maven {

url = file('local-repo')

}

mavenCentral()

}

You would then put the "tweaked" pom at

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值