编程知识 cdmana.com

Every programmer should learn Maven knowledge

The old days

When we used to write code ,jar By default, all packages are placed in a place called /lib Under the directory of , Then set the directory to classpath Directory that can be read , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

One day we added a new function , Need to use an older z.jar package , At this time, we went to the Internet to search , Because it is rare , Eventually, at some point xxx Software Park Found him in . And then we put z.jar Package copy to /lib Under the table of contents :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

At this time, a lot of errors are reported after running , as a result of z.jar Packages have many dependencies , Namely z1.jar , z2.jar , z3.jar. At this time, do you have an impulse to swear ? But impulse is impulse , The code still needs to be written ,jar The bag is still looking for , A hole dug by myself , You have to fill it out when you cry .

Through all difficulties and dangers , Finally in the 1 Found in a blog z1.jar , z2.jar , z3.jar Download link for , But you need to pay points to download .. In order to get these jar package , We registered another account , Made a few comments , After earning enough points , Finally put those three jar The package has been downloaded . Then quickly copy them to /lib down :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

That's enough jar After the package , Run the project again , Finally, it can run successfully , Thank goodness !

After half a month , The boss said we project A Very good , Now we're ready to start another project B As his brother project . Then you start building project B The framework of , Put everything you need jar Packet from project A copy to project B in :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Since then, you have started the day of playing strange and upgrading again .

These days

With the development of science and technology , The tide of reform and opening up swept the earth , Also swept IT world , A lot of productivity tools have been created , As the saying goes , If a worker wants to do a good job, he must sharpen his tools first . With good productivity tools , What you have to do must be twice the result with half the effort ! and Maven It is a productivity tool to liberate our program apes .

Program apes need a lot of... In their daily work jar package , Some are framework packages, such as :netty,sentinel etc. , There are toolkits, such as :hutool, Some are private packages within the company, such as :xx-framework wait .

A project may be filled with all kinds of jar package , If we manage one by one by hand , Then you will be lost in jar In the ocean of bags , At this time we pass through Maven This kind of Management jar Package tools to help us solve this cumbersome and difficult problem , It allows us to focus on our functions and business .

Actually Maven Is a set of software engineering management and integration tools . It has many functions, including but not limited to the following :

  • Project creation 、 structure 、 test

  • Dependent Management

  • Warehouse management

  • Automated Deployment

  • ...

What we use most in our daily life may be engineering and dependency management , Others don't use much frequency .

With Maven after , We :

  • You don't need to create one for each project /lib The directory is used to store all kinds of jar It's packed

  • There's no need to find what I need... For where to go jar Worried about the bag

  • There is no need to reference jar Bag to find what he depends on jar It's packed

  • ...

structure

Here is a typical maven Structure chart of the project :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Warehouse

stay Maven In terms of , The warehouse is a location (place), For example directory , Can store all the projects jar file 、library jar writing Pieces of 、 Plug in or any other project specified file .

Strictly speaking ,Maven There are only two types of warehouses :

  • Local (local)

  • long-range (remote)

Local repository

Maven Your local warehouse is a folder on the machine . It's the first time you run any maven Command to create .

Maven Your local repository holds all the dependencies of your project (library jar、plugin jar etc. ). When you run once Maven Build time ,Maven It will automatically download all dependent jar File to local warehouse . It avoids referencing dependent files stored in a remote warehouse every time you build .

Maven The local warehouse of is created in by default ${user.home}/.m2/repository Under the table of contents . To change the default location , As long as settings.xml Define another path in the file , for example :

  1. <localRepository>/anotherDirectory/.m2/respository</localRepository>

Remote warehouse

Maven A remote repository can be any other type of Repository , Through various protocols , for example file// and http// To visit .

These repositories can be downloadable remote repositories provided by third parties , for example Maven The central warehouse (central repository):

repo.maven.apache.org/maven2

uk.maven.org/maven2

It can also be in the company FTP Server or HTTP The internal repository set up on the server , Used to share private information between the development team and the release artifacts.

The central warehouse

Maven Our central warehouse is Maven Community maintenance , It contains a large number of commonly used libraries , We can directly quote , But the premise is that our project can access the Internet .

Private warehouse

except Maven Outside the central warehouse , There is also a private warehouse , This kind of warehouse is usually a private library created within the enterprise , For some internal jar Maintenance and sharing of packages . Due to network reasons and security considerations , Many companies have isolated internal and external networks , Direct access to the central warehouse is impossible , And it is also very dangerous to directly expose internal resources to the Internet , So you need to create a private library .

