Skip to content
Advertisement

Gradle : Failed to notify build listener

When we build our application using gradle, it is throwing the exception below .Following is the build.gradle code:

buildscript {
    repositories{
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
        classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
    }
}

apply plugin: "idea"
apply plugin: "java-library"
apply plugin: "maven-publish"
apply plugin: "com.jfrog.artifactory"
apply plugin: "io.spring.dependency-management"

group = "com.xx.ff"
version = "2.1.5-SNAPSHOT"

wrapper {
    gradleVersion = "6.5"
    distributionType = Wrapper.DistributionType.ALL
}

repositories {
    jcenter()
    if (System.getenv('ARTIFACTORY_USER') == null || System.getenv('ARTIFACTORY_PASSWORD') == null) {
        logger.warn("Please set environment variables ARTIFACTORY_USER and ARTIFACTORY_PASSWORD")
    }
    maven {
        name "libs-snapshot"
        url "https://vvvvvvvvvvvvvvvv/artifactory/libs-snapshot/"
        credentials {
            username = System.getenv('ARTIFACTORY_USER')
            password = System.getenv('ARTIFACTORY_PASSWORD')
        }
    }
    maven {
        name "libs-release"
        url "https://vvvvvvvvvvvvvvvvvvvvvvvvvv/artifactory/libs-release/"
        credentials {
            username = System.getenv('ARTIFACTORY_USER')
            password = System.getenv('ARTIFACTORY_PASSWORD')
        }
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

 idea.module {
    outputDir file("build/classes/java/main")
    testOutputDir file("build/classes/java/test")
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
    }
}

dependencies {
    api("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
    api("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springBootVersion}")
    implementation("javax.validation:validation-api:${validationVersion}")
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = "libs-snapshot-local"
            username = System.getenv('ARTIFACTORY_USER')
            password = System.getenv('ARTIFACTORY_PASSWORD')
            maven = true

        }
        defaults {
            publications("mavenJava")
        }
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

I am getting the below error : Build file, line: 81

Failed to notify build listener.

‘org.gradle.api.file.FileCollection org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal.getPublishableFiles()’

Can anyone help me please ?

Advertisement

Answer

For future readers who stumble upon this error.

I’ve been piece mealing together a working jfrog publish from here:

Gradle Artifactory Plugin – How to publish artifacts from multiple modules in a project?

I got the error, then realized I was not using android.

I got this error when I had this:

publishing {
    publications {
        Android(MavenPublication) {
            groupId "${projectGroupName}"
            artifactId 'MyFirstArtifactId'
            version "${projectVersionName}"
            artifact "$buildDir/blah/blah/mything-1.0-SNAPSHOT.jar"
        }
    }
}

and changed “Android” to “mavenJava” as seen below.

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId "${projectGroupName}"
            artifactId 'MyFirstArtifactId'
            version "${projectVersionName}"
            artifact "$buildDir/blah/blah/mything-1.0-SNAPSHOT.jar"
        }
    }
}

My only other hint is that i have this. keep in mind i have a multi-module gradle project and i do not want to artifactory-publish the root module.

subprojects {
    apply plugin: 'java-library'
    apply plugin: "maven-publish"
}

So my in general idea is : are you missing an apply-plugin ?

Documentation:

https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:complete_example

=========

Another Hint Project:

https://github.com/foragerr/SO-35851251-Multiproject-Artifactory-Publish

=========

Another longer answer I posted:

How do I generate maven-metata.xml with maven-publish and the artifactory-gradle-plugin?

=========

Just a reminder for newbies.

https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html

below is example code from url just above:

publishing {
  publications {
    myPublicationName(MavenPublication) {
      // Configure the publication here
    }
  }
}

this is one reason why using “keywords” for the “myPublicationName” make it harder to discern.

=========

https://gradle.github.io/gradle-script-kotlin-docs/userguide/publishing_maven.html

publishing { publications { mavenJava(MavenPublication) { from(components.java) } } }

I’m still trying to figure out if mavenJava is just another name (like “myPublishingName” and the ‘from’ is the more important part. or it is a special name / reserved keyword.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement