keepmoving
keepmoving

Reputation: 2043

Unable to find Custom Gradle Plugin in Maven Local repository

I am writing one custom Gradle plugin to add common resource for all project. For example all microservices uses SpringBoot web, sleuth and other common dependencies.

So decide that will create a standalone project and will export plugin as jar and then will apply plugin for other project.

Following is piece of code build.gradle . in test-common is the another plugin that contains information about repo and publishing.

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 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.

Upvotes: 5

Views: 2301

Answers (1)

keepmoving
keepmoving

Reputation: 2043

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.

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

Upvotes: 7

Related Questions