What is the relationship between these warehouses ? Or a Maven The project wants to get a jar Bag words , Which warehouse should he get it from ? The following figure is a simple description :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

First Maven Will go to the local warehouse to find what you need jar Well , If it cannot be found, it will go to the configured private warehouse , If you can't find it in the private warehouse , Will go to the central warehouse of the configuration to find , If you still can't find it, you will report an error . But as long as it is found in a warehouse, it will return , Unless there is an updated version in the warehouse , Or is it snapshot edition .

that Maven How is the remote warehouse configured ? Suppose we want to configure a central warehouse , It can be configured as follows :

  1. <project>

  2. ...

  3. <profiles>

  4. <profile>

  5. <id>central</id>

  6. <repositories>

  7. <repository>

  8. <id>Central</id>

  9. <name>Central</name>

  10. <url>http://repo.maven.apache.org/maven2/</url>

  11. </repository>

  12. </repositories>

  13. </profile>

  14. </profiles>

  15. <activeProfiles>

  16. <activeProfile>central</activeProfile>

  17. </activeProfiles>

  18. ...

  19. </project>

Best practices

However, the official does not recommend directly configuring remote warehouses , For example, directly configure a central warehouse , But through Warehouse Manager To download what we need jar package . Imagine if your company has thousands or even tens of thousands of developers , Everyone has a separate central warehouse , Then everyone goes to the central warehouse to download what they need jar, This degenerates into the most primitive pattern , And it's a huge waste of resources .

What is Warehouse Manager Well ? The warehouse manager is a dedicated server application , The purpose is to manage the repository of binary components . For any use Maven Project , The use of a warehouse manager is considered an essential best practice .

The warehouse manager provides the following basic purposes :

  • Act as the center Maven A dedicated proxy server for the repository

  • Provide a repository as Maven Deployment target of project output

Using the warehouse manager, you can get the following advantages and functions :

  • Significantly reduce the number of downloads from remote repositories , Save time and bandwidth , This improves build performance

  • Due to reduced dependence on external repositories , Improved build stability

  • With the remote SNAPSHOT Improved performance of repository interactions

  • It provides an effective platform , Used to exchange binary artifacts inside and outside the organization , Without having to build artifacts from source code

  • ...

Known open source and commercial repository managers have the following :

  • Apache Archiva( Open source )

  • CloudRepo( business )

  • Cloudsmith package ( business )

  • JFrog Artifactory Open source ( Open source )

  • JFrog Artifactory Pro( business )

  • Sonatype Nexus OSS( Open source )

  • Sonatype Nexus Pro( business )

  • packagecloud.io( business )

Mirror image

Mirror Is equivalent to an agent , It will intercept the specified remote Repository Request to download components , Then find the component from yourself and send it back to the client . To configure Mirror The purpose of is generally for the consideration of network speed .

Repository and Mirror It's two different concepts : The former itself is a warehouse , Can provide services outside the heap , The latter itself is not a warehouse , It's just a network accelerator for remote warehouses .

It should be noted that many local warehouse building tools often provide Mirror service , such as Nexus You can make the same URL, Both as internalrepository, And make it all repository Of Mirror.

If Warehouse X Can provide Warehouse Y Everything stored , Then we can think of X yes Y A mirror image of . It also means that , Any component that can be obtained from a warehouse , Can be obtained from its image .

for instance :http://maven.net.cn/content/groups/public/ It's a central warehouse http://repo1.maven.org/maven2/ Mirror image in China , Due to geographical location , This image can often provide faster service than the central warehouse .

therefore , Can be in Maven Configure the image in to replace the central warehouse . stay settings.xml The following code is configured in :

  1. <settings>

  2. ...

  3. <mirrors>

  4. <mirror>

  5. <id>maven.net.cn</id>

  6. <mirrorOf>central</mirrorOf>

  7. <name>one of the central mirrors in china</name>

  8. <url>http://maven.net.cn/content/groups/public/</url>

  9. </mirror>

  10. </mirrors>

  11. ...

  12. </settings>

\ The value of is central, Indicates that the image is the image of the central warehouse , Any request to the central warehouse will go to the image , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

The best practice for mirroring is to combine private servers . Because private server can act as any external public warehouse ( Including the central warehouse ), therefore , For... Within the organization Maven Users , Using a private server address is equivalent to using all the required external warehouses , This can focus the configuration on private servers , Thus simplify Maven Its own configuration . under these circumstances , Any required component can be obtained from private server , Private server is the mirror image of all warehouses .

