发布开源库到Github
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mouday</groupId> <artifactId>hello-package</artifactId> <version>1.0-SNAPSHOT</version> <!-- 发布的软件包的位置 --> <distributionManagement> <repository> <id>local-repo-release</id> <name>GitHub Release</name> <url>file://${project.basedir}/maven-repo</url> </repository> </distributionManagement> <build> <plugins> <!--创建源码--> <plugin> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <phase>package</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!--创建javadoc--> <plugin> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-javadocs</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
构建功能
package com.mouday; public class Hello { public void sayHello(){ System.out.println("Hello"); } }
生成部署文件
mvn clean package deploy
生成如下文件
$ tree . ├── README.md ├── hello-package.iml ├── maven-repo │ └── com │ └── mouday │ └── hello-package │ ├── 1.0-SNAPSHOT │ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar │ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar.md5 │ │ ├── hello-package-1.0-20200731.025404-1-javadoc.jar.sha1 │ │ ├── hello-package-1.0-20200731.025404-1-sources.jar │ │ ├── hello-package-1.0-20200731.025404-1-sources.jar.md5 │ │ ├── hello-package-1.0-20200731.025404-1-sources.jar.sha1 │ │ ├── hello-package-1.0-20200731.025404-1.jar │ │ ├── hello-package-1.0-20200731.025404-1.jar.md5 │ │ ├── hello-package-1.0-20200731.025404-1.jar.sha1 │ │ ├── hello-package-1.0-20200731.025404-1.pom │ │ ├── hello-package-1.0-20200731.025404-1.pom.md5 │ │ ├── hello-package-1.0-20200731.025404-1.pom.sha1 │ │ ├── maven-metadata.xml │ │ ├── maven-metadata.xml.md5 │ │ └── maven-metadata.xml.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 ├── pom.xml └── src ├── main │ ├── java │ │ └── com │ │ └── mouday │ │ └── Hello.java │ └── resources └── test └── java
将代码推送到 Github,并开启Pages服务
仓库地址:https://github.com/mouday/hello-package
使用开源库
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mouday</groupId> <artifactId>import-hello-demo</artifactId> <version>1.0-SNAPSHOT</version> <repositories> <!--声明发布的Maven的repo地址--> <repository> <id>github-rich-repo</id> <name>The Maven Repository on Github</name> <url>https://www.pengshiyu.com/hello-package/maven-repo/</url> </repository> </repositories> <dependencies> <!--引入依赖--> <dependency> <groupId>com.mouday</groupId> <artifactId>hello-package</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
使用测试
package com.mouday; public class demo { public static void main(String[] args) { Hello hello =new Hello(); hello.sayHello(); } }
参考
https://www.liaoxuefeng.com/wiki/1252599548343744/1347981037010977