org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
时间: 2023-08-05 21:50:58 浏览: 69
这个错误是由于在构建文件 `build.gradle` 中添加了一个项目仓库,但是构建设置优先使用设置仓库而不是项目仓库。解决这个问题的方法是将该仓库添加到 `settings.gradle` 文件中的仓库列表中,而不是在 `build.gradle` 文件中添加项目仓库。您可以按照以下步骤操作:
1. 打开 `settings.gradle` 文件。
2. 在 `settings.gradle` 文件中添加以下代码来定义您要使用的仓库:
```groovy
repositories {
maven {
url 'https://maven.google.com'
}
}
```
3. 删除 `build.gradle` 文件中添加项目仓库的代码。
4. 重新运行构建,该错误应该已经解决了。
相关问题
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
这个问题是由于在 `build.gradle` 文件中添加了一个名为 `maven` 的存储库,并且构建配置中设置了首选设置存储库而不是项目存储库引起的。这意味着构建系统将使用设置存储库而不是项目存储库。
要解决这个问题,你可以尝试以下几种方法:
1. 将 `maven` 存储库添加到你的构建配置的项目存储库列表中。这样做可以确保构建系统使用项目存储库而不是设置存储库。你可以在 `build.gradle` 文件中查找类似以下内容的代码块并进行相应的修改:
```groovy
repositories {
// ...
maven {
url "https://example.com/maven-repo"
}
// ...
}
```
2. 如果你确实希望首选使用设置存储库,则可以尝试删除 `maven` 存储库的引用,或者将其替换为设置存储库中相应组织或URL的引用。
请确保在更改构建配置之前备份你的项目文件,以便在需要时可以恢复到先前的状态。此外,根据你的具体情况和需求,可能还有其他解决方案可供选择。
Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
这个警告表示在构建脚本中添加了一个已经在 Gradle 设置中配置好的仓库。这可能会导致构建速度变慢,因为Gradle会尝试从重复的仓库中下载相同的依赖项。为了避免这种情况,您可以将这个仓库从构建脚本中移除,让Gradle只使用配置文件中指定的仓库。如果您确实需要在构建脚本中添加仓库,请确保使用和Gradle配置文件中相同的名称和地址。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)