Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best solution I've been able to find consists of these steps:</p> <ol> <li>Create a branch called <code>mvn-repo</code> to host your maven artifacts.</li> <li>Use the github <a href="https://github.com/github/maven-plugins#readme" rel="noreferrer">site-maven-plugin</a> to push your artifacts to github.</li> <li>Configure maven to use your remote <code>mvn-repo</code> as a maven repository.</li> </ol> <p>There are several benefits to using this approach:</p> <ul> <li>Maven artifacts are kept separate from your source in a separate branch called <code>mvn-repo</code>, much like github pages are kept in a separate branch called <code>gh-pages</code> (if you use github pages)</li> <li>Unlike some other proposed solutions, it doesn't conflict with your <code>gh-pages</code> if you're using them.</li> <li>Ties in naturally with the deploy target so there are no new maven commands to learn. Just use <code>mvn deploy</code> as you normally would</li> </ul> <p>The typical way you deploy artifacts to a remote maven repo is to use <code>mvn deploy</code>, so let's patch into that mechanism for this solution.</p> <p>First, tell maven to deploy artifacts to a temporary staging location inside your target directory. Add this to your <code>pom.xml</code>:</p> <pre class="lang-xml prettyprint-override"><code>&lt;distributionManagement&gt; &lt;repository&gt; &lt;id&gt;internal.repo&lt;/id&gt; &lt;name&gt;Temporary Staging Repository&lt;/name&gt; &lt;url&gt;file://${project.build.directory}/mvn-repo&lt;/url&gt; &lt;/repository&gt; &lt;/distributionManagement&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt; &lt;version&gt;2.8.1&lt;/version&gt; &lt;configuration&gt; &lt;altDeploymentRepository&gt;internal.repo::default::file://${project.build.directory}/mvn-repo&lt;/altDeploymentRepository&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; </code></pre> <p>Now try running <code>mvn clean deploy</code>. You'll see that it deployed your maven repository to <code>target/mvn-repo</code>. The next step is to get it to upload that directory to GitHub.</p> <p>Add your authentication information to <code>~/.m2/settings.xml</code> so that the github <code>site-maven-plugin</code> can push to GitHub:</p> <pre class="lang-xml prettyprint-override"><code>&lt;!-- NOTE: MAKE SURE THAT settings.xml IS NOT WORLD READABLE! --&gt; &lt;settings&gt; &lt;servers&gt; &lt;server&gt; &lt;id&gt;github&lt;/id&gt; &lt;username&gt;YOUR-USERNAME&lt;/username&gt; &lt;password&gt;YOUR-PASSWORD&lt;/password&gt; &lt;/server&gt; &lt;/servers&gt; &lt;/settings&gt; </code></pre> <p>(As noted, please make sure to <code>chmod 700 settings.xml</code> to ensure no one can read your password in the file. If someone knows how to make site-maven-plugin prompt for a password instead of requiring it in a config file, let me know.)</p> <p>Then tell the GitHub <code>site-maven-plugin</code> about the new server you just configured by adding the following to your pom:</p> <pre class="lang-xml prettyprint-override"><code>&lt;properties&gt; &lt;!-- github server corresponds to entry in ~/.m2/settings.xml --&gt; &lt;github.global.server&gt;github&lt;/github.global.server&gt; &lt;/properties&gt; </code></pre> <p>Finally, configure the <code>site-maven-plugin</code> to upload from your temporary staging repo to your <code>mvn-repo</code> branch on Github:</p> <pre class="lang-xml prettyprint-override"><code>&lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;com.github.github&lt;/groupId&gt; &lt;artifactId&gt;site-maven-plugin&lt;/artifactId&gt; &lt;version&gt;0.11&lt;/version&gt; &lt;configuration&gt; &lt;message&gt;Maven artifacts for ${project.version}&lt;/message&gt; &lt;!-- git commit message --&gt; &lt;noJekyll&gt;true&lt;/noJekyll&gt; &lt;!-- disable webpage processing --&gt; &lt;outputDirectory&gt;${project.build.directory}/mvn-repo&lt;/outputDirectory&gt; &lt;!-- matches distribution management repository url above --&gt; &lt;branch&gt;refs/heads/mvn-repo&lt;/branch&gt; &lt;!-- remote branch name --&gt; &lt;includes&gt;&lt;include&gt;**/*&lt;/include&gt;&lt;/includes&gt; &lt;repositoryName&gt;YOUR-REPOSITORY-NAME&lt;/repositoryName&gt; &lt;!-- github repo name --&gt; &lt;repositoryOwner&gt;YOUR-GITHUB-USERNAME&lt;/repositoryOwner&gt; &lt;!-- github username --&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase --&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;site&lt;/goal&gt; &lt;/goals&gt; &lt;phase&gt;deploy&lt;/phase&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; </code></pre> <p>The <code>mvn-repo</code> branch does not need to exist, it will be created for you.</p> <p>Now run <code>mvn clean deploy</code> again. You should see maven-deploy-plugin "upload" the files to your local staging repository in the target directory, then site-maven-plugin committing those files and pushing them to the server.</p> <pre><code>[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building DaoCore 1.3-SNAPSHOT [INFO] ------------------------------------------------------------------------ ... [INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ greendao --- Uploaded: file:///Users/mike/Projects/greendao-emmby/DaoCore/target/mvn-repo/com/greendao-orm/greendao/1.3-SNAPSHOT/greendao-1.3-20121223.182256-3.jar (77 KB at 2936.9 KB/sec) Uploaded: file:///Users/mike/Projects/greendao-emmby/DaoCore/target/mvn-repo/com/greendao-orm/greendao/1.3-SNAPSHOT/greendao-1.3-20121223.182256-3.pom (3 KB at 1402.3 KB/sec) Uploaded: file:///Users/mike/Projects/greendao-emmby/DaoCore/target/mvn-repo/com/greendao-orm/greendao/1.3-SNAPSHOT/maven-metadata.xml (768 B at 150.0 KB/sec) Uploaded: file:///Users/mike/Projects/greendao-emmby/DaoCore/target/mvn-repo/com/greendao-orm/greendao/maven-metadata.xml (282 B at 91.8 KB/sec) [INFO] [INFO] --- site-maven-plugin:0.7:site (default) @ greendao --- [INFO] Creating 24 blobs [INFO] Creating tree with 25 blob entries [INFO] Creating commit with SHA-1: 0b8444e487a8acf9caabe7ec18a4e9cff4964809 [INFO] Updating reference refs/heads/mvn-repo from ab7afb9a228bf33d9e04db39d178f96a7a225593 to 0b8444e487a8acf9caabe7ec18a4e9cff4964809 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 8.595s [INFO] Finished at: Sun Dec 23 11:23:03 MST 2012 [INFO] Final Memory: 9M/81M [INFO] ------------------------------------------------------------------------ </code></pre> <p>Visit github.com in your browser, select the <code>mvn-repo</code> branch, and verify that all your binaries are now there.</p> <p><img src="https://i.stack.imgur.com/RQUz0.png" alt="enter image description here"></p> <p><strong>Congratulations!</strong></p> <p>You can now deploy your maven artifacts to a poor man's public repo simply by running <code>mvn clean deploy</code>.</p> <p>There's one more step you'll want to take, which is to configure any poms that depend on your pom to know where your repository is. Add the following snippet to any project's pom that depends on your project:</p> <pre class="lang-xml prettyprint-override"><code>&lt;repositories&gt; &lt;repository&gt; &lt;id&gt;YOUR-PROJECT-NAME-mvn-repo&lt;/id&gt; &lt;url&gt;https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/mvn-repo/&lt;/url&gt; &lt;snapshots&gt; &lt;enabled&gt;true&lt;/enabled&gt; &lt;updatePolicy&gt;always&lt;/updatePolicy&gt; &lt;/snapshots&gt; &lt;/repository&gt; &lt;/repositories&gt; </code></pre> <p>Now any project that requires your jar files will automatically download them from your github maven repository.</p> <p>Edit: to avoid the problem mentioned in the comments ('Error creating commit: Invalid request. For 'properties/name', nil is not a string.'), make sure you state a name in your profile on github.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload