Home > Mobile >  Error when building an app with Gradle - No signature of method: build_49q3y83g7hdxe5s51k5187z33.pub
Error when building an app with Gradle - No signature of method: build_49q3y83g7hdxe5s51k5187z33.pub

Time:07-08

I'm following a tutorial on publishing artifacts to Nexus and a simple Java app is used as an example. A Gradle file is provided and meant to be changed. In the end, it looks like this:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}

group 'com.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

apply plugin: 'maven-publish'

publishing {
    publications {
        maven(MavenPublication) {
            artifacts("build/libs/my-app-$version" ".jar") {
                extension = 'jar'
            }
        }   
    }

    repositories {
        maven {
            name'nexus'
            url "http://someip:someport/repository/maven-snapshots/"
            credentials {
                username project.repoUser
                password project.repoPassword
            }
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '5.2'
    testImplementation group: 'junit', name: 'junit', version: '4.12'
}

I when I use the command ./gradle build I get the following error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/matteo/Desktop/devops_bootcamp/java-app/build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'my-app'.
> No signature of method: build_49q3y83g7hdxe5s51k5187z33.publishing() is applicable for argument types: (build_49q3y83g7hdxe5s51k5187z33$_run_closure1) values: [build_49q3y83g7hdxe5s51k5187z33$_run_closure1@79692f52]

Gradle version: Gradle 7.4.2

What am I doing wrong?

CodePudding user response:

The "no signature of method" problem is a bug that happens when a closure can't compile. It should be fixed in the upcoming Gradle version 7.5.

The reason that it can't compile is because artifacts is a property and extension is a method (you have them both the other way around). There is also a method called artifact (in singular) that you probably want to use.

It is difficult to just guess what syntax to use, so check the documentation on it here.

There are various ways you can express this publication, but one is like the snippet below.

publications {
    maven(MavenPublication) {
        artifact("build/libs/my-app-$version" ".jar") {
            extension('jar')
        }
    }   
}
  • Related