Cannot publish Gradle project to Nexus repository

Hello everybody, I have the following build.gradle file.

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

group 'org.example'
version '2.0'
sourceCompatibility = 1.8

publishing {
    publications {
        maven(MavenPublication){
            artifact ("build/libs/my_maven_app-$version"+".jar"){
                extension "jar"
            }
        }
        }

    repositories {
        maven {
            name 'nexus'
            url 'nexus(http://167.71.41.177:8081/repository/maven-snapshots/)'
//            credentials {
//                username project.repoUser
//                password project.repoPassword
//            }
        }
    }
}


repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
    implementation group: 'com.cisco.oss.foundation', name: 'configuration-api', version: '1.1.0-1'
    implementation group: 'org.codehaus.sonar-plugins.python', name: 'python-squid', version: '1.5'
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'


}

test {
    useJUnitPlatform()
}

and I am trying to push it to the maven repository on Nexus.

I can execute command ./gradlew publish and it gives the following result on the terminal of Intellij IDEA.

\King Julien$ ./gradlew publish

BUILD SUCCESSFUL in 630ms
2 actionable tasks: 2 executed

and also I can see that directory is being created on Intellij with my remote destination address of the Maven repo. ( Screenshot attached)

Meanwhile, when I go to the root directory of my code and execute the same command I receive the following.

\King Julien$ ./gradlew publish

FAILURE: Build failed with an exception.

  • What went wrong:

Task ‘publish’ not found in root project ‘java-app-master’.

  • Try:

Run gradlew tasks to get a list of available tasks.

Run with --stacktrace option to get the stack trace.

Run with --info or --debug option to get more log output.

Run with --scan to get full insights.

BUILD FAILED in 575ms

this never happened to me before

Besides that you really should never use paths, but proper model your build, so do not use artifact ("build/libs/my_maven_app-$version"+".jar"){ extension "jar" }, but simply from(components["java"]),
the URL of your publishing repository is simply wrong.
You configured nexus(http://167.71.41.177:8081/repository/maven-snapshots/) which is not a valid URL, so it is interpreted as a relative path and is created as thus as you can see.
Remove the nexus( and the ) and it will probably work as expected.

And about publish not being found, you probably call the command in the wrong directory or similar, but hard to guess from the information you provided.