无法将令牌从 gradle.properties 传递到 settings.gradle
Can't pass token from gradle.properties to 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"]
我按照 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"]