Little-known label maven commentary

maven is a tool to build and manage the project, provided to help management build, documents, reports, dependence, scms, publishing, distribution method. You can easily compile the code, dependency management, management of binary libraries and so on.
maven project that benefits the process can be standardized, automated, efficient and powerful scalability
use maven itself and its plug-ins can also get the code inspection reports, unit test coverage, achieve continuous integration and so on.

localRepository

A path for the specified storage jar package, in other words, the local address of the warehouse, if not set by default ${user.home}/.m2/repository. $ {user.home} is the system environment variables

<localRepository>E:/.m2</localRepository>

interactiveMode

Indicates whether to use the interactive mode, the default is true; if set to false, then when Maven requires the user to input, it will use a default value.

<interactiveMode>true</interactiveMode>

offline

Maven indicates whether you need to run in offline mode. If the build system needs to run in offline mode, for the true, the default is false. Because when the network setting problem or safety factors built when the server can not connect to a remote repository, we can set to false, so security

<offline>false</offline>

pluginGroups

  • Element contains a pluginGrouplist. There are default maven org.apache.maven.pluginsand org.codehaus.mojotwo pluginGroup. When parsing plugin expressed through the plugin prefix where to look. pluginGroup element specifies that the plugin groupId
  • As a plug-in so that we configured in pom file, configuration and coordinate our groupId not specified, familiar maven knows at least since we introduced the need groupId and artifactId. But the following plug-in is not. This time maven will get pluginGroupsin pluginGroupthe list one by one and configuration artifactId match. Matched to download. Repeat if it does not matter appears here, when we used to use on the line.
<plugins>
          <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
      </plugins>

proxies

Here it can define a series of sub-elements proxy represents Maven is required to make to the network when the agent. When a plurality of agents is set when the first flag is true of the active agent will be used

<proxies>
  <!--代理元素包含配置代理时需要的信息-->
  <proxy>
   <!--代理的唯一定义符,用来区分不同的代理元素。-->
   <id>myproxy</id>
   <!--该代理是否是激活的那个。true则激活代理。当我们声明了一组代理,而某个时候只需要激活一个代理的时候,该元素就可以派上用处。 -->
   <active>true</active>
   <!--代理的协议。 协议://主机名:端口,分隔成离散的元素以方便配置。-->
   <protocol>http</protocol>
   <!--代理的主机名。协议://主机名:端口,分隔成离散的元素以方便配置。  -->
   <host>proxy.somewhere.com</host>
   <!--代理的端口。协议://主机名:端口,分隔成离散的元素以方便配置。 -->
   <port>8080</port>
   <!--代理的用户名,用户名和密码表示代理服务器认证的登录名和密码。 -->
   <username>proxyuser</username>
   <!--代理的密码,用户名和密码表示代理服务器认证的登录名和密码。 -->
   <password>somepassword</password>
   <!--不该被代理的主机名列表。该列表的分隔符由代理服务器指定;例子中使用了竖线分隔符,使用逗号分隔也很常见。-->
   <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
  </proxy>
 </proxies>

servers

  • Configure some settings of the server. Some settings, such as security certificates and should not be distributed with pom.xml. This type of information should exist to build settings.xml file on the server
<servers>
<!--服务器元素包含配置服务器时需要的信息 -->
<server>
 <!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。-->
 <id>server001</id>
 <!--鉴权用户名。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。 -->
 <username>my_login</username>
 <!--鉴权密码 。鉴权用户名和鉴权密码表示服务器认证所需要的登录名和密码。密码加密功能已被添加到2.1.0 +。详情请访问密码加密页面-->
 <password>my_password</password>
 <!--鉴权时使用的私钥位置。和前两个元素类似,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。将来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
 <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
 <!--鉴权时使用的私钥密码。-->
 <passphrase>some_passphrase</passphrase>
 <!--文件被创建时的权限。如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(permission)。这两个元素合法的值是一个三位数字,其对应了unix文件系统的权限,如664,或者775。 -->
 <filePermissions>664</filePermissions>
 <!--目录被创建时的权限。 -->
 <directoryPermissions>775</directoryPermissions>
</server>
</servers>

## Instructions

  • We configured the publication properties distributionManagement are deployed to remote configuration label pom project. This label will speak in the maven pom section
<distributionManagement>
  <repository>
      <id>release-repository</id>
      <name>Release Repository</name>
      <url>http://www.myrepository.com/repositories/releases</url>
  </repository>
  <snapshotRepository>
      <id>snapshot-repository</id>
      <name>Snapshot Repository</name>
      <url>http://www.myrepository.com/repositories/snapshots</url>
  </snapshotRepository>
</distributionManagement>
  • The above configuration upload and remote upload path RELEASE address packet SNAPSHOT package, but we have permission of the remote address, the most basic is the need to account and password. This time we can not be exposed in the project, we can set up the maven of setting, the label is achieved through servers,

    <servers>
        <server>
            <id>snapshot-repository</id>
            <username>snapshot</username>
            <password>123456</password>
        </server>
        <server>
            <id>release-repository</id>
            <username>release</username>
            <password>123456</password>
        </server>
    </servers>
  • Note that both sides must match the id can. maven encrypted passwords

mirrors

  • Download mirror list configured for the repository list. Advanced Settings See mirror settings page, is used to define a series of remote repository mirroring. We can define a remote repository to download the workpiece when used in the pom. But sometimes this remote repository would be busy, so this time people are thinking about giving it to create a mirror image of the remote repository to ease the pressure that is put on request remote warehouse conversion to request its mirror address. Each will have a remote repository id, so that we can create your own mirror to associate to the warehouse, then later from a remote repository need to download the workpiece when Maven can be downloaded from our defined mirror sites, which can be very good It eases the pressure on our remote repository. In the mirror we define each remote repository can only have a mirror associated with it, which means you can not configure multiple mirror of mirrorOf point to the same repositoryId.
    • id: is used to distinguish the mirror, the mirror can not all have the same id

    • mirrorOf: The mirror is used to indicate which repository associated with a value of its associated warehouse id. When you want to associate multiple warehouses Meanwhile, among the plurality of warehouses which may be separated by a comma; when all of the warehouse to be associated, can be used " " represents; and when all the other to link a certain warehouse except repository can expressed as " , RepositoryId!"; when you want to associate with a file request is not localhost or warehouse, it can be expressed as "external: *".

    • url: url indicates the mirror. When Maven will use this url in the creation of systems to connect to our remote repository.

 <mirrors>
  <!--给定仓库的下载镜像。 -->
  <mirror>
   <!--该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
   <id>planetmirror.com</id>
   <!--镜像名称 -->
   <name>PlanetMirror Australia</name>
   <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 -->
   <url>http://downloads.planetmirror.com/pub/maven2</url>
   <!--被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。-->
   <mirrorOf>central</mirrorOf>
  </mirror>
 </mirrors>

profiles

  • Designate a series of profile. profile element consists of activation, repositories, pluginRepositories and properties of four elements. When a profile is in the active state settings.xml and defining a profile of the same id in pom.xml, the settings.xml profile will cover the pom.xml profile.

scenes to be used

  • profile allows us to define a set of configuration information, and then specify the conditions for its activation. Thus we can define a plurality of profile, and each corresponds to a different profile activation conditions and configuration information, so as to achieve different environments using different configuration information. For example, we can use a set of configuration profile defined by jdk1.5 above information, use another set of configuration information in jdk1.5 or less; or sometimes we may use different configuration information by different operating systems, such as windows under is a set of information, under linux is another set of information, and so on. Specific activation conditions which I mentioned in the text will

Location appears

  • For we can define the project's pom.xml profile configuration to a specific project.

  • Configuration profile for a particular user, we can define the user's profile in the settings.xml file. In case the user's home directory ".m2" directory of the file.

  • Global profile configuration. Global profile is defined in the Maven installation directory "conf / settings.xml" file

Activation

  • Activation method is the use of several performance profiles, we achieve the flexibility to deploy to different environments, to meet different conditions we offer different profile, profile we have different configurations by these activation, thus achieving a flexible deployment sex
    • Activation parameters
    We configured as two profile (zxh1, zxh2), two profile in addition to identifying the parameters further configured id properties. Zxhtom When the attribute value of each represent single, double the activation profile.
