title: How to publish jar to Nexus(snapshot repository)?
body: <h1>What I want to achieve</h1>
  
  <p>I want to publish jar to Nexus snapshot repository.</p>
  
  <p>If you know how to realize, I would like to know.</p>
  
  <h1>Detail</h1>
  
  <p>I'm planning to publish Java project artifacts (jar) using Gradle from the Jenkins Pipeline to the Nexus3 artifact repository. (But on requirements
    I can not use the <code>maven-publish</code> plugin for<code>build.gradle</code>. Using <code>maven-publish</code> as<code>gradle publish</code>, I confirms that I can publish to the snapshot repository)</p>
  
  <p>I will publish jar from a Jenkins job.</p>
  
  <p>I would like to publish to <strong>snapshot repository</strong> , but I was not able to investigate / implement various things.</p>
  
  <h2>Survey / Confirmation</h2>
  
  <p>According to my research, it seems that there is already the following Jenkins Plugin</p>
  
  <ul>
  <li><a href="https://wiki.jenkins.io/display/JENKINS/Nexus+Artifact+Uploader" rel="nofollow noreferrer">Nexus Artifact Uploader</a></li>
  <li><a href="https://help.sonatype.com/integrations/nexus-and-continuous-integration/nexus-platform-plugin-for-jenkins" rel="nofollow noreferrer">Nexus Platform Plugin for Jenkins</a></li>
  </ul>
  
  <p>However, neither plug-in seems to support Publish to the snapshot repository. (I tried for a while, but I got an error)</p>
  
  <p>Also, calling API in the JenkinsPipeline script using <code>curl</code> was not permitted as follows:</p>
  
  <pre><code>        sh "curl -v -u admin:admin123 \
              -X POST http://localhost:8081/service/rest/v1/components?repository=maven=snapshots \
              -F maven2.groupId=${groupId} \
              -F maven2.artifactId=${artifactId} \
              -F maven2.version=${version} \
              -F maven2.asset1=build/libs/${artifactId}-${version}.jar \
              -F maven2.asset1.extension=jar \
              -F maven2.asset2=build/libs/${artifactId}-${version}.jar \
              -F maven2.asset2.classifier=javadoc \
              -F maven2.asset2.extension=jar \
              -F maven2.asset3=build/libs/${artifactId}-${version}.jar \
              -F maven2.asset3.classifier=sources \
              -F maven2.asset3.extension=jar"
          }
  </code></pre>
  
  <p><a href="https://support.sonatype.com/hc/en-us/articles/115006744008-How-can-I-programmatically-upload-files-into-Nexus-3-" rel="nofollow noreferrer">https://support.sonatype.com/hc/en-us/articles/115006744008-How-can-I-programmatically-upload-files-into-Nexus-3-</a></p>
  
  <p>The error message when curling is as follows.</p>
  
  <pre><code>* Server auth using Basic with user 'admin'
  &gt; POST /service/rest/v1/components?repository=maven-snapshots HTTP/1.1
  
  &gt; Host: localhost:8081
  
  &gt; Authorization: Basic YWRtaW46YWRtaW4xMjM=
  
  &gt; User-Agent: curl/7.55.1
  
  &gt; Accept: */*
  
  &gt; Content-Length: 1379
  
  &gt; Expect: 100-continue
  
  &gt; Content-Type: multipart/form-data; boundary=------------------------bea51339dc9456fe
  
  &gt; 
  
  &lt; HTTP/1.1 100 Continue
  
  } [1379 bytes data]
  &lt; HTTP/1.1 400 Bad Request
  
  &lt; Date: Sat, 13 Jul 2019 11:18:22 GMT
  
  &lt; Server: Nexus/3.17.0-01 (OSS)
  
  &lt; X-Content-Type-Options: nosniff
  
  &lt; Vary: Accept
  
  &lt; Content-Type: application/vnd.siesta-validation-errors-v1+json
  
  &lt; X-Siesta-FaultId: 2281dcfa-6583-456a-9970-318d54dd431b
  
  &lt; Content-Length: 93
  
  * HTTP error before end of send, stop sending
  &lt; 
  
  { [93 bytes data]
  
  100  1472  100    93  100  1379     93   1379  0:00:01 --:--:--  0:00:01  2944
  * Closing connection 0
  [{"id":"*","message":"Upload to snapshot repositories not supported, use the maven client."}][Pipeline] error
  </code></pre>
  
  <p>Thank you.</p>