/ maven

Use github as maven repo

I want to find some free maven repo to store my jar files, but no good cadidate. After some googling there are some docs for make github as maven repo.
ref docs:
https://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github

https://www.javacodegeeks.com/2014/09/hosting-a-maven-repository-on-github-with-sources-and-javadoc.html

below is my steps:

  1. create a github project as maven repo, the name like "maven-repo".
    eg. I have a repo https://github.com/yren/maven-repo

  2. Use the github site-maven-plugin to push your artifacts to github

2.1 First let maven deploy artifacts to your local target directory. Add below to your pom.xml:

<distributionManagement>
    <repository>
      <id>internal.repo</id>
      <name>Temporary Staging Repository</name>
      <url>file://${project.build.directory}/mvn-repo</url>
    </repository>
</distributionManagement>

Now try running mvn clean deploy. You'll see it deployed to your local target/mvn-repo

2.2 The next step is upload that directory to GitHub

a. Config your ~/.m2/settings.xml , add a github server as below:

<!-- Note: settings.xml only in your local machine. Don't let anyone know your github pwd -->
<servers>
    <server>
        <id>github</id>
        <username>$user</username>
        <password>$pwd</password>
    </server>
</servers>

Note: settings.xml only in your local machine, don't let anyone know your github pwd!!!

b. Config github site-maven-plugin upload artificats to github. add blow to your project's pom.xml

<plugin>
        <groupId>com.github.github</groupId>
        <artifactId>site-maven-plugin</artifactId>
        <version>0.12</version>
        <configuration>
          <!-- git commit message -->
          <message>Maven artifacts for ${project.name} ${project.version}</message>
          <outputDirectory>${project.build.directory}/mvn-repo</outputDirectory>
          <branch>refs/heads/master</branch>
          <merge>true</merge>
          <includes><include>**/*</include></includes>
          <repositoryName>maven-repo</repositoryName>
         <repositoryOwner>$user</repositoryOwner>
          <server>github</server>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>site</goal>
            </goals>
            <phase>deploy</phase>
          </execution>
        </executions>
</plugin>

Now run mvn clean deploy again. You should see maven-deploy-plugin upload contents to github maven-repo

  1. Use you github repo dependency, in your project's pom.xml add below:
<repositories>
    <repository>
        <id>yren-maven-repo</id>
        <url>https://raw.githubusercontent.com/yren/maven-repo/master/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
  </repositories>