Custom Gradle plugin JAR dependencies are not loaded

Hi there,

I have created a java library that is published to the maven snapshot repo. Then I created a Gradle plugin that has a dependency to this java library. The gradle plugin is published to the Gradle plugin portal. Now I want to use the gradle plugin in a new project, but the java library can´t get loaded:

Could not find io.elementals.pevatron:pevatron:1.0-alpha-SNAPSHOT.
Searched in the following locations:
  - https://plugins.gradle.org/m2/io/elementals/pevatron/pevatron/1.0-alpha-SNAPSHOT/maven-metadata.xml
  - https://plugins.gradle.org/m2/io/elementals/pevatron/pevatron/1.0-alpha-SNAPSHOT/pevatron-1.0-alpha-SNAPSHOT.pom
  - https://plugins.gradle.org/m2/io/elementals/pevatron/pevatron/1.0-alpha-SNAPSHOT/pevatron-1.0-alpha-SNAPSHOT.jar
Required by:
    project : > org.examples.greeting:org.examples.greeting.gradle.plugin:1.4.1 > gradle.plugin.greeting-plugin:greeting-plugin:1.4.1

It seems that the URL of the java library is wrong, but I have no clue where this comes from?! I investigated already a lot of time, but couldn´t find a solution. What am I missing?

Java library:
https://oss.sonatype.org/content/repositories/snapshots/io/elementals/pevatron/pevatron/

/**
 * Used plugins
 */
plugins {
    id 'java-library'
    id 'application'
    id 'signing'
    id 'maven-publish'
}

/**
 * Project settings
 */
group = 'io.elementals.pevatron'
mainClassName = "io.elementals.pevatron.PevatronRunner" // For running as application
sourceCompatibility = 1.8
// version = '1.0'
// version = '1.0-alpha'
version = '1.0-alpha-SNAPSHOT'

/**
 * Used repositories
 */
repositories {
    mavenCentral()
}

/**
 * Necessary dependencies
 */
dependencies {
    implementation 'org.apache.logging.log4j:log4j-api:2.11.0'
    implementation 'org.apache.logging.log4j:log4j-core:2.11.0'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation 'net.sourceforge.htmlunit:htmlunit:2.28'
    implementation 'net.sourceforge.cssparser:cssparser:0.9.24'
    testImplementation 'junit:junit:4.11'
}

/**
 * Task configuration
 */
task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    classifier 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    classifier 'javadoc'
}

compileJava {
    // Avoid annotation processors warning (caused by log4j) in Gradle 5+
    options.compilerArgs += '-proc:none'
}

jar {
    manifest {
        attributes(
                'Implementation-Title' : project.name,
                'Implementation-Version' : project.version,
                'Implementation-Vendor' : 'elementals.io',
                'Main-Class': 'io.elementals.pevatron.PevatronRunner'
        )
    }
}

/**
 * Configuration for publishing to Maven artifact repository
 */
// Plugin configuration for Maven Central publishing
// https://oss.sonatype.org/service/local/staging/deploy/maven2/ ===> ?
publishing {
    publications {
        pevatronLibrary(MavenPublication) {
            artifactId project.name
            from components.java
            artifact sourcesJar
            artifact javadocJar
            pom {
                name = 'Pevatron'
                description = 'Static website accelerator'
                url = 'https://elementals.io/pevatron/'
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'elementals'
                        name = 'elementals.io'
                        email = 'admin@elementals.io'
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/elementals-io/pevatron.git'
                    developerConnection = 'scm:git:ssh://github.com/elementals-io/pevatron.git'
                    url = 'https://github.com/elementals-io/pevatron/'
                }
            }
        }
    }

    repositories {
        maven {
            // def releasesRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots"
            // def snapshotsRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
            // url version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl
            url 'https://oss.sonatype.org/content/repositories/snapshots'
            credentials {
                username "${pevatron_maven_user}"
                password "${pevatron_maven_password}"
            }
        }
    }
}

/**
 * Signing for publishing to artifact repository
 */
signing {
    sign publishing.publications.pevatronLibrary
}

Gradle plugin:
https://plugins.gradle.org/plugin/org.examples.greeting

plugins {
    // id 'java'
    id 'java-gradle-plugin'
    id 'com.gradle.plugin-publish' version '0.9.10'
}

group 'greeting-plugin'
version '1.4.4'

sourceCompatibility = 1.8

compileJava {
    // Avoid annotation processors warning (caused by log4j) in Gradle 5+
    options.compilerArgs += '-proc:none'
}

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
}

dependencies {
    // compile gradleApi()
    implementation 'io.elementals.pevatron:pevatron:1.0-alpha-SNAPSHOT'
}

gradlePlugin {
    plugins {
        greetingsPlugin {
            id = 'org.examples.greeting'
            implementationClass = 'org.example.greeting.GreetingPlugin'
        }
    }
}

pluginBundle {
    website = 'http://www.gradle.org/'
    vcsUrl = 'https://github.com/gradle-guides/greeting-plugin-example'

    plugins {
        greetingsPlugin {
            id = 'org.examples.greeting'
            displayName = 'Gradle Guides Example Greeting Plugin'
            description = 'The Greeting plugin is used as a template for people to start their own plugin adventure'
            tags = ['example','template','greeting']
            version = project.version
        }
    }
}

Test project:

/**
 * Used plugins
 */
plugins {
    // id "io.elementals.pevatron" version "0.0.1"
    id "java"
    id "org.examples.greeting" version "1.4.1"
}

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots'
    }
}

Harald

Solved it on my own.

For those who may have similar issues when using JAR dependencies within custom gradle plugins using ‘java-gradle-plugin’ and ‘com.gradle.plugin-publish’:

I found a small hint in an example under https://plugins.gradle.org/docs/publish-plugin which says “If your plugin has any external java dependencies, Gradle will attempt to downloaded them from JCenter for anyone using the plugins DSL so you should probably use JCenter for dependency resolution in your own project.”.

Publishing the Java library that is used from within the custom plugin to Bintray and syncing it to JCenter, solved the issue.