I have a fork of a small open sourced library that I'm working on on github. I'd like to make it available to other developers via maven, but I don't want to run my own Nexus server, and because it's a fork I can't easily deploy it to oss.sonatype.org.
What I'd like to do is to deploy it to github so that others can access it using maven. What's the best way to do this?
The best solution I've been able to find consists of these steps:
mvn-repo
to host your maven artifacts.mvn-repo
as a maven repository.There are several benefits to using this approach:
mvn-repo
, much like github pages are kept in a separate branch calledgh-pages
(if you use github pages)gh-pages
if you're using them.mvn deploy
as you normally wouldThe typical way you deploy artifacts to a remote maven repo is to use
mvn deploy
, so let's patch into that mechanism for this solution.First, tell maven to deploy artifacts to a temporary staging location inside your target directory. Add this to your
pom.xml
:Now try running
mvn clean deploy
. You'll see that it deployed your maven repository totarget/mvn-repo
. The next step is to get it to upload that directory to GitHub.Add your authentication information to
~/.m2/settings.xml
so that the githubsite-maven-plugin
can push to GitHub:(As noted, please make sure to
chmod 700 settings.xml
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.)Then tell the GitHub
site-maven-plugin
about the new server you just configured by adding the following to your pom:Finally, configure the
site-maven-plugin
to upload from your temporary staging repo to yourmvn-repo
branch on Github:The
mvn-repo
branch does not need to exist, it will be created for you.Now run
mvn clean deploy
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.Visit github.com in your browser, select the
mvn-repo
branch, and verify that all your binaries are now there.Congratulations!
You can now deploy your maven artifacts to a poor man's public repo simply by running
mvn clean deploy
.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:
Now any project that requires your jar files will automatically download them from your github maven repository.
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.
Don't use GitHub as a Maven Repository.
Edit: This option gets a lot of down votes, but no comments as to why. This is the correct option regardless of the technical capabilities to actually host on GitHub. Hosting on GitHub is wrong for all the reasons outlined below and without comments I can't improve the answer to clarify your issues.
Best Option - Collaborate with the Original Project
The best option is to convince the original project to include your changes and stick with the original.
Alternative - Maintain your own Fork
Since you have forked an open source library, and your fork is also open source, you can upload your fork to Maven Central (read Guide to uploading artifacts to the Central Repository) by giving it a new
groupId
and maybe a newartifactId
.Only consider this option if you are willing to maintain this fork until the changes are incorporated into the original project and then you should abandon this one.
Really consider hard whether a fork is the right option. Read the myriad Google results for 'why not to fork'
Reasoning
Bloating your repository with jars increases download size for no benefit
A jar is an
output
of your project, it can be regenerated at any time from itsinputs
, and your GitHub repo should contain onlyinputs
.Don't believe me? Then check Google results for 'dont store binaries in git'.
GitHub's help Working with large files will tell you the same thing. Admittedly jar's aren't large but they are larger than the source code and once a jar has been created by a release they have no reason to be versioned - that is what a new release is for.
Defining multiple repos in your pom.xml slows your build down by Number of Repositories times Number of Artifacts
Stephen Connolly says:
That's right! Maven needs to check every artifact (and its dependencies) defined in your pom.xml against every Repository you have defined, as a newer version might be available in any of those repositories.
Try it out for yourself and you will feel the pain of a slow build.
The best place for artifacts is in Maven Central, as its the central place for jars, and this means your build will only ever check one place.
You can read some more about repositories at Maven's documentation on Introduction to Repositories
If you have only
aar
orjar
file itself, or just don't want to use plugins - I've created a simple shell script. You can achieve the same with it - publishing your artifacts to Github and use it as public Maven repo.Another alternative is to use any web hosting with webdav support. You will need some space for this somewhere of course but it is straightforward to set up and a good alternative to running a full blown nexus server.
add this to your build section
Add something like this to your distributionManagement section
Finally make sure to setup the repository access in your settings.xml
add this to your servers section
and a definition to your repositories section
Finally, if you have any standard php hosting, you can use something like sabredav to add webdav capabilities.
Advantages: you have your own maven repository Downsides: you don't have any of the management capabilities in nexus; you need some webdav setup somewhere
You can use JitPack to expose your GitHub repository as a Maven artifact. Its very easy. Your users would need to add this to their pom.xml:
As answered elsewhere the idea is that JitPack will build your GitHub repo and will serve the jars. The requirement is that you have a build file and a GitHub release.
The nice thing is that you don't have to handle deployment and uploads. Since you didn't want to maintain your own artifact repository its a good match for your needs.
As an alternative, Bintray provides free hosting of maven repositories. That's probably a good alternative to Sonatype OSS and Maven Central if you absolutely don't want to rename the groupId. But please, at least make an effort to get your changes integrated upstream or rename and publish to Central. It makes it much easier for others to use your fork.