You do already mirror dependencies into your Artifactory, but Gradle needs to be explicitly told to look in your Artifactory for plugins.
That should be possible by adding a pluginManagement
block in your settings.gradle
file:
pluginManagement {
repositories {
maven {
url 'https://my.artifactory/my-repo/gradle'
}
gradlePluginPortal() // Optional: If you still want to resolve from Gradle Plugin Portal when online
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == 'com.android.application') {
useModule("com.android.application:com.android.application.gradle.plugin:${requested.version}")
}
}
}
}
有关Kotlin DSL(settings.gradle.kts
),请参阅this example:
验证ArtiFactory中的构件的 struct 是否正确,以及是否存在所有必要的元数据,包括.pom
个文件和任何.jar
或.aar
个文件.Gradle依赖于这些元数据来解析依赖关系.
有关Kotlin DSL(settings.gradle.kts
),请参见this example.
验证ArtiFactory中的构件的 struct 是否正确,以及是否存在所有必要的元数据,包括.pom
个文件和任何.jar
或.aar
个文件.Gradle依赖于这些元数据来解析依赖关系.
在运行构建时,您可以强制Gradle从本地缓存或您配置的存储库中解析依赖项,而无需try 使用--offline
标志访问Internet:
./gradlew build --offline
有趣的是,当我以--scan
运行时,它给出了一个不同的错误.也就是说,它现在找不到com.gradle.enterprise
(不在ArtiFactory中).
The error related to com.gradle.enterprise
not being found in Artifactory suggests that there might be additional plugins or dependencies not mirrored in your Artifactory. That plugin (the com.gradle.enterprise
one) is often used for Gradle Enterprise or build scans, which helps in diagnosing build issues but also needs to be available in your repository if your build configuration requires it. You might need to add this plugin to your Artifactory or adjust your build configuration to not require it for offline builds.
If com.gradle.enterprise
is essential for your build, apply a similar pluginManagement
strategy to resolve this plugin from your Artifactory, similar to how you have done for com.android.application
.
If the com.gradle.enterprise
plugin is not relevant for your offline builds, consider conditionally applying this plugin based on whether an internet connection is available or not. That can be achieved with logic in your build.gradle
or settings.gradle
files to check for connectivity before applying the plugin.
我的目录 struct 正确吗?还是应该是com.android/application
?
在Maven存储库(ArtiFactory模拟的)中存储构件的约定通常使用正斜杠(/
)来分隔路径中的组ID、构件ID和版本.然而,Gradle's plugin management系统对插件使用了略有不同的符号,这就是为什么您在构建脚本中使用类似com.android.application
的ID来指定插件,但实际的构件可能存储在类似com/android/application/com.android.application.gradle.plugin/8.2.1/
的路径中.重要的是要确保ArtiFactory反映Gradle所期望的 struct ,这通常意味着将插件ID转换为与Maven兼容的路径 struct .
所以,我在我原来的帖子中列出了目录 struct ?这就是Gradle所期望的吗?
您为ArtiFactory中的插件列出的目录 struct 是:
gradle/
com.android.application/
com.android.application.gradle.plugin/
8.2.1/
<some hash>/
com.android.application.gradle.plugin-8.2.1.pom
它与Gradle在解析插件和依赖项时所期望的传统Maven存储库布局不一致.
Gradle在解析插件时需要一个类似Maven的 struct ,其中指向特定构件的路径是根据其组ID、构件ID和版本构建的.您描述的 struct 似乎是Gradle缓存 struct 的直接传输,这是不同的.
对于Gradle插件,预期的Maven存储库布局通常如下所示:
com/android/application/<version>/com.android.application-<version>.jar
或者,对于Gradle插件标记构件,Gradle使用该构件将插件ID映射到实际构件:
com/android/application/com.android.application.gradle.plugin/<version>/com.android.application.gradle.plugin-<version>.pom
.pom
文件应该定义对实际插件JAR构件的依赖关系,然后将其存储在与第一个示例类似的路径中.
根据错误消息和您的描述,Gradle似乎无法解析插件,因为它正在寻找遵循此 struct 的标记构件,但在指定的存储库中找不到它.相反,ArtiFactory中的 struct 应该反映Maven布局,因为Gradle插件是以与Maven存储库兼容的方式发布的.
您可能需要重新组织Artifactory中的插件工件以匹配Maven struct .对于com.android.application
插件版本8.2.1
,Artifactory中的 struct 应该更像这样:
com/android/application/com.android.application.gradle.plugin/8.2.1/com.android.application.gradle.plugin-8.2.1.pom
并确保.pom
文件指向正确的JAR文件,该文件也应该在您的ArtiFactory中插件的组和构件ID路径下可用.这可能需要手动将插件JAR及其.pom
文件上传到ArtiFactory的正确位置,如果您还没有这样做的话.
请记住,实际插件的JAR文件也应该存在于存储库中,并被.pom
文件正确引用,这可能需要在com/android/application/
下为插件的JAR构件添加另一个条目,遵循Maven约定.