我有一个简单的插件与greet任务做一些'Hello World‘打印。
plugins {
id 'java-gradle-plugin'
id 'groovy'
id 'maven-publish'
}
group = 'standalone.plugin2.greeting'
version = '1.0'
gradlePlugin {
plugins {
greeting {
id = 'standalone.plugin2.greeting'
implementationClass = 'standalone.plugin2.StandalonePlugin2Plugin'
}
}
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'standalone.plugin2.greeting'
version = '1.0'
from components.java
}
}
}现在,我有了运行greet task的runner应用程序
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'standalone.plugin2.greeting:standalone-plugin2:1.0'
}
}
apply plugin: 'standalone.plugin2.greeting'使用apply plugin natation可以正常工作,但当我使用插件表示法时,如下所示:
plugins {
id 'standalone.plugin2.greeting' version '1.0'
}它不起作用。
错误消息为:
* What went wrong:
Plugin [id: 'standalone.plugin2.greeting', version: '1.0'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'standalone.plugin2.greeting:standalone.plugin2.greeting.gradle.plugin:1.0')
Searched in the following repositories:
Gradle Central Plugin Repository有什么关系?根据文档,apply plugin是旧的,不应该使用。
发布于 2020-07-07 18:31:59
在引入plugins块之前,必须使用repositories和dependencies的组合,以与常规项目依赖相同的方式来解决插件依赖。因为在运行实际的构建脚本之前需要解析它们,所以需要在特殊的buildscript块中定义它们:
buildscript {
repositories {
// define repositories for build script dependencies
}
dependencies {
// define build script dependencies (a.k.a. plugins)
}
}
repositories {
// define repositories for regular project dependencies
}
dependencies {
// define regular project dependencies
}一旦解决了依赖关系,就可以使用apply plugin:应用它们。
默认情况下,新的plugins块只解析来自Gradle Plugin Repository的插件。这是一个常规的Maven存储库,因此也可以使用旧方法使用它:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
}在您的例子中,插件只存在于mavenLocal中,所以plugins块不能解析它,因为它只查看Gradle Central插件存储库。您可以使用resolve plugins from custom repositories的pluginManagement块。
正如上面链接的文章中所描述的,有必要在插件标识符(在plugins块中使用)和提供相应插件的Maven坐标之间创建一个链接。要创建此链接,必须发布遵循特定约定的标记工件。如果与Maven Publish Plugin结合使用,Gradle Plugin Development Plugin会自动发布此标记工件。
https://stackoverflow.com/questions/62772073
复制相似问题