Skip to content

Instantly share code, notes, and snippets.

@cleberjamaral
Last active February 17, 2024 16:32
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cleberjamaral/6c9b0a615e51e26c94ffe407a641f531 to your computer and use it in GitHub Desktop.
Save cleberjamaral/6c9b0a615e51e26c94ffe407a641f531 to your computer and use it in GitHub Desktop.

How to use github as a maven repository

In this how-to it is being explained how to create a maven repository on github and how to use an existing one.

Creating a repository

  1. Clone your original project to a new local repository (change GROUP-NAME and PROJECT-NAME) git clone https://github.com/GROUP-NAME/PROJECT-NAME.git PROJECT-NAME-maven2

  2. Go to the clonned repository (use your PROJECT-NAME-maven2) cd PROJECT-NAME-maven2

  3. Create a branch for maven files git branch maven2

  4. Switch to this new branch git checkout maven2

  5. Remove project original files, this branch is just for releases rm -R ALL-PROJECT-SUB-FOLDERS rm ALL-PROJECT-FILES

  6. run mvn install for jar creation (change GROUP, ARTIFACT-NAME, ARTIFACT-VERSION, PATH-TO-THE-JAR and PATH-TO-EXISTING-POM). See *1 for details. mvn install:install-file -DgroupId=GROUP -DartifactId=ARTIFACT-NAME -Dversion=ARTIFACT-VERSION -Dfile=PATH-TO-THE-JAR -Dpackaging=jar -DlocalRepositoryPath=. -DcreateChecksum=true -DgeneratePom=true

  7. Add all files to be commited git add .

  8. Commit these changes git commit -m "Released version ARTIFACT-VERSION"

  9. Push this commit. After that your maven structure for you project can be reached by github raw data address https://github.com/GROUP-NAME/PROJECT-NAME/raw/maven2 git push origin maven2

  10. On gradle you can add this repository on 'repositories' maven { url "https://github.com/ORGANIZATION-NAME/PROJECT-NAME/raw/maven2" }

  • *1 Your PATH-TO-THE-JAR will be something like: ../PROJECT-NAME/build/libs/ARTIFACT-NAME-ARTIFACT-VERSION.jar. Use -DpomFile=PATH-TO-EXISTING-POM instead of -DgeneratePom=true if you already have a POM.

Using an existing repository

If you already have a repository using this way explained above, you can use the following commands to setup another machine in order to update your repository.

  1. Clone your maven2 branch to a local folder which name is followed by "-maven2" (change GROUP-NAME and PROJECT-NAME) git clone https://github.com/GROUP-NAME/PROJECT-NAME.git PROJECT-NAME-maven2 --branch maven2

  2. To update your maven2 repo, follow steps from run mvn install for jar creation

@elect86
Copy link

elect86 commented May 26, 2021

Sorry for shameless self-promotion, but I'd like to gather some feedbacks about one gradle plugin I've been working on: magik. Basically it allows to publish directly on a github repository acting as a maven repository. Github repos may serve for some nice custom solution since they allow up to 100GB total repo size with a max 100MB size for single file

@kyze8439690
Copy link

What if I set maven git repo as private? Can I use private token to fetch maven git repo?

@gamma-02
Copy link

Sorry for shameless self-promotion, but I'd like to gather some feedbacks about one gradle plugin I've been working on: magik. Basically it allows to publish directly on a github repository acting as a maven repository. Github repos may serve for some nice custom solution since they allow up to 100GB total repo size with a max 100MB size for single file

This looks exactly like what I'm looking for! the only thing I'm worried about is that my project is open-source and I don't want my github keys exposed...

@elect86
Copy link

elect86 commented Mar 10, 2022

you don't need to expose anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment