簡體   English   中英

在 Maven 本地存儲庫中找不到自定義 Gradle 插件

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

我正在編寫一個自定義 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");
    }
}

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.

現在是將此插件應用到其他項目的第二部分。

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

有人可以幫忙嗎? 我在這里缺少什么步驟。

我找到了這個問題的根本原因,並且已經解決。 我只需要在想要使用它的項目的 settings.gradle 文件中添加以下屬性。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM