Pure dry goods! Maven for Huawei Software Development Cloud Compile and Build

one. Introduction to Maven

Maven is a project management and integration tool. Maven provides developers with a complete build lifecycle framework. The development team can automatically complete the basic build configuration of the project in very little time, because Maven uses a standard directory structure and a default build life cycle.

two. Maven uses

Maven provides help to manage

Methods for building, documentation, reporting, dependencies, SCMs, publishing, distribution. It can easily compile code, manage dependencies, manage binary libraries, and more. The advantage of Maven is that the project process can be standardized, automated, efficient, and powerfully extensible. Using Maven itself and its plug-ins, you can also get code inspection reports, unit test coverage, and continuous integration.

three. Maven configuration

1. Create a new build task

First , create a new build task in the Huawei Software Development Cloud (see Figure 1).

Figure 1 New build task

[maven-demo] is the user-defined build task name.

[maven_demo] is the code repository that has been created, and [master] is a branch in [maven_demo].

There are two things to note about archiving:

1)

The path of the archive, the default is [target/*.jar], the actual path depends on the path of the pom file, we first look at the project directory of [maven_demo] (see Figure 2), the pom file is in the [springmvc_demo] folder, so the actual The archive path should be [springmvc_demo/target/*.jar].

Figure 2 maven_demo warehouse directory structure

2) The archive type, the default is jar, the actual type depends on the settings in the pom file (see Figure 3). In the pom file, the packaging type is war, so the actual type is war.

Figure 3 springmvc_demo project pom file

Therefore, in the archive, [springmvc_demo/target/*.war] should be written.

Finally, the build task is successfully created.

2. Edit the build task

1) Basic information

The configuration when creating a task is the most basic configuration, and users can configure more detailed parameters by editing the task (see Figure 4).

Figure 4 Build task editing steps

In [Basic Information], you can set [Execution Parameter Configuration], that is, parameter configuration when executing the build. These parameters are mainly used to set [package name], [version number], [grouping] and [package type], and these parameters will be used in [configuration build] (see Figure 5).

Figure 5 Execution parameter configuration

[Character type] is a string, [custom type] is similar to enumeration, select one from the defined values ​​(see Figure 6, Figure 7).

Figure 6 Editing of custom type parameters

Figure 7 Custom type parameter values

2) Code configuration

Select the repository and branch to build (see Figure 8).

Figure 8 Select a code repository

If you select [Auto Build], as long as the warehouse code changes, the compilation and build will be triggered.

According to the needs of the project, if you want to build multiple repositories, in order to avoid code conflicts, you need to specify the storage directory (see Figure 9).

Figure 9 Selecting multiple code repositories

The storage directory is set by the user, and the corresponding path in the server is related to the directory structure of the warehouse.

The build path of [maven_demo] is as follows:

Figure 10 The working directory of the maven_deno repository

The build path of [maven_demo2] is as follows:

Figure 11 The working directory of the maven_deno2 repository

Note: The directory structure of the warehouse [maven_demo2] is different from that of the warehouse [maven_demo]. The pom file of the former is in the root directory of the warehouse, and the pom file of the latter is in the [springmvc_demo] directory of the root directory.

3) Build configuration

Select [Java] for the build environment and [Maven] for the build type. Maven has many configuration parameters (see Figure 12).

Figure 12 maven parameter configuration

[Maven version]: Currently only mvn3.3.1 is supported, and the optional version number will be updated according to the version upgrade of maven.

[Publish to private library]: The default option is to execute maven

package, packaged into this project, usually in the project target directory. If checked, execute maven

deploy, package and upload to the remote warehouse, and publish the software package to the user's private maven release and maven snapshot warehouses, you need to configure the pom file.

[Maven parameter]: The default is -U, and the latest dependency package of the snapshot repository will be downloaded when compiling. Other parameters can be configured if required (see Figure 13).

Figure 13 maven common parameter commands

[POM file]: If the pom file is in the root directory of the warehouse, you do not need to fill it in. If it is like the warehouse [maven_demo], the pom file is not in the root directory, you need to specify the path of the pom file [springmvc_demo/pom.xml], if in [ In Code Configuration], if the [Storage Directory] is specified as test1, you need to add the storage directory, that is, [test1/springmvc_demo/pom.xml].

[Properties]: The properties required by the build script. When using the Maven plugin from the command line, -D represents the input of properties. For example, in the version management of maven, the added properties are as follows (see Figure 14):

#Maven Version Management

branchName=xxxx-100317 #The name in the branch

updateBranchVersions=false #Whether to update the version information of the branch, the default is false

updateWorkingCopyVersions=false #Whether to update the version information of the trunk, the default is true

There cannot be spaces in each attribute, and the attributes are separated by spaces.

Figure 14 maven property configuration

For details on how to find properties, please refer to the following links:

http://www.cnblogs.com/EasonJim/p/6865150.html

[JVM options]: In Maven-based Java projects, memory overflow errors often occur. In this case, the parameter settings of the JVM need to be updated. Generally speaking, they are based on different memory overflow problems. permspace to make adjustments and settings. For example, increase the space of the PermGen area to 128M, and the setting method is

set

MAVEN_OPTS=-XX:MaxPermSize=128M, when filling in [JVM options], only write [-XX:MaxPermSize=128M] (see Figure 15). If you need to set multiple attributes, separate the attributes with spaces.

Figure 15 maven JVM option configuration

For the specific parameters of the JVM, please refer to the following link:

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

[ After compiling and building ] select [Publish to Compile and Build Repository] (see Figure 16)

Figure 16 Parameter configuration after compilation and build

Here, [package name], [version number], [file path], [grouping] and [packaging type] will be defined, and fixed values ​​can be written here, or the parameters defined in [Basic Information] can be used here. The parameters defined in [Basic Information] are used. The method is ${parameter name}. Regarding the [file path], if the pom file is in the root directory of the warehouse and the [storage directory] is not specified, then the [file path] is [target/springmvc_demo.war], if the [storage directory] is specified as test1, then in [File path] The storage directory should be added at the front, for example [test1/springmvc_demo/target/springmvc_demo.war].

If you build multiple repositories at the same time, you need to add the steps of [Execute Maven] and [Publish to Build and Build Repository] (see Figure 17).

Figure 17 Parameter configuration after multi-warehouse compilation and construction

4) Build execution configuration

[Build Result] Select [Archive], and [Files for Archiving] are all packages by default (see Figure 18). The specific path also depends on the path of the pom file, refer to [File Path] in [Build Configuration].

Figure 18 Build result configuration

The type of package depends on the definition in the pom file. [Not included] refers to packages that do not need to be archived. If there are multiple packages, separate each package with a space.

If you select multiple code repositories, you need to add [Archive] (see Figure 19).

Figure 19 Multi-warehouse build result configuration

5) Build plan configuration

[Construction plan] There are [Irregular], [Daily] and [Weekly].

[Irregular] means that the user builds manually. If the user does not operate, it will not be built.

【Daily】means to build regularly every day without user operation (see Figure 20).

Figure 20 Daily build plan configuration

[Weekly] refers to which days of the week can be fixed for timed construction, such as Tuesday and Thursday (see Figure 21), and no user operation is required.

Figure 21 Weekly build plan configuration

[Build time limit] refers to the maximum time limit for a build. If the build is not completed after this time, the build will be stopped.

Four. Maven build

When the user executes [Start Build], the parameter window will pop up (see Figure 22).

Figure 22 Execute build configuration

Fill in the parameters according to the actual needs of the project. These parameters are defined in [Basic Information], then start [Execute], and finally the construction is successful (see Figure 23).

Figure 23 Successful build

Fives. summary

Maven is not only a build tool, it is also a dependency management tool and a project management tool, providing a central repository that can help us download components automatically. In order to solve the problems of increasing dependencies, inconsistent versions, conflicting versions, and bloated dependencies, it precisely locates each component through a coordinate system. maven also provides a free central repository for Java developers all over the world, where almost any popular open source software can be found. Through derivatives (nexus), we can also quickly search for it. In short, maven builds will bring you a lot of benefits and surprises.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326578401&siteId=291194637