For example, you can configure an agent to mirror all warehouses :

  1. <settings>

  2. ...

  3. <mirrors>

  4. <mirror>

  5. <id>internal-repository</id>

  6. <name>Internal Repository Manager</name>

  7. <url>internal-repository-url</url>

  8. <mirrorOf>*</mirrorOf>

  9. </mirror>

  10. </mirrors>

  11. ...

  12. </settings>

\ The value of is an asterisk , Indicates that the image is all Maven The image of the warehouse , Any request for a remote warehouse will be forwarded to : internal-repository-url This address .

Here's one Maven Official architecture :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Life cycle

The life cycle is made up of A group of Yes The order Of Stage As a whole , It may be a little convoluted to say so , Let's focus on some important points in him :

  • A group of : It means that there may be more than one

  • The order : Means to execute in order , When executing the instructions of a stage, the instructions before the stage will be executed first in turn

  • Stage : It refers to the specific content to be implemented

for example Maven There are three built-in build lifecycles : default, clean and site. Each life cycle consists of a series of stages , such as default A simple phase of the life cycle is as follows , For the complete life cycle, please refer to the official documentation :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Each node in the figure above is a Stage , The execution of phases is sequential , After one phase is completed, the next phase will be executed . For example, we execute the following command :

  1. mvn install

He will actually carry out install All stages before stage , Then it will be executed install Stage itself .

PS: When our project is multi module , When we execute the instruction at the top ,Maven Will traverse each sub module , Perform all phases in turn .

coordinate

Speaking of Maven Coordinates of , We first need to think of GAV , namely groupId artifactId version. From these three attributes, we can uniquely determine one jar It's packed . The meaning of each attribute is as follows :

  • groupId: Represents a group , It could be a company 、 Organization, etc

  • artifactId: Represents an item under the group

  • version: Indicates the version number of a project

The relationship between them is one to many , That is, each group can have multiple projects , Each project can have multiple version numbers , You can use the following figure to show :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

rely on

Maven One of the core features is dependency management . Once we start dealing with multi module engineering ( Contains hundreds of sub modules or sub projects ) When , modular The dependencies between them become very complex , Management has also become difficult . In this case ,Maven A method of height control is provided .

Depend on the transfer

Dependency passing is well understood , hypothesis B Depend on C, When A Need to rely on B when , be A Automatically get the right C Dependence . Dependency passing is sometimes very good , When we need to rely on a lot jar Packet time , We can declare a package that depends on all jar, Then just rely on this package . But sometimes it's troublesome , Because it is likely to cause a conflict of dependencies .

Dependency conflict

When in the same project due to different jar The package depends on the same jar package , At this point, a dependency conflict occurs , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

When the project depends on a and c, and a and c It all depends on b, There was a conflict . To avoid conflict ,Maven Two strategies are used to resolve conflicts , Namely Short circuit priority and Declaration of priority .

Short circuit priority

The consciousness of short circuit priority is , From the project to the final dependency jar Distance of , Which distance is short depends on which , Long distances will be ignored . For example, as shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Declaration of priority

Declaration of priority means , adopt jar The order of package declarations determines which package to use , The first to declare jar Packages are always selected , Later stated jar Packages are ignored , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Dependency exclusion

If we just want to reference what we directly depend on jar package , Instead of indirectly relying on jar If the package is also introduced , You can use dependency exclusion , Will indirectly reference jar Remove the bag , As shown in the following configuration :

  1. <exclusions>

  2. <exclusion>

  3. <groupId>excluded.groupId</groupId>

  4. <artifactId>excluded-artifactId</artifactId>

  5. </exclusion>

  6. </exclusions>

Resolve conflicts

Conflict in project , Mostly because of the reasons described above , then Maven In the choice jar Packet time , Chose the wrong package , Cause problems , Then we need to intervene in him , tell Maven Which positive packet to use . Let me give an example to illustrate how to solve the conflict .

A project we were running well , Suddenly there was a start , Wrong report , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

You can see a report NoSuchMethodError , See this mistake , Mostly because of conflict .

The mistake is that you can't find javax.servlet.ServletContext Class getVirtualServerName The method , Then we are idea Search for javax.servlet.ServletContext class , See if there are multiple situations , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

