Use of Maven tool for Java interface automation

VOL 190

30

2020-12

Today is 1 day before 2021

This is the 190th tweet of ITester Software Testing Stack

Click on the top blue word " ITester software testing Flowering " I'm concerned about, one, three, five in the morning every week  08: 3 0 punctual push each month from time to time presented technical books .

WeChat official account backstage responds to " resources " and " test kit " to receive test resources, and responds to " WeChat exchange group " and " introduction group " to join the group to fight monsters.

This article is 3862 words, about 11 minutes to read

In the last article of the Java interface automation test series: Introduction to IDEA, permanent activation and common shortcut keys for Java interface automation , it mainly introduces the advantages of IDEA, how to activate the idea tool, and the shortcut keys we commonly use in daily development.

The following mainly introduces the characteristics of Maven, installation and configuration and Maven warehouse.

One

Introduction to Maven

1

What is maven?

MavenIs a project management tool, it contains a project object model (Project Object Model), reflected in the configuration, is a pom.xml file. It is a set of standards, a project life cycle, a dependency management system, and also includes plugins and goals defined in the project life cycle stage.

When we use Maven, we use a custom project object model, pom.xml, to describe our own project in detail. The two cores in Maven:

  • Dependency management: unified management of jars (Maven provides a central repository for Maven, https://mvnrepository.com/, when we add dependencies to the project, Maven will automatically go to the central repository to download related dependencies and resolve them Dependency issues)

  • Project construction: compile, test, package, deploy, upload to private server, etc.

2

Why use maven?

Because Javathe ecology is very rich, no matter what function you want to achieve, you can find the corresponding tool classes. These tool classes are in the form of jar packages, such as Spring, SpringMVC, MyBatis, database drivers, etc. In the form of jar packages, there will be associations between jar packages. Before using a dependency, you need to determine the other dependencies that this dependency depends on. Therefore, when the project is relatively large, the dependency management will become very troublesome and bloated. This is the first problem solved by Maven.

Maven can also handle multi-module projects. Simple projects can be processed by single module subcontracting. If the project is more complex, it should be made into a multi-module project. For example, an e-commerce project has an order module, a membership module, a commodity module, a payment module, and so on. Generally speaking, in a multi-module project, each module cannot run independently, and multiple modules must be combined before the project can run. At this time, with the help of Maven tools, one-click packaging of the project can be achieved.

3

What are the characteristics of maven?

The characteristics of maven are as follows:

  • Project settings follow uniform rules.

  • Share in any project.

  • Dependency management includes automatic updates.

  • A large and growing library.

  • Extensible, can easily write plug-ins in Java or scripting languages.

  • New features can be accessed instantly with little or no additional configuration.

  • Model-based construction  : Maven can build any number of projects into predefined output types, such as JAR, WAR, or distribution based on project metadata, without the need to execute any scripts in most cases.

  • Consistent site for project information : Using the same metadata as the build process, Maven can generate a website or PDF, including any documents you want to add, and add it to a standard report on the development status of the project.

  • Release management and release separate output  : Maven will not require additional configuration, can be integrated with source code management systems (such as Subversion or Git), and can manage project release based on a certain tag. It can also publish it to a distribution location for use by other projects. Maven can publish individual outputs, such as JARs, archives containing other dependencies and documentation, or as source code.

  • Backward compatibility  : You can easily migrate multiple modules from old versions of Maven to Maven 3.

  • When the child project uses the parent project dependency, the child project should inherit the parent project dependency under normal circumstances without using the version number.

  • Parallel construction  : Compilation speed can generally be increased by 20-50%.

  • Better error reporting:Maven has improved the error report. It provides you with a link to the Maven wiki page. You can click on the link to view the full description of the error.

two

Maven installation and configuration

1

Ready to work

Maven is a Java project, so JDK must be installed first. Check if jdk has been installed, use command: java -version

2

maven download

Official download portal:

http://maven.apache.org/download.cgi

According to the needs, select the maven corresponding to the operating system to download.

3

maven installation and configuration

①After the download is complete, the unzipped directory is as follows:

② Configure maven environment variables. New system variable:

Variable name: MAVEN_HOME

 Variable value: C:\ruanjian\maven\apache-maven-3.6.3

Add environment variables in path:

%MAVEN_HOME%\bin

cmd opens the dos window, enter mvn -v, and check whether maven is successfully configured.

three

Maven repository

1

What is a maven repository?

In Maven terms, a warehouse is a location ( place), such as a directory, which can store all project jar files, library jar files, plug-ins, or any other project-specified files.

2

Why use maven repository?

Before Maven, the packages that our project depends on will be downloaded and placed in the lib directory of the corresponding project. For the same package, such as the Spring framework package, if project A wants to use it, copy it to the lib directory of project A; if project B wants to use it, copy it to the directory of project B. If this continues, you will find that the same dependency package needs to be copied N copies, which not only causes a waste of disk space, but also difficult to manage uniformly.

With Maven, based on Maven 坐标机制, any Maven project uses any component in exactly the same way. On this basis, Maven can uniformly store the packages shared by all Maven projects in a certain location, and this unified storage location for dependent packages is the warehouse. To put it bluntly, the Maven repository is where the dependent packages are stored.

3

maven warehouse type

There are three types of Maven repositories:

  • Local

  • Central

  • Remote (remote)

①Local warehouse

The Maven local repository is a folder on the machine that is created the first time you run any maven command.

The Maven local warehouse stores all the dependencies of your project (library jar, plugin jar, etc.). When you run a Maven build, Maven will automatically download all dependent jar files to the local repository. It avoids quoting dependent files stored on the remote machine every time you build.

The default location of the local repository is the current user name\.m2\repository. When you run the Maven command, Maven will download the dependent files to the path you specify.

If you can customize the location of the local warehouse, you can customize the location of the local warehouse in conf/settings.xml:

② Central warehouse

The Maven central repository is a repository provided by the Maven community, which contains a large number of commonly used libraries.

The key concepts of the central warehouse:

  • This repository is managed by the Maven community.

  • No configuration is required.

  • Need to go through the network to access.

To browse the contents of the central repository, the maven community provides a URL:

http://search.maven.org/#browse

Using this repository, developers can search all available code libraries. For example, to use the testng framework, search for testng on the page.

Just copy the dependencies:

Note: Because the default central warehouse download is slow, you can change the warehouse address to the Alibaba warehouse address, modify the conf/settings.xml file, and save it.

<mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

As follows:

③ Remote warehouse

If Maven cannot find the dependent files in the central repository, it will stop the build process and output an error message to the console. To avoid this situation, Maven provides the 远程仓库concept, which is the developer's own custom warehouse, which contains the required code base or jar files used in other projects. For example, if you declare dependencies in pom.xml, Maven will download the dependent files declared in pom.xml from the remote warehouse.

Since there are three warehouses, how to find the jar package? The order in which maven multi-repositories find dependencies is roughly as follows:

  •  Search in the local warehouse, if not, go to the next step;

  • Search in the global configuration private server warehouse (configured in settings.xml and activated), if not, go to the next step;

  • Search in the private server repository (pom.xml) configured by the project itself, if not, go to the next step;

  • Search in the central warehouse, if not, terminate the search.

the above


That‘s all

More series articles

Stay tuned


ITester software testing stack (ID: ITestingA), focuses on software testing technology and treasure dry goods sharing, updates original technical articles on time every week, and gives away technical books from time to time every month. May we meet at a higher level. Like to remember the star ⭐I, get the latest push every week in time. Please indicate the source for third-party reprints.

ITester software testing stack

Past content favored

1. Python interface automation-interface basics (1)


2. Python interface automation-interface basics (2)


3. Python interface automation-requests module get request


4. Python interface automation-requests module post request


5. Cookie and session application for Python interface automation


6. Detailed explanation and application of Token for Python interface automation


7. Python interface automation requests request packaging


8. Python interface automation of pymysql database operation


9. Python interface automation logging log


10. Python interface automation logging package and actual combat

Want to get more latest dry goods content

Come star and follow me

See you at 08:30 every Monday, Wednesday and Friday

<< Swipe right to view the next picture >>

 Backstage  reply "resources" to take dry goods

Reply to " WeChat Group" to fight monsters and upgrade

Personal WeChat: Cc2015123

Please indicate your intention to add :)

Really love Silian, see you in 2021~

Guess you like

Origin blog.csdn.net/weixin_42485712/article/details/112001262