```
  <profiles>  
       <profile>  
              <id>zxh1</id>  
              <properties>  
                     <zxhtom>single</zxhtom>  
              </properties>  
       </profile>  
       <profile>  
              <id>zxh2</id>  
              <properties>  
                     <zxhtom>double</zxhtom>  
              </properties>  
       </profile>  
  <profiles>
```

  +  环境激活
  
  在部署是符合这些环境要求的电脑则会获取到该profile的配置。这样我们windows上配置和Linux上就不同了。

  ```
  <activation>
    <os>
     <!--激活profile的操作系统的名字 -->
     <name>Windows 7</name>
     <!--激活profile的操作系统所属家族(如 'windows')  -->
     <family>Windows</family>
     <!--激活profile的操作系统体系结构  -->
     <arch>x64</arch>
     <!--激活profile的操作系统版本-->
     <version>x.x.x..</version>
    </os>
  </activation>
  ```

  +  默认激活
      *  activeByDefault激活

      下面的配置在我们部署是没有指定profile时,zxh1这个profile就会成为默认的profile,如果我们指定了那么zxh1就不会被启用。这里要注意这里是不启用。和后面的activeProfiles激活不同。

      ```
      <profiles>  
            <profile>  
                 <id>zxh1</id>  
                 <properties>  
                        <zxhtom>single</zxhtom>  
                 </properties>  
                 <activation>  
                        <activeByDefault>true</activeByDefault>  
                 </activation>  
            </profile>  
              
            <profile>  
                 <id>zxh2</id>  
                 <properties>  
                        <zxhtom>double</zxhtom>  
                 </properties>  
            </profile>  
      </profiles>
      ```

      *  activeProfiles激活
      
      如下图中我们定义zxh1为激活状态,另外我们如果在通过参数或者其他条件激活了zxh2,这里zxh1和zxh2都是出于激活的,并不像activeByDefault激活那样直接停止了。而是两者的覆盖值合并。

      ```
      <profiles>  
       <profile>  
              <id>zxh1</id>  
              <properties>  
                     <zxhtom>single</zxhtom>  
              </properties>  
       </profile>  
       <profile>  
              <id>zxh2</id>  
              <properties>  
                     <zxhtom>double</zxhtom>  
              </properties>  
       </profile>  
      <profiles>
      <activeProfiles>  
         <activeProfile>zxh1</activeProfile>  
      </activeProfiles>  
      ```
    档如下在activeProfiles中配置了多个profile是,maven选择的是后者覆盖合并前者的方式,也就是将zxh1和zxh2合并,相同值去后者的值。
      ```
      <profiles>  
       <profile>  
              <id>zxh1</id>  
              <properties>  
                     <zxhtom>single</zxhtom>  
              </properties>  
       </profile>  
       <profile>  
              <id>zxh2</id>  
              <properties>  
                     <zxhtom>double</zxhtom>  
              </properties>  
       </profile>  
      <profiles>
      <activeProfiles>  
         <activeProfile>zxh1</activeProfile>  
         <activeProfile>zxh2</activeProfile>  
      </activeProfiles>  
      ```

  +  文件激活

    ```
    <activation>
         <file>
         <!--如果指定的文件存在,则激活profile。 -->
         <exists>${basedir}/file2.properties</exists>
         <!--如果指定的文件不存在,则激活profile。-->
         <missing>${basedir}/file1.properties</missing>
         </file>
    </activation>
    ```

[//]: maven setting Reference Site: http://blog.csdn.net/liutengteng130/article/details/46991829
[//]: Setting https://www.cnblogs.com/yangxia-test/p/4409736 .html
[//]: POM http://blog.csdn.net/sunzhenhua0608/article/details/32938533
[//]: Repositories: remote connection warehouse. Mirror mirror can be made by the setting in
[//]: distributionManagement: Managing snapshots version and the final version
[//]: repository: the official version
[//]: snapshotRepository: Snapshot Version
[//]: dependencyManagement: unified management version number

Guess you like

Origin www.cnblogs.com/zhangxinhua/p/11343764.html