无法解析 Gradle 脚本插件中的插件(外部 Gradle 文件)
Unable to resolve plugin in Gradle Script plugin (external Gradle file)
我正在尝试将一些 JFrog 发布代码从我的 build.gradle
干燥到外部文件(Gradle 脚本插件)(我在不同的 Gradle 中复制了它)项目)。
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
}
}
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
publishing {
publications {
wpJFrogMaven(MavenPublication) {
// Code removed for brevity
}
}
}
// Code removed for brevity
我在实际项目的主要 build.gradle
末尾使用这个 Gradle 脚本插件-
apply from: "https://raw.githubusercontent.com/wizpanda/gradle-common/main/grails-plugin-jfrog-publish.gradle"
当我 运行 任何 Gradle 任务如- ./gradlew artifactoryPublish
,它失败并显示错误-
FAILURE: Build failed with an exception.
* Where:
Script 'https://raw.githubusercontent.com/wizpanda/gradle-common/06a497b62fb4bb86facd96375bad1d91a67545d1/grails-plugin-jfrog-publish.gradle' line: 14
* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.jfrog.artifactory' not found.
但是如果我在项目的 build.gradle
主文件中定义相同的 buildscript
配置和插件,它工作正常。
我已经花了 3-4 个小时调试它并阅读了各种文章、博客和文档-
- https://plugins.gradle.org/plugin/com.jfrog.artifactory
- https://github.com/gradle/gradle/issues/14517
- https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:using_methods
- https://docs.gradle.org/current/userguide/plugins.html#:~:text=Script%20plugins%20are%20automatically%20resolved,applied%20to%20a%20given%20target.
- (示例)https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle
- https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016
- https://docs.gradle.org/current/userguide/init_scripts.html?_ga=2.152768569.1473794243.1621063281-1685601076.1621063281
我错过了什么愚蠢的东西吗?
在外部构建脚本中不支持通过 id 应用。备选方案:
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
不幸的是,如果您通过 ID 引用第三方插件,则无法在外部 Gradle 脚本插件中传递应用。
您将不得不通过实现来引用插件-class。
有一个open ticket regarding this issue。
您可以在 following PR 中看到必要的更改。
apply plugin: 'com.jfrog.artifactory'
进入
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
我正在尝试将一些 JFrog 发布代码从我的 build.gradle
干燥到外部文件(Gradle 脚本插件)(我在不同的 Gradle 中复制了它)项目)。
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.21.0"
}
}
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
publishing {
publications {
wpJFrogMaven(MavenPublication) {
// Code removed for brevity
}
}
}
// Code removed for brevity
我在实际项目的主要 build.gradle
末尾使用这个 Gradle 脚本插件-
apply from: "https://raw.githubusercontent.com/wizpanda/gradle-common/main/grails-plugin-jfrog-publish.gradle"
当我 运行 任何 Gradle 任务如- ./gradlew artifactoryPublish
,它失败并显示错误-
FAILURE: Build failed with an exception.
* Where:
Script 'https://raw.githubusercontent.com/wizpanda/gradle-common/06a497b62fb4bb86facd96375bad1d91a67545d1/grails-plugin-jfrog-publish.gradle' line: 14
* What went wrong:
A problem occurred evaluating script.
> Plugin with id 'com.jfrog.artifactory' not found.
但是如果我在项目的 build.gradle
主文件中定义相同的 buildscript
配置和插件,它工作正常。
我已经花了 3-4 个小时调试它并阅读了各种文章、博客和文档-
- https://plugins.gradle.org/plugin/com.jfrog.artifactory
- https://github.com/gradle/gradle/issues/14517
- https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:using_methods
- https://docs.gradle.org/current/userguide/plugins.html#:~:text=Script%20plugins%20are%20automatically%20resolved,applied%20to%20a%20given%20target.
- (示例)https://raw.githubusercontent.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle
- https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016
- https://docs.gradle.org/current/userguide/init_scripts.html?_ga=2.152768569.1473794243.1621063281-1685601076.1621063281
我错过了什么愚蠢的东西吗?
在外部构建脚本中不支持通过 id 应用。备选方案:
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
不幸的是,如果您通过 ID 引用第三方插件,则无法在外部 Gradle 脚本插件中传递应用。
您将不得不通过实现来引用插件-class。
有一个open ticket regarding this issue。
您可以在 following PR 中看到必要的更改。
apply plugin: 'com.jfrog.artifactory'
进入
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin