{"id":531,"date":"2014-04-21T14:52:16","date_gmt":"2014-04-21T19:52:16","guid":{"rendered":"http:\/\/tiemensfamily.com\/TimOnCS\/?p=531"},"modified":"2014-04-21T14:52:16","modified_gmt":"2014-04-21T19:52:16","slug":"gradle-with-local-archiva-publish","status":"publish","type":"post","link":"https:\/\/tiemensfamily.com\/timoncs\/2014\/04\/21\/gradle-with-local-archiva-publish\/","title":{"rendered":"Gradle with Local Archiva Publish"},"content":{"rendered":"<p>This shows the way to get gradle to use a local Archiva server to publish your project artifacts.<\/p>\n<p><b>IMPORTANT<\/b>: You must configure your &#8220;guest&#8221; user in Archiva to have the correct permissions (roles) to publish to the Archiva server.  To do this, in the Archiva WebUI (the default is http:\/\/localhost:8080), on the left side under &#8220;USERS&#8221;, click &#8220;Manage&#8221;, then click the blue pencil next to &#8220;guest&#8221;, then click the &#8220;Edit Roles&#8221; (next to the blue &#8220;Edit&#8221; button), then checkbox select &#8220;Global Repository Manager&#8221; and &#8220;Global Repository Observer&#8221; and press Update.<\/p>\n<p>Interesting fact: Archiva will accept &#8220;SNAPSHOT&#8221; artifacts into its &#8220;internal&#8221; repository (i.e. the upload will succeed, and Archiva will store the artifacts in its &#8220;\/repositories\/internal\/&#8221; directory).  BUT it will not serve these artifacts, saying instead &#8220;managed repo is configured for release only&#8221;.  If you accidentally publish SNAPSHOT artifacts to the &#8220;internal&#8221; repository, then you&#8217;ll have to clean your &#8220;\/repositories\/internal\/&#8221; directory by hand &#8211; the WebUI won&#8217;t let you.<\/p>\n<p>So, given that interesting fact, the &#8220;if&#8221; logic (below) looks for &#8220;SNAPSHOT&#8221; and sets the url to the correct location.  Note that the single &#8220;maven { }&#8221; entry is different from how it was configured for resolving, where there were two entries. (See  <a href=\"TimOnCS\/2014\/04\/16\/gradle-with-local-archiva\/\">Gradle with Local Archiva<\/a>).<\/p>\n<p>This shows the correct &#8216;publishing&#8217; section of your build.gradle file for publishing to your local Archiva server.  This also shows how to publish your &#8220;-sources&#8221; artifact.  Feel free to substitute &#8220;localhost&#8221; for the actual machine name or IP address of your Archiva server.<\/p>\n<p>(2014\/6\/10 update: added ext.isReleaseVersion and added checks before using the .publishBaseUrl property before using it.)<\/p>\n<p>Versions:<br \/>\narchiva: 2.0.1<br \/>\ngradle: 1.11<\/p>\n<pre class=\"prettyprint\">\n\/\/ Used in publishing - the new plugin:\napply plugin: 'maven-publish'\n\n\/\/ Used in publishing - pom information: \ngroup =  'com.tiemens'\nversion =  '0.1-SNAPSHOT'\nproject.ext.isReleaseVersion = !version.endsWith(\"SNAPSHOT\")\n\n\/\/ Used in publishing - source artifact: \ntask sourceJar(type: Jar) {\n    from sourceSets.main.allJava\n}\n\npublishing {\n    publications {\n        mavenJava(MavenPublication) {\n\n            from components.java\n\n            artifact sourceJar {\n                classifier \"sources\"\n            }\n        }\n    }\n\n    repositories {\n        maven {\n            if (project.hasProperty('publishBaseUrl')) {\n                if (! project.ext.isReleaseVersion) {\n                    url project.publishBaseUrl + \"\/snapshots\"\n                } else {\n                    url project.publishBaseUrl + \"\/internal\"\n                }\n            } else {\n                    \/\/ this is a notice that 'publish' requires .publishBaseUrl\n                    url \"http:\/\/you.must.configure.project.publishBaseUrl\"\n            }\n        }\n    }\n\n}\n<\/pre>\n<p>Just for documentation, this shows the error message you get if you don&#8217;t set up your guest user with the proper roles.<br \/>\n<code><br \/>\n$ gradle --debug publish<br \/>\n  ... snip ...<br \/>\n17:09:38.693 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@19507226 pairs: {PUT \/repository\/snapshots\/com\/tiemens\/CardWar\/0.5-SNAPSHOT\/CardWar-0.5-20140421.220938-1.jar HTTP\/1.1: null}{User-Agent: maven-artifact\/3.0.4 (Java 1.7.0_45; Linux 3.2.0-31-generic-pae)}{Host: sitearchiva:8080}{Accept: text\/html, image\/gif, image\/jpeg, *; q=.2, *\/*; q=.2}{Connection: keep-alive}{Content-Length: 21915}<br \/>\n17:09:38.703 [DEBUG] [sun.net.www.protocol.http.HttpURLConnection] sun.net.www.MessageHeader@10775136 pairs: {null: HTTP\/1.1 401 Unauthorized}{Date: Mon, 21 Apr 2014 22:09:38 GMT}{Set-Cookie: JSESSIONID=11ohtcvqtpqu3s9r3iis2a7c1;Path=\/}{WWW-Authenticate: Basic realm=\"Repository Archiva Managed snapshots Repository\"}{Content-Length: 0}{Server: Jetty(8.1.14.v20131031)}<br \/>\n17:09:38.737 [INFO] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:null] An error has occurred while processing the Maven artifact tasks.<br \/>\n Diagnosis:<\/p>\n<p>Error deploying artifact 'com.tiemens:CardWar:jar': Error deploying artifact: Failed to transfer file: http:\/\/sitearchiva:8080\/repository\/snapshots\/com\/tiemens\/CardWar\/0.5-SNAPSHOT\/CardWar-0.5-20140421.220938-1.jar. Return code is: 401<br \/>\n  ...snip...<br \/>\n<\/code><\/p>\n<p>More documentation links:<\/p>\n<p>Shows example using authentication, instead of using &#8220;guest&#8221; with publish role:<br \/>\n<a href=\"http:\/\/forums.gradle.org\/gradle\/topics\/maven_publish_and_setting_snapshotrepository_and_releaserepository\">http:\/\/forums.gradle.org\/gradle\/topics\/maven_publish_and_setting_snapshotrepository_and_releaserepository<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This shows the way to get gradle to use a local Archiva server to publish your project artifacts. IMPORTANT: You must configure your &#8220;guest&#8221; user in Archiva to have the correct permissions (roles) to publish to the Archiva server. To &hellip; <a href=\"https:\/\/tiemensfamily.com\/timoncs\/2014\/04\/21\/gradle-with-local-archiva-publish\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/531"}],"collection":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":0,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiemensfamily.com\/timoncs\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}