How to hide the nexus username and password, when publish artifacts to nexus

Following this post How do I configure my Gradle build to publish artifacts to Nexus? – Sonatype Support

I can successfully publish grade (uploadArchives) to a private nexus repository. But it has to provide the username and password

I try to set it in ~/.gradle/, but not sure how to do that.

So how to hide that nexus username and password?

Got the solution from official document for this problem

with mine

$ more build.gradle
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'maven'

repositories {
    maven {
          url "${nexusUrl}/content/groups/public"

dependencies {

uploadArchives {
    repositories {
       mavenDeployer {
             repository(url: "${nexusUrl}/content/repositories/snapshots") {
             authentication(userName: nexusUsername, password: nexusPassword)

you can save the username and password in ~/.gradle/

$ cat ~/.gradle/