Skip to content

Instantly share code, notes, and snippets.

@fernandezpablo85
Last active April 16, 2024 17:02
Show Gist options
  • Save fernandezpablo85/03cf8b0cd2e7d8527063 to your computer and use it in GitHub Desktop.
Save fernandezpablo85/03cf8b0cd2e7d8527063 to your computer and use it in GitHub Desktop.
how to create your own maven repository on github

How to create a maven repository for your github project step by step

Clone your project in a separate folder

(note: replace ORGANIZATION and PROJECT)

git clone git clone git@github.com:ORGANIZATION/PROJECT.git my-repository

Cd into it

cd my-repository

Create a new branch (here named repository)

git branch repository

Switch to that branch

git checkout repository

Remove all files

rm -rf file1 file2 file3 .. etc

Install your jar in that directory

(note: replace YOUR_GROUP, YOUR_ARTIFACT, YOUR_VERSION and YOUR_JAR_FILE)

mvn install:install-file -DgroupId=YOUR_GROUP -DartifactId=YOUR_ARTIFACT -Dversion=YOUR_VERSION -Dfile=YOUR_JAR_FILE -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=.  -DcreateChecksum=true

YOUR_JAR_FILE should point to an existent jar file, this is why it's best to create your repository branch in a different folder, so you can reference the existing jar in /your/project/path/target/artifact-x.y.z.jar

Add all generated files, commit and push

git add -A . && git commit -m "released version X.Y.Z"

git push origin repository

Reference your jar from a different project

The repository url you just created is https://raw.github.com/YOUR_ORGANIZATION/YOUR_ARTIFACT/repository/

@MikhailKaduchka
Copy link

MikhailKaduchka commented Jun 17, 2020

Thanks for tutor it helped me a lot.

For me next command works with sources and docs

 mvn install:install-file -DgroupId=com.foo -DartifactId=bar -Dversion=0.0.1 -Dfile=~/tmp/bar/target/bar-0.0.1.jar -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=.  -DcreateChecksum=true -Dsources=/~/tmp/bar/target/bar-0.0.1-sources.jar -Djavadoc=~/tmp/bar/target/bar-0.0.1-javadoc.jar -DpomFile=~/tmp/bar/pom.xml 

and to use it

    <repositories>
        <repository>
            <id>private-repo</id>
            <name>Private Repository</name>
            <url>https://raw.githubusercontent.com/GITHUB_PROFILE/PROJECT/repository/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

@baszero
Copy link

baszero commented Aug 31, 2020

@mikhail: i get a "400: Invalid request" if I call my repo like you mention.
What is the correct URL? The repo must be browsable within the browser in order to work within a regular maven build.

@OCTO26092020-Akash
Copy link

Excellent ! It works fine.

@priyanka2211
Copy link

How to find the correct url?
I get "400: Invalid request" for all the urls formats mentioned above

@droar
Copy link

droar commented Jan 25, 2021

Thanks

@elect86
Copy link

elect86 commented Apr 30, 2021

any way to directly publish on it without manually having to commit and push on the repository itself?

@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

@arathi-linvest21
Copy link

I m getting 400 for the url. any correctiosn to the url above?

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