如何在Gradle上设置依赖项的版本?

时间:2018-10-26 02:16:20

标签: gradle build.gradle version

我想在我的Gradle中的一个地方设置依赖项的版本 (app / build.gradle)配置文件,以防万一更新。

问题是:

dependencies {
implementation 'com.google.android.gms:play-services-maps:12.0.0'
implementation 'com.google.android.gms:play-services-auth:12.0.0'
implementation 'com.google.firebase:firebase-core:12.0.0'
implementation 'com.google.firebase:firebase-auth:12.0.0'
implementation 'com.google.firebase:firebase-database:12.0.0'
implementation 'com.google.firebase:firebase-storage:12.0.0'
implementation 'com.google.firebase:firebase-messaging:12.0.0'
implementation 'com.google.android.gms:play-services-ads:12.0.0'
implementation 'com.github.bumptech.glide:glide:4.5.0'
}

您能看到吗,我多次投放同一个版本,这使将所有版本更改为下一个版本变得缓慢且毫无成效。

就像在Maven中一样,我可以这样做:

<properties>
    <org.springframework.version>5.0.8.RELEASE</org.springframework.version>
</properties>

设置版本后,我只需添加以下内容:

<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
</dependencies>

Maven配置的最后一部分确实在此部分中设置了版本:

  

$ {org.springframework.version}

如何在Gradle配置中执行相同的操作?

1 个答案:

答案 0 :(得分:3)

他们都将拥有相同版本的假设是绝对错误的...

Dim mesaConstraints As NonlinearConstraint() =
    {' Make sure all variables follow their constraints
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(0) >= min0),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(1) >= min1),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(2) >= min2),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(3) >= min3),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(4) >= min4),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(5) >= min5),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(6) >= min6),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(0) <= max0),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(1) <= max1),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(2) <= max2),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(3) <= max3),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(4) <= max4),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(5) <= max5),
    New NonlinearConstraint(7, Function(mesaVar) mesaVar(6) <= max6)
}

还可以使用版本号设置def glideVersion = "4.5.0" dependencies { implementation "com.google.android.gms:play-services-base:16.0.1" implementation "com.google.android.gms:play-services-auth:16.0.1" implementation "com.google.android.gms:play-services-maps:16.0.0" implementation "com.google.android.gms:play-services-ads:16.0.0" implementation "com.google.firebase:firebase-core:16.0.4" implementation "com.google.firebase:firebase-auth:16.0.4" implementation "com.google.firebase:firebase-database:16.0.3" implementation "com.google.firebase:firebase-storage:16.0.3" implementation "com.google.firebase:firebase-messaging:17.3.4" implementation "com.github.bumptech.glide:glide:${glideVersion}" } properties-或从外部文件加载它们。

project.ext

,然后将其与ext { glideVersion = "4.5.0" ... } ${rootProject.ext.glideVersion}一起使用。

通常,更改并不容易...只是另一种组织方式。