Install (MAC)

1. Check the JAVA_HOME environment variable

Maven is developed in Java, so a Java environment is a must

2, downloadMavenAnd unzip to a directory

For example: / Users/XXX/apache maven — 3.3.3

3. Set Maven CLASspath

$vi ~/. Bash_profile // Add the following code to save the configuration and exit vi: export M2_HOME=/Users/robbie/apache-maven-3.3.3 export PATH=$PATH:$M2_HOME/binCopy the code

4. Enable bash_profile

$ source ~/.bash_profile
Copy the code

5. Check whether Maven is successfully installed

$ mvn -v 
Copy the code

configuration

1. Configure the local repository

1) Maven’s core program does not contain specific functions, only responsible for macro scheduling, and specific functions are completed by plug-ins.

The Maven core program looks for plug-ins in the local repository. If not in the local repository it is downloaded from the remote central repository. If you do not have access to the Internet, you cannot perform Maven functions. To solve this problem, we can point Maven’s local repository to a directory that can be downloaded online.

Maven default local repository (MAC) : ~ (/Users/XXX/.m2) /settings.xml

~ : indicates the current user’s home directory.

3) Find Maven’s core configuration file settings.xml

Unzip: %M2_HOME%\conf\settings.xml

4) Setting method

/ / local repository path: < localRepository > / Users/XXX/m2 / repository < / localRepository >Copy the code

2. Configure The Ari cloud mirroring

To facilitate jar downloads, configure the following tags in the tag of Maven’s core configuration file settings. XML:

<mirrors>
    <mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>central</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>
Copy the code

3. Configure the warehouse user name and password

<servers>
    <server>
      <id>jfrog-releases</id>
      <username>username</username>
      <password>password</password>
    </server>
    <server>
      <id>jfrog-snapshots</id>
      <username>username</username>
      <password>password</password>
    </server>
</servers>
Copy the code

4. Configure the company’s warehouse information

<profiles> <profile> <id>dev</id> <repositories> <repository> <id>jfrog-virtual</id> <name>artifactory-releases</name> <url>https:// company specified address /artifactory/SR_maven_virtual/</ URL > < Releases > <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>nexus</id> <name>nexus</name> < url > http:// specified address/nexus/content/groups/public / < / url > < releases > < enabled > true < / enabled > < / releases > < snapshots > <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>dev</activeProfile> </activeProfiles>Copy the code

5. Configure Maven in Idea

  • Maven with its own, local warehouse automatically set up for our warehouse

  • Configure your own Maven installation

The commonly used skill

1. Common commands

MVN :install: after the parent project is created, run this command to publish the parent project to the repository for inheriting child projects. Maven Clean deploy: Deploy code to the repository. {note: If uploading code to repository fails, add an account to the Servers in maven configuration file: XXX/.m2/settings. XML}

Project build command

MVN clean -u package -t 1C -dmaven.test. skip=true -pl Project name -am

Cp project name /target/ project name -1.0.0-snapshot.jar./ project name -1.0.0-snapshot.jar

Tar -zcf project name -1.0.0-snapshot.tar. gz “./ project name -1.0.0-snapshot.jar”

Start the command

Nohup Java -xms725m -xmx925m -jar project name -1.0.0 -snapshot.jar &

2. Pom configuration

XML configuration file for Maven

1) dependencyManagement: Usually used in parent project

  • Manage dependency version numbers, usually in the parent POM at the top level of an organization or project, by having all child projects reference a dependency without having to display the listed version numbers.
  • After the submodule inherits, provide the following functions: lock the version, the submodule does not need to write groupId and version
  • Note: only declaring dependencies does not implement introductions. So the subproject needs to show the dependencies required by the declaration. If the subproject specifies a version number, the subproject uses the specified JAR version.

2) exclusions: Shield dependencies to resolve dependency JAR version conflicts

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <! -- Mask dependencies. For example, libA used in the project relies on a library version 1.0, libB relies on a library version 2.0, and now wants to use a unified version 2.0. Exclusions > <exclusion> <groupId> Redis. Clients </groupId> <artifactId>jedis</artifactId> </exclusion>  <exclusion> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> </exclusion> </exclusions> </dependency>Copy the code

3) distributionManagement: project distribution information that indicates the location to be published after MVN deploy is executed

This information specifies whether to deploy the website to a remote server or to deploy the artifacts to a remote repository (corresponding to the company repository information configured in the Settings file Servers)

<distributionManagement> <repository> <id>jfrog-releases</id> <name>artifactory-releases</name> <url> https://artifactory /SR_maven_releases_local/</url> </repository> <snapshotRepository> <id>jfrog-snapshots</id> <name>artifactory-snapshots</name> <url>https:// company specified address /artifactory/SR_maven_snapshots_local</url> </snapshotRepository> </distributionManagement>Copy the code

Repositories: Discover a list of remote repositories for dependencies and extensions

Contains information that needs to be connected to the remote warehouse (corresponding to the company warehouse information configured in the Settings file profiles)

<repositories> <repository> <id>jfrog-virtual</id> <name>artifactory-releases</name> <url> https://artifactory /SR_maven_virtual/</url> < Releases > </enabled> true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>nexus</id> < name > nexus < / name > < url > https:// specified address/nexus/content/groups/public / < / url > < releases > < enabled > true < / enabled > </releases> <snapshots> <enabled> true </enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>Copy the code

PluginRepositories: A list of remote repositories that discover plug-ins

These plug-ins are used for building and reporting (corresponding to the company warehouse information configured in the Settings profiles)

<pluginRepositories> <pluginRepository> <id>jfrog-virtual</id> <name>artifactory-releases</name> <url> https://artifactory /SR_maven_virtual/</url> < Releases > </enabled> true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> <pluginRepository> < id > nexus < / id > < name > nexus < / name > < url > https:// specified address/nexus/content/groups/public / < / url > < releases > < enabled > true </enabled> </releases> <snapshots> <enabled> true </enabled> </snapshots> </pluginRepository> </pluginRepositories>Copy the code

3. Skip unit tests

4. The project starts very slowly (MAC)

Solution: /ets/hosts Add machine address: 127.0.0.1 localhost yanzhus-macbook-pro.local

Cause: Startup loop to find the machine

Machine name: System Preferences – Share (Computers on your local network can access your computer at the following address: XXX-MacBook-pro.local)

5. Import project is abnormal

1) There is no Maven Project window on the right after importing the project

Select the project root POM file: right-click Add as Maven Project

Can’t find… can’t find…

Select the test package: right-click Mark Directory as-test Resources Root

3), Kotlin: Language version 1.1 is no longer supported; Please, use version 1.2 or greater

  • 1) Set Kotlin Compiler
  • 2) if the Kotlin Compiler setting does not work, set it directly in the project structure of the project