Gradle Maven Bom属性 [英] Gradle Maven Bom Properties

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

问题描述

我正在考虑从maven迁移到gradle,在我们当前的设置中,我们有一个主pom,它定义了我们所有的版本依赖项.

I'm looking into migrating from maven to gradle and in our current setup we have a master pom that defines all of our version dependencies.

项目名称为master-pom,并具有以下片段:

the project name is master-pom and has snippets like this:

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>${commons-beanutils-version}</version>
        </dependency>

.... 然后在文件中,我们沿着以下几行定义一些内容:

.... and later down in the file we define something along these lines:

<properties>
    <commons-beanutils-version>1.9.1</commons-beanutils-version>
</properties>

现在,这是我到目前为止所拥有的:

Now, this is what I have so far:

 plugins {
    id "com.github.johnrengelman.shadow" version "1.2.4"
    id "nebula.dependency-recommender" version "3.7.0"
}


apply plugin: 'java'
apply plugin: 'war'

apply plugin: 'nebula.dependency-recommender'
apply plugin: "com.github.johnrengelman.shadow"




version = '1.0.0-SNAPSHOT'
sourceCompatibility =  '1.8'

description = """best-service-ever"""



repositories {
       mavenLocal()
       maven { url 'https://repo.server.com/nexus/content/groups/public'
          credentials {
               username 'username'
               password nexusPassword
          }
    }
       mavenCentral()
       jcenter()


}

dependencyRecommendations {
   mavenBom module: 'biz.company.name:master-pom:1.0.0-SNAPSHOT'
}



dependencies {
          ... some dependencies
          compile 'biz.company.name:db-schema'
}

这时,它将选择名为$ {db-version}的版本,并使用build-maven中正确定义的版本.问题是,我需要使用特定版本覆盖该版本.

At this point it'll pick up the version named ${db-version} and use the correctly defined one from the build-maven. The problem is, I need to override that version with a specific version.

我尝试将值放在gradle.properties中,但是存在问题.

I tried putting the value in gradle.properties, but there's an issue with that.

db-version,因为它将-解释为算术运算.相反,我尝试将值定义为

db-version is unsupported by gradle, since it interprets - as arithmetic operation. I instead tried defining the value as

db_version = 0.0.1700

db_version=0.0.1700

这似乎有效,但是如何设置它以覆盖$ db-version值.我想避免必须在每个工件中显式设置版本:

which seems to work, but how do I set it so it overrides the $db-version value. I would like to avoid having to explicitly set the version: in every artifact.

理想的情况是要么允许我简单地覆盖bom文件中的属性.

My ideal scenario would either allow me to simply override the properties that come from the bom file.

以前有人遇到过这个问题吗?还是要解决?

Has anyone run into this issue before? Or have a work around?

推荐答案

这可能是部分答案.

我确实发现这种模式似乎可行,尽管它有点脆弱并且有点太冗长.我真正想做的就是说.

I did find this pattern that seems to work though it's a bit brittle and a bit too verbose. What I really would like to do is say.

${common-service-version} = MyVersionNumber  (which is defined in gradle.properties)

示例修复程序:

dependencyRecommendations {
   mavenBom module: 'biz.company.name:master-pom:1.0.0-SNAPSHOT'
   /* Override properties from mavenBom */
   map recommendations: [ 'biz.company.name:shared-common-service': services_common_global_version,
    'biz.company.name:services-core': services_common_global_version,
    'biz.neustar.ms:test-services-common': services_common_global_version,
    'biz.company.name:mip-db-schema':  db_version,
    'biz.company.name:services-api': services_api_version
   ]
}

这确实有效,尽管您必须以某种方式重新定义依赖项.如果有人有更好的模式,请告诉我.

This does work though you have to re-define the dependencies in a way. If someone has a better pattern let me know.

这篇关于Gradle Maven Bom属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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