This is the 13th day of my participation in Gwen Challenge

As the saying goes, a journey of a thousand miles begins with a single step. Building a clean, concise and rigorous project scaffolding can avoid many bugs in the operation of subsequent projects.

Create a project

First go to the New Project page through File –> New –> Project

Four points need to be noted in the New Project:

These four points are not necessary to follow, but small editor feel to build a simple initial project to do

  1. On the left, select Maven
  2. Project SDK select 1.8 (select your own JDK)
  3. “Create Project from archetype”
  4. Select “org, apache maven. Archetypes: maven archetype – site”

Project naming

1. What are Groupid and artifactId?

Groupid and artifactId are collectively referred to as “coordinates” to ensure that the project is unique and can only be found based on these two ids when the project is put into maven’s local repository. GroupId and artifactId are the fields maven uses to distinguish project packages, like coordinates on a map.

GroupId is generally divided into multiple segments. Take two segments as an example: the first segment is the domain, and the second segment is the company name. Domains can be divided into ORG, COM, CN, etc. Org is a non-profit organization, and COM is a commercial organization.

For example, the Apache Tomcat project: the groupId of this project is org.apache, its domain is org (because Tomcat is a nonprofit project), the company name is apache, and artigactId is Tomcat.

Maven Version selection

Mave uses 3.5 +

Package cleaning and hiding

After the project is created successfully, the SRC directory is useless

There are directories of some script information files, as follows. Idea and so on

Modify File –> Settings –> Editor –> File Types –> ActionScript

Modify before:

Revised:

Finally, there is only one POM file left in IDEA for the entire project

Pom modification

Note that the values of groupId and artifactId need to be changed to the values of groupId and artifactId that you named when you created the project

<groupId>brief.talk.spring.cloud</groupId>
<artifactId>study</artifactId>
Copy the code

      

<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>brief.talk.spring.cloud</groupId>
    <artifactId>study</artifactId>
    <version>1.0.0 - the SNAPSHOT</version>
    <packaging>pom</packaging><! -- add jar or war -->

    <! -- Manage jar package version -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.12</junit.version>
        <log4j.version>1.2.17</log4j.version>
        <lombok.version>1.16.18</lombok.version>
        <mysql.version>5.1.47</mysql.version>
        <druid.version>1.1.16</druid.version>
        <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
    </properties>

    <! GroupId + modlue -->
    <dependencyManagement>
        <dependencies>
            <! - spring boot 2.2.2 -- -- >
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2. RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <! --spring cloud Hoxton.SR1-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <! - spring cloud alibaba 2.1.0. RELEASE -- -- >
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0. RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${druid.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.spring.boot.version}</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <optional>true</optional>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <! -- <finalName> Your project name </finalName> (added for single project) -->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Copy the code

Pom attention

Maven dependencies will be reloaded after the poM content has been overwritten. The poM file may have some dependencies highlighted in red. Therefore, before declaring the dependency, make sure that the dependency of the corresponding version has been downloaded to the local repository. Red indicates that the dependency of the corresponding version may not have been downloaded to the local repository

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${mysql.version}</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>${druid.version}</version>
</dependency>
Copy the code

Modify uniform coding

File –> Settings –> Editor –> File Encodings Change Project Encodings from GBK to UTF-8 The Default encoding for properties files is UTF-8, Transparent native to ASCII conversion √ oh!

Before the change

The modified

Modifying the Compile environment

File – – > Settings – > Build, Execution, Deployment – > Compiler – > Java Compiler will projectTarget bytecode versionChange the default from 1.5 to 8

Today’s summary

Today’s content is mainly practical operation, although these knowledge points are not much, and even some places are not perfect, but when the project is set up, a little bit of a new feeling.