It can be found that there are two jar Found everything in the bag javax.servlet.ServletContext This class , Let's open them to see which class doesn't have the method we need :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

You can see it clearly , stay servlet-api-3.0.jar The method we need is not found in the package , and Maven Must have chosen this package . Let's look at the dependency tree , have a look Maven How did you choose the wrong package .

Enter the following command in the project directory :

  1. mvn dependency:tree -Dverbose -Dincludes=javax.servlet:servlet-api

Maven Will print out servlet-api-3.0.jar The dependency tree of the package , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Then enter the following command :

  1. mvn dependency:tree -Dverbose -Dincludes=org.apache.tomcat.embed:tomcat-embed-core

Maven Will print out tomcat-embed-core-8.5.31.jar The dependency tree of the package , As shown in the figure below :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Let's analyze the reason , from Maven From the dependency tree printed out in , Find something strange :

servlet-api-3.0.jar The bag is in xx-service Module , from xx-web To his depth is 6,

tomcat-embed-core-8.5.31.jar The bag is in xx-web Module , from xx-web To his depth is 3.

Then follow the short circuit first rule ,Maven Should choose tomcat-embed-core-8.5.31.jar The bag is right , There is no choice now , There must be only one reason : Declaration of priority !

explain servlet-api-3.0.jar Baubi tomcat-embed-core-8.5.31.jar The package first declares .

We found that servlet-api-3.0.jar The bag is in xx-service Introduced in ,

and tomcat-embed-core-8.5.31.jar Is in spring-boot-starter-web Introduced in .

Then as long as it can be proved that xx-web in xx-service Precede spring-boot-starter-web A statement will do , Let's go xx-web Look at it :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Facts have proved that our conjecture is correct , xx-service Do than spring-boot-starter-web First of all !

It can be graphically represented as follows :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Then you know why , To resolve this conflict , It's easy to do , There are two ways :

  • stay  xx-web  Lieutenant general  xx-service  Put it in  spring-boot-starter-web  It is stated later that

  • stay  xx-service  Found in  servlet-api-3.0.jar  The bag ruled him out

Dependency management

polymerization

Running multiple projects at the same time is called aggregation , The following is a multi module project :

  1. <packaging>pom</packaging>

  2. <modules>

  3. <module>module-1</module>

  4. <module>module-2</module>

  5. <module>module-3</module>

  6. </modules>

The advantage of aggregation is that you can compile multiple files in one place pom file .

PS: When we get together packaging Must if pom

Inherit

Follow java Class inheritance is similar to ,Maven The inheritance feature of also inherits the parent pom Dependency in , Suppose we define a parent pom:

  1. <groupId>com.houyi</groupId>

  2. <artifactId>maven-parent</artifactId>

  3. <version>0.0.1-SNAPSHOT</version>

  4.  

  5. <dependencyManagement>

  6. <dependencies>

  7. <dependency>

  8. <groupId>junit</groupId>

  9. <artifactId>junit</artifactId>

  10. <version>${junit.version}</version>

  11. <scope>test</scope>

  12. </dependency>

  13. <dependency>

  14. <groupId>mysql</groupId>

  15. <artifactId>mysql-connector-java</artifactId>

  16. <version>5.1.30</version>

  17. </dependency>

  18. </dependencies>

  19. </dependencyManagement>

And then in the pom Introduce this parent pom:

  1. <!-- Appoint parent, Explain from which pom Inherit -->

  2. <parent>

  3. <groupId>com.houyi</groupId>

  4. <artifactId>maven-parent</artifactId>

  5. <version>0.0.1-SNAPSHOT</version>

  6. <!-- Specify the relative path -->

  7. <relativePath>../maven-parent</relativePath>

  8. </parent>

  9.  

  10. <!-- Just indicate groupId + artifactId, You can go to the father pom eureka , There is no need to indicate the version -->

  11. <dependencies>

  12. <dependency>

  13. <groupId>junit</groupId>

  14. <artifactId>junit</artifactId>

  15. </dependency>

  16. <dependency>

  17. <groupId>mysql</groupId>

  18. <artifactId>mysql-connector-java</artifactId>

  19. </dependency>

  20. </dependencies>

Use dependencyManagement, Dependencies can be managed . Subclasses just don't reference what's written in this groupId + artifactId, No dependencies will be added , This prevents duplicate packets from being added : If not used dependencyManagement, So just write dependency, Son pom Will all be added to the dependency , And many of these bags may not be used .

