Greetings. I’ve created two convention/script plugins that I have successfully published to a Google Artifacts Registry of type Maven repo. This entails using a Google plugin that handles things like authentication, etc. Publishing works fine, and I end up with the jar file published and Google tells me the POM looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.test</groupId>
<artifactId>build-logic</artifactId>
<version>0.3</version>
</project>
As mentioned, my plugins are script convention plugins. This is the src/main/groovy/build.gradle
for the plugins:
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
}
dependencies {
implementation "org.springframework.boot:spring-boot-gradle-plugin:3.1.5"
}
The plugins themselves look like this:
src/main/groovy/java-conventions.gradle
:
plugins {
id 'java'
}
java {
sourceCompatibility = JavaVersion.VERSION_21
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
compileOnly "org.projectlombok:lombok:1.18.30"
annotationProcessor "org.projectlombok:lombok:1.18.30"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.0"
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.0"
}
tasks.named('test') {
useJUnitPlatform()
testLogging.showStandardStreams = true
}
and src/main/groovy/spring-conventions.gradle
:
plugins {
id 'java-conventions'
id('org.springframework.boot')
}
dependencies {
implementation('org.springframework.boot:spring-boot-gradle-plugin:3.1.5')
implementation 'org.springframework.boot:spring-boot-starter-actuator:3.1.5'
implementation 'org.springframework.boot:spring-boot-starter-webflux:3.1.5'
implementation 'jakarta.validation:jakarta.validation-api:3.0.2'
testImplementation 'org.springframework.boot:spring-boot-testcontainers:3.1.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.1.5'
testImplementation 'org.springframework.boot:spring-boot-test:3.1.5'
testImplementation 'io.projectreactor:reactor-test:3.5.11'
testImplementation 'org.testcontainers:junit-jupiter:1.19.1'
}
The project compiles fine, and I’m able to publish it to the GCP Artifacts Registry without problems. The issue arises when I’m trying to use the plugins in a different project. Because accessing the GCP Artifacts Registry requires authentication, etc., there’s a Google Gradle plugin that must be used for “bootstrapping”. After a lot of googling for this is sort of scenario, I found an article that suggested something like this in the settings.gradle
file:
pluginManagement{
repositories{
maven {
url = "artifactregistry://us-west1-maven.pkg.dev/<my-secret-project>/maven"
}
gradlePluginPortal()
mavenLocal()
}
}
dependencyResolutionManagement {
repositories {
maven {
url "https://us-west1-maven.pkg.dev/<my-secret-project>/maven"
}
mavenCentral()
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
mavenLocal()
}
}
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
dependencies {
classpath("gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:latest.release")
}
}
apply plugin: "com.google.cloud.artifactregistry.gradle-plugin"
In my build.gradle
file, I have:
plugins {
id 'java-conventions' version '0.3'
}
So a few details here. If I change my build.gradle
file to simply declare the jar file containing my plugin (that lives in GCP Artifact Registry) as a dependency, I’m able to successfully have Gradle pull it down. So that means that my repo config with the Google plugin, etc. works. I can see that it successfully pulls down the jar file. What puzzles me is what should the plugin id be? I’ve tried a gazillion different variants with/without the artifact name, the package, etc. I’ve even tried to specifically name it in the project that publishes the plugin jar, but no matter what I try, it fails with the same error:
Plugin [id: 'java-conventions', version: '0.3'] was not found in any of the following sources:
- Gradle Core Plugins (not a core plugin. For more available plugins, please refer to https://docs.gradle.org/8.4/userguide/plugin_reference.html in the Gradle documentation.)
- Plugin Repositories (could not resolve plugin artifact 'java-conventions:java-conventions.gradle.plugin:0.3')
Searched in the following repositories:
maven(https://us-west1-maven.pkg.dev/<my-secret-project>/maven)
Gradle Central Plugin Repository
MavenLocal(file:/Users/<my-secret-user>/.m2/repository/)