【问题标题】:Unable to find Custom Gradle Plugin in Maven Local repository无法在 Maven 本地存储库中找到自定义 Gradle 插件
【发布时间】:2021-04-18 02:15:21
【问题描述】:

我正在编写一个自定义 Gradle 插件来为所有项目添加公共资源。 比如所有的微服务都使用SpringBoot web、sleuth等常见的依赖。

因此决定创建一个独立项目并将插件导出为 jar,然后将插件应用于其他项目。

下面是一段代码 build.gradle 。在 test-common 中是另一个包含 repo 和发布信息的插件。

plugins {
    id 'java-gradle-plugin'
    id 'test-common'
}

gradlePlugin {
    plugins {
        simplePlugin {
            id = 'test.resource-plugin'
            implementationClass = 'com.test.CommonResource'
        }
    }
}
public class CommonResourcesPlugin implements Plugin<Project> {
    @Override
    public void apply(Project project) {
        var dependencySet= project.getConfigurations().getByName("compile").getDependencies();
        log.info("Applying depdencies");
        project.getDependencies().add("implementation", "org.springframework.boot:spring-boot-starter-web");
        project.getDependencies().add("implementation", "org.springframework.boot:spring-boot-starter-actuator");
    }
}

现在当我构建和发布这个 gradle 项目时,它会在 maven repo 中创建一个 jar,其中包含 META-INF/gradle.plugins/test.resource-plugin.properties 并且源文件夹有 java 文件。

现在是将此插件应用到其他项目的第二部分。

plugins {
    id "test.resource-plugin" version '1.0-SNAPSHOT'
}


dependencies {
    implementation "com.test:test-starter-plugin:1.0-SNAPSHOT"

}

但是当我尝试构建这个项目时,它没有找到这个插件并说。

* Exception is:
org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'test.resource-plugin', version: '1.0-SNAPSHOT'] 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 'test-starter-plugin:test-starter-plugin.gradle.plugin:1.0-SNAPSHOT')

有人可以帮忙吗?我在这里缺少什么步骤。

【问题讨论】:

    标签: java maven gradle


    【解决方案1】:

    我找到了这个问题的根本原因,并且已经解决。 我只需要在想要使用它的项目的 settings.gradle 文件中添加以下属性。

    pluginManagement {
      repositories {
          mavenLocal()
          gradlePluginPortal()
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-17
      • 2015-08-27
      • 2021-10-14
      • 2014-08-10
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 1970-01-01
      相关资源
      最近更新 更多