无法将令牌从 gradle.properties 传递到 settings.gradle



我在https://docs.mapbox.com/android/maps/guides/install/除了我不能选择存储在gradle.properties中的令牌来在settings.gradle中的Mapbox Maven存储库上对自己进行身份验证之外,一切似乎都正常。安装指南中显示的方法对我不起作用。

这是我的settings.gradle:

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = System.getenv("MAPBOX_DOWNLOADS_TOKEN")
}
}
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "MyApp Name"
include ':app'

这是我的gradle.properties:

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token

我可能做错了什么?

在阅读gradle文档后,我发现mapbox安装指南错误的地方是在gradle.properties中设置令牌变量。您需要将其指定为系统属性(请参阅https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties),所以基本上你所要做的就是改变

MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token

在中

systemProp.MAPBOX_DOWNLOADS_TOKEN=this_is_my_secret_access_token

现在转到settings.gradle文件并更改行

password = System.getenv("MAPBOX_DOWNLOADS_TOKEN")

带有

password = System.properties["MAPBOX_DOWNLOADS_TOKEN"]

最新更新