利用Github做Maven私服

2018-06-02 雕虫小技

关于GitHub的骚操作一直以来都有很多,这篇文章记录一下使用GitHub来做免费maven 私服的方法。

发布到GitHub

修改setting.xml

修改mavensetting.xml文件,在servers节点下添加

<server>
  <id>github</id>
  <username>yourname</username>
  <password>yourpassword</password>
</server>

使用maven插件

修改项目工程的pom.xml文件,添加以下两个插件:

maven-deploy-plugin

<plugin>
  <artifactId>maven-deploy-plugin</artifactId>
  <version>2.8.2</version>
  <configuration>
    <altDeploymentRepository>
      internal.repo::default::file://${project.build.directory}/maven-repo
    </altDeploymentRepository>
  </configuration>
</plugin>

site-maven-plugin

<plugin>
  <groupId>com.github.github</groupId>
  <artifactId>site-maven-plugin</artifactId>
  <version>0.12</version>
  <configuration>
    <message>🐳 deploy maven artifacts, version: ${project.version}</message>
    <noJekyll>true</noJekyll>
    <outputDirectory>${project.build.directory}/maven-repo</outputDirectory>
        <!--本地jar地址-->
    <branch>refs/heads/master</branch><!--分支的名称-->
    <merge>true</merge>
    <includes>
      <include>**/*</include>
    </includes>
    <repositoryName>maven-repo</repositoryName><!--对应github上创建的仓库名称 name-->
    <repositoryOwner>cayzlh</repositoryOwner><!--github 仓库所有者即登录用户名-->
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>site</goal>
      </goals>
      <phase>deploy</phase>
    </execution>
  </executions>
</plugin>

###deploy

执行命令进行打包:

mvn clean package

好像可以不用打包

idea左侧lifecycle中双击deploy

image-20200423221908456

静静等待…..

image-20200423222621366

使用

在需要使用到私服的项目pom.xml文件中添加:

  <repositories>
    <repository>
      <id>maven-repo</id>
      <url>https://raw.githubusercontent.com/yourname/maven-repo/master/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

Enjoy it.

Maven

相关推荐



版权声明




留言区

文章目录