Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
我想在我的gradle文件中添加jitpack.io作为存储库。 这是我的gradle根文件。
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
由于我没有"allrepositories"来放置我的依赖性(只在那里工作),我在buildcript代码之后创建并添加了这段代码。
allprojects {
repositories {
maven {url 'https://www.jitpack.io'}
}
}
但是,我得到的错误是这样的
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
Gradle 6.8 引入了存储库的中央声明,定义存储库的新方法。最新文档 (7.4.2) 可以在这里找到.
从setting.gradle
文件中删除dependencyResolutionManagement
块,让你的项目按老方法工作。
Could not find androidx.databinding:viewbinding:7.0.3.
和其他一些代码段,如paypal
相关的代码和其他也是如此。
- Vivek Thummar 2022-01-26
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
- desertSniper87 2022-08-07
您可以在 settings.gradle 中的 dependencyResolutionManagement 中添加 jitpack.io 作为存储库
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
您需要更新settings.gradle
中的设置并将repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
更改为repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
最后,将maven { url 'https://jitpack.io' }
添加到存储区块中。
完整的settings.gradle
文件看起来会是这样的:
import org.gradle.api.initialization.resolve.RepositoriesMode
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "appname"
include ':app'
替换这行字。
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
使用此方法:
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
Before
After
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
在gradle version '7.1.0'
中只需在setting.gradle
中添加maven { url 'https://jitpack.io' }
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
进入Settings.gradle,并将其放在仓库内。
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
解决方案:
你可以添加这个网址 在 settings.gradle(Project Settings) 文件中, 您可以在 Gradle 脚本中找到它,
在dependencyResolutionManagement内添加你的网址,就像这样
dependencyResolutionManagement{
maven {
url 'https://jitpack.io'
}
}
现在同步它,它将会工作。
谢谢你!:)
随着 Android Studio 的更新,您必须通过 setting.app 控制您的依赖关系
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
} rootProject.name = "EmfDetector" 包括 ':app'
请将这条线放在呼吸系统
maven { url 'https://jitpack.io' } //as i have done above
`
就我而言,我只是删除了settings.gradle
中的dependencyResolutionManagement{...}
语句,新项目默认添加到settings.gradle 中
在settings.gradle中添加这行内容
有些老建议让你把maven { url "https://jitpack.io" }添加到根build.gradle中,但只要你使用的是最新版本的as,你可以简单地把它放到settings.gradle中,而不是build.gradle。
在我的例子中,我只是在settings.gradle中添加了mavenLocal()。
如果你通过登录/密码来访问存储库,请尝试这样做
这里的例子是基于GitHub repo的。
<settings.gradle>
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/OWNER/REPOSITORY")
credentials {
username = "${usernameFromYourGradlePropertiesFile}"
password = "${passwordFromYourGradlePropertiesFile}"
}
}
}
}