plug-in unit

The plug-in is Maven At the heart of , All operations performed are based on plug-ins .

In order to realize many similar functions in a plug-in ,Maven Set goals for plug-ins , There may be multiple targets in a plug-in . In fact, each stage in the life cycle is executed by a specific goal of the plug-in

For example, you can configure a plug-in in the following way :

  1. <build>

  2. <plugins>

  3. <plugin>

  4. <groupId>org.apache.maven.plugins</groupId>

  5. <artifactId>maven-source-plugin</artifactId>

  6. <version>2.2.1</version>

  7. <!-- Configuration execution -->

  8. <executions>

  9. <execution>

  10. <phase>package</phase>

  11. <goals>

  12. <goal>jar-no-fork</goal>

  13. </goals>

  14. </execution>

  15. </executions>

  16. </plugin>

  17. </plugins>

  18. </build>

Configuration objectives goal Is the purpose of : It's executing mvnpackage When , Automatically mvn source:jar-no-fork 了 ,jar-no-fork This goal is used for source code packaging .

Except in the build Element , Of course you can parent In the project , use pluginManagement To configure the , Then you can inherit in the subproject and use .

PS: We can do a lot of things through plug-ins , Such as through mybatis-generator We can generate many DAO Layer code , And then cooperate with GM Mapper+lombok Use it to make your code very concise , Absolute productivity tools !

Instructions

Here are some of the most commonly used maven Instructions :

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Command parameters

The above list is just a more general command , In fact, many commands can carry parameters to perform more precise tasks . Maven The types of parameters that the command can carry are as follows :

-D Pass in property parameter

For example, command : mvnpackage-Dmaven.test.skip=true With -D start , take maven.test.skip The value of the set true , Just tell maven Skip unit testing when packaging .

Empathy , mvn deploy-Dmaven.test.skip=true Represents the deployment project and skips unit tests .

-P Use specified Profile To configure

For example, project development needs to have multiple environments , Usually for development , test , Advance , formal 4 An environment , stay pom.xml The configuration in :

  1. <profiles>

  2. <profile>

  3. <id>dev</id>

  4. <properties>

  5. <env>dev</env>

  6. </properties>

  7. <activation>

  8. <activeByDefault>true</activeByDefault>

  9. </activation>

  10. </profile>

  11. <profile>

  12. <id>qa</id>

  13. <properties>

  14. <env>qa</env>

  15. </properties>

  16. </profile>

  17. <profile>

  18. <id>pre</id>

  19. <properties>

  20. <env>pre</env>

  21. </properties>

  22. </profile>

  23. <profile>

  24. <id>prod</id>

  25. <properties>

  26. <env>prod</env>

  27. </properties>

  28. </profile>

  29. </profiles>

  30.  

  31. ...

  32.  

  33. <build>

  34. <filters>

  35. <filter>config/${env}.properties</filter>

  36. </filters>

  37. <resources>

  38. <resource>

  39. <directory>src/main/resources</directory>

  40. <filtering>true</filtering>

  41. </resource>

  42. </resources>

  43. </build>

profiles Defines the variables of each environment id, filters The address of the variable configuration file is defined in , The environment variable in the address is above profile The value defined in , resources Define which directory files will be replaced by the variables defined in the configuration file .

adopt maven It can be deployed in different environments , The order is :

  1. mvn package -P dev

among dev Variables for the environment id, On behalf of the use of Id by dev Of profile.

-e Show maven Run error messages

-o Executing commands offline , That is, do not go to the remote warehouse to update the package

-X Show maven Allow the debug Information

-U Force remote updates snapshot Plug in or dependency of , By default, it is updated only once a day

for instance

To his own jar Deploy the package to the remote warehouse , have access to deploy Instructions :

  1. mvn deploy:deploy-file -DgroupId=<group-id> \

  2. -DartifactId=<artifact-id> \

  3. -Dversion=<version> \

  4. -Dpackaging=<type-of-packaging> \

  5. -Dfile=<path-to-file> \

  6. -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \

  7. -Durl=<url-of-the-repository-to-deploy>

Finally, let's talk about why we should study maven, You can probably reap these benefits :

  • Improve your productivity

  • Better manage... In the project jar package

  • self-developed jar Packages can be shared with others

  • encounter jar The package conflict problem can be solved without asking people

  • ...

 

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

 

版权声明
本文为[Java confidant]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/08/20210809181600811o.html

Scroll to Top