用eclipse向GitHub发布项目,并将该项目作为其他项目的依赖
思路:创建要发布的项目(如:utils)–>发布该项目到GitHub–>在其他项目中引入该utils的依赖
1.创建要发布的项目(项目名:utils)
1.1 点击该网址(https://start.spring.io/) ,按图填写完毕后,下载到本地,如图:
1.2 将下载好的文件解压到指定目录下,如图:
2.发布该项目(utils)到GitHub
2.1 先点击该网址(https://github.com/) 完成注册,登录后,点击“New repository”,
2.2 按图填写信息,如图:
2.3 将解压好的utils项目导入eclipse中
2.3.1 在eclipse中 “右键”-“import”-“Existing Maven Projects”-“browse”-“Finish”
2.3.2 打开pom.xml
删除以下代码块
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
将main和test下com.example.utils包下的两个utilsApplication.java文件统统删除,如图:
2.3.3 向该项目(utils)发布到GitHub
选中项目后,右键–Team–Share Project,选择Git后,Next–
按图所示步骤操作:
注意:此时可能会报如下错误:
解决办法:
选中项目,右键-Team-Commit,如图:
填写说明并全选文件后,Commit and Push
URI地址去GitHub中复制
然后,点击Next
2.3.4 此时去GitHub中一看,尴尬了,发现并没有传上去
选中项目–右键–Team–Remote–push
点击Next
点击Finish
2.3.5 去GitHub一看,成功了,如果你还是没有提交上去,就先Team–pull一下,然后反复的commit或者remote操作
3.在其他项目中引入该utils的依赖
3.1 创建测试工具类(StreamUtils.java),并提交到GitHub,等会在别的项目引入utils依赖成功后,就可以调用里面的方法来测试是否引用成功
StreamUtils.java代码
package com.example.utils;
/**
* @Description
* @author 大都督
* @date 2018年10月27日
*/
public class StreamUtils {
public static String helloGitHub() {
return "success";
}
}
3.2 提交StreamUtils.java文件到GitHub
选中StreamUtils.java文件,右键–Team–Commit
点击 Commit and Push
3.3 去GitHub检查一下,发现提交成功
3.4 向其他项目中引入utils的maven依赖
3.4.1 在GitHub发布utils,点击 “releases”
点击 “create a new release”
3.4.2 点击网址(https://jitpack.io/) , 输入你的repository URI(我的:https://github.com/lee58/utils.git)
3.4.3 复制生成的maven依赖到其他项目中
3.4.5 测试:
在其他项目的pom.xml中添加依赖
测试结果: