Why get http 401 error when publish android library to maven

I develop a android library and want to use gradle to publish it to my own maven repo.

Task ‘uploadArchives’ run successfully on my computer. However, run fail on jenkins server. I compare 2 gradle log and found difference.

  • Log on my computer:
    Re-using cached ‘basic’ auth scheme for http://xxx
    Target auth state: CHALLENGED
    Proxy auth state: UNCHALLENGED
    Attempt 1 to execute request
    Sending request: PUT /nexus/content/repositories/xxx HTTP/1.1
    Receiving response: HTTP/1.1 201 Created

  • Log on jenkins server:
    Auth cache not set in the context
    Target auth state: UNCHALLENGED
    Proxy auth state: UNCHALLENGED
    Attempt 1 to execute request
    Sending request: PUT /nexus/content/repositories/xxx.jar HTTP/1.1
    Receiving response: HTTP/1.1 401 Unauthorized

I use plugin ‘maven’ to publish. The publish gradle file is like below:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://url_to_maven") {
                authentication(userName: "xxx", password: "xxx")                 
            }
           
            pom.project {
                version publishVersion
                artifactId PROJ_ARTIFACT_ID
                groupId PROJ_GROUP_ID
                packaging PROJ_PACKAGING
                description PROJ_DESCRIPTION
            }
        }
    }
}

Why 401?

I use gradle version 4.2
Who can help me with this issue? Is it related to “pre-emptive authorization”.

I also found some log:
17:36:47.151 [DEBUG] [org.apache.http.impl.conn.DefaultClientConnection] Receiving response: HTTP/1.1 401 Unauthorized
17:36:47.151 [DEBUG] [org.apache.http.impl.client.DefaultHttpClient] Connection can be kept alive indefinitely
17:36:47.151 [DEBUG] [org.apache.http.impl.client.DefaultHttpClient] Authentication required
17:36:47.151 [DEBUG] [org.apache.http.impl.client.DefaultHttpClient] maven.xxx:80 requested authentication
17:36:47.151 [DEBUG] [org.apache.http.impl.client.TargetAuthenticationStrategy] Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
17:36:47.151 [DEBUG] [org.apache.http.impl.client.TargetAuthenticationStrategy] Challenge for Negotiate authentication scheme not available
17:36:47.151 [DEBUG] [org.apache.http.impl.client.TargetAuthenticationStrategy] Challenge for Kerberos authentication scheme not available
17:36:47.151 [DEBUG] [org.apache.http.impl.client.TargetAuthenticationStrategy] Challenge for NTLM authentication scheme not available
17:36:47.151 [DEBUG] [org.apache.http.impl.client.TargetAuthenticationStrategy] Challenge for Digest authentication scheme not available