谷粒商城-全栈-05 配置 Git-SSH 及项目结构创建

一、选择托管仓库

目前有许多可使用的托管仓库平台,如GitHub,Gitee,但是由于国外网络的原因,GitHub有时候会连接不上,所以,我们用国内的码云gitee 来进行代码托管。

二、设置

如果你还没有码云账号,则可以先注册一个。

用户信息设置

$ git config --global user.name "用户名"
$ git config --global user.email "邮箱"    // 注册账号时用的邮箱

SSH配置

1、打开git bash

2、执行生成公钥和私钥的命令:ssh-keygen -t rsa -C "407544577@qq.com" (这里的邮箱为码云账号邮箱)并按回车3下(为什么按三下,是因为有提示你是否需要设置密码,如果设置了每次使用Git都会用到密码,一般都是直接不写为空,直接回车就好了)。会在一个文件夹里面生成一个私钥 id_rsa和一个公钥id_rsa.pub。(可执行start ~ 命令,生成的公私钥在 .ssh的文件夹里面)

3、执行查看公钥的命令:cat ~/.ssh/id_rsa.pub

4、登录进入gitee,在设置里面找到SSH KEY将 .pub 文件的内容粘贴进去。

查看配置信息

要检查已有的配置信息,可以使用 git config --list 命令:

$ git config --list
user.name=Scott Chacon
user.email=schacon@gmail.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

也可以直接查阅某个环境变量的设定,只要把特定的名字跟在后面即可,像这样:

$ git config user.name
Scott Chacon

5、测试
使用 ssh -T git@gitee.com 测试是否成功即可。

➜  ~ ssh -T git@gitee.com
Warning: Permanently added the ECDSA host key for IP address '212.64.62.183' to the list of known hosts.
Hi 恺易! You've successfully authenticated, but GITEE.COM does not provide shell access.

三、项目结构创建及上传到码云

1、在码云上边创建仓库:

file

2、IDEA 通过仓库构建项目

file->New->Get from Version Control

file

3、创建项目微服务

商品服务、仓储服务、订单服务、优惠券服务、用户服务

各个微服务的共同点:
1)、web、openfeign(依赖包)
2)、每一个服务、包名 com.atguigu.gulimall.xxx(product/order/ware/coupon/member)
3)、模块名:gulimall-coupon
4)、Springboot 版本 2.1.16

导入之后,然后再创建我们项目的微服务:
File->New->Module->Spring Initializr

创建 gulimall-product 模块
file

选择两个重要的依赖:
file

其他的微服务也同样如此创建。

创建好的目录结构是这样的:
file

4、父模块关联子模块

然后从子模块复制一个 pom.xml 文件放到 gulimall 父模块下边,并对其进行修改:

我们拿的是 gulimall-ware 的pom.xml 进行修改:
gulimall-ware/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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.16.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.atguigu.gulimall</groupId>
  <artifactId>gulimall-ware</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>gulimall-ware</name>
  <description>谷粒商城-仓储服务</description>

  <properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR6</spring-cloud.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

gulimall/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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.atguigu.gulimall</groupId>
  <artifactId>gulimall</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>gulimall</name>
  <description>聚合服务</description>
  <packaging>pom</packaging>

  <modules>
    <module>gulimall-coupon</module>
    <module>gulimall-member</module>
    <module>gulimall-order</module>
    <module>gulimall-product</module>
    <module>gulimall-ware</module>
  </modules>

</project>

然后将父 pom.xml 添加到编辑器右边栏,方便统一管理:

file

添加后的maven目录结构:

file

5、修改.gitignore文件

修改主目录下的 .gitignore 文件,把子项目下的垃圾文件全部忽略掉。

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

## ** 忽略所有目录下的文件 ##
**/mvnw
**/mvnw.cmd

**/.mvn
**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### VS Code ###
.vscode/

然后在IDEA 中添加 add to CVS,想要提交代码到码云,找码云的插件gitee 进行安装,安装好之后,进行提交:
file

提交了之后,然后再推送到码云,推送成功可以在码云看到刚推得项目:
file

至此,我们的前期环境的有关项目结构创建工作已经做完了。


相关文章:
初次运行 Git 前的配置

为者常成,行者常至