简体   繁体   English

在 Maven 本地存储库中找不到自定义 Gradle 插件

[英]Unable to find Custom Gradle Plugin in Maven Local repository

I am writing one custom Gradle plugin to add common resource for all project.我正在编写一个自定义 Gradle 插件来为所有项目添加公共资源。 For example all microservices uses SpringBoot web, sleuth and other common dependencies.比如所有微服务都使用SpringBoot web、sleuth等常用依赖。

So decide that will create a standalone project and will export plugin as jar and then will apply plugin for other project.因此决定将创建一个独立项目并将插件导出为 jar 然后将插件应用于其他项目。

Following is piece of code build.gradle.以下是一段代码 build.gradle。 in test-common is the another plugin that contains information about repo and publishing.在 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");
    }
}

now when I build and publish this gradle project then it create one jar in maven repo which contains META-INF/gradle.plugins/test.resource-plugin.properties and source folder has java file. now when I build and publish this gradle project then it create one jar in maven repo which contains META-INF/gradle.plugins/test.resource-plugin.properties and source folder has java file.

Now the second part to apply this plugin to other project.现在是将此插件应用到其他项目的第二部分。

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


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

}

but when I am trying to build this project, it does not find this plugin and says.但是当我尝试构建这个项目时,它没有找到这个插件并说。

* 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')

Can someone help on this?有人可以帮忙吗? What step I am missing here.我在这里缺少什么步骤。

I found the root cause for this issue and it has been resolved.我找到了这个问题的根本原因,并且已经解决。 and I just need to add following properties in settings.gradle file of project that wants to use it.我只需要在想要使用它的项目的 settings.gradle 文件中添加以下属性。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM