【Java】Maven配置文件帮助文档(settings.xml 和 pom.xml)

文章目录

  • 1. settings.xml
    • 1.1 localRepository
    • 1.2 interactiveMode
    • 1.3 offline
    • 1.4 pluginGroups
    • 1.5 proxies
    • 1.6 servers
    • 1.7 mirrors
    • 1.8 profiles
    • 1.9 activeProfiles
  • 2. pom.xml
    • 2.1 本项目信息
    • 2.2 父项目信息
    • 2.3 prerequisites
    • 2.4 issueManagement
    • 2.5 ciManagement
    • 2.6 inceptionYear
    • 2.7 mailingLists
    • 2.8 developers
    • 2.9 contributors
    • 2.10 licenses
    • 2.11 scm
    • 2.12 organization
    • 2.13 build
    • 2.14 profiles
    • 2.15 modules
    • 2.16 repositories
    • 2.17 pluginRepositories
    • 2.18 dependencies
    • 2.19 reporting
    • 2.20 dependencyManagement
    • 2.21 distributionManagement
    • 2.22 properties

1. settings.xml

以下几个属性是settings属性的下一级属性:

  • localRepository
  • interactiveMode
  • offline
  • pluginGroups
  • proxies
  • servers
  • mirrors
  • profiles
  • activeProfiles

1.1 localRepository

localRepository:本地仓库的路径,默认值为 ${user.home}/.m2/repository

 
 <localRepository>usr/local/mavenlocalRepository>

1.2 interactiveMode

interactiveMode:表示Maven是否需要和用户交互以获得输入

 
 <interactiveMode>trueinteractiveMode>

1.3 offline

offline:表示Maven是否需要在离线模式下运行

 
 <offline>falseoffline>

1.4 pluginGroups

pluginGroups:插件列表

  • 当插件的组织Id(groupId)没有显式提供时,供搜寻插件组织Id(groupId)的列表。
  • 该元素包含一个pluginGroup元素列表,每个子元素包含了一个组织Id(groupId),当我们使用某个插件,并且没有在命令行为其提供组织Id(groupId)的时候,Maven就会使用该列表。
  • 默认情况下该列表包含了org.apache.maven.plugins和org.codehaus.mojo

 <pluginGroups>
    
    <pluginGroup>org.codehaus.mojopluginGroup>
 pluginGroups>

1.5 proxies

proxies:代理列表,用来配置不同的代理,可以在这台机器上用来连接到网络


 <proxies> 
    
    <proxy>
        <id>myproxyid> 
        <active>trueactive> 
        <protocol>httpprotocol> 
        <host>proxy.somewhere.comhost> 
        <port>8080port> 
        <username>proxyuserusername> 
        <password>somepasswordpassword>  
        <nonProxyHosts>*.google.com|ibiblio.orgnonProxyHosts> 
    proxy>
 proxies>

1.6 servers

servers:表示服务端的一些配置,一些设置如安全证书不应该和pom.xml一起分发,这种类型的信息应该存在于构建服务器上的settings.xml文件中。

  • server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配
  • 鉴权用户名和鉴权密码,表示服务器认证所需要的登录名和密码
  • 鉴权时使用的私钥位置,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)
  • 文件被创建时的权限,如果在部署的时候会创建一个仓库文件或者目录,这时候就可以使用权限(permission),其对应了unix文件系统的权限,如664或775。

 <servers>
    
    <server>
        <id>server001id> 
        <username>my_loginusername> 
        <password>my_passwordpassword> 
        <privateKey>${usr.home}/.ssh/id_dsaprivateKey>  
        <passphrase>some_passphrasepassphrase> 
        <filePermissions>664filePermissions> 
        <directoryPermissions>775directoryPermissions> 
    server>
 servers>

1.7 mirrors

mirrors:为仓库列表配置的下载镜像列表


<mirrors>
    
	<mirror>
		<id>nexus-aliyunid> 
		<mirrorOf>centralmirrorOf> 
		<name>Nexus aliyunname> 
		<url>http://maven.aliyun.com/nexus/content/groups/publicurl> 
	mirror>
mirrors>

1.8 profiles

profiles:表示根据环境参数,来调整构建配置的列表。

activation:控制profile在那种条件下会被激活。

  • jdk:1.4 1.4表示激活JDK1.4、1.4.0_2,而!1.4表示激活所有不以1.4开头的JDK版本
  • os:可以定义一些操作系统相关的属性
  • property:如果Maven检测到某一个属性(其值可以在POM中通过${name}引用),其拥有对应的name = value,Profile就会被激活。如果值字段是空的,那么存在属性名称字段就会激活profile,否则按区分大小写方式匹配属性值字段
  • file:提供一个文件名,通过检测该文件的存在或不存在来激活profile。missing检查文件是否存在,如果不存在则激活profile。另一方面,exists则会检查文件是否存在,如果存在则激活profile。

repositories:远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。

  • layout:用于定位和排序构件的仓库布局类型-可以是default(默认)或者legacy(遗留)。Maven 2为其仓库提供了一个默认的布局;然而,Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)
  • updatePolicy:该元素指定更新发生的频率。Maven会比较本地POM和远程POM的时间戳。这里的选项是:always(一直),daily(默认,每日),interval:X(这里X是以分钟为单位的时间间隔),或者never(从不)。
  • checksumPolicy:当Maven验证构件校验文件失败时该怎么做-ignore(忽略),fail(失败),或者warn(警告)
  • snapshots:如何处理远程仓库里快照版本的下载。有了releases和snapshots这两组配置,POM就可以在每个单独的仓库中,为每种类型的构件采取不同的策略。例如,可能有人会决定只为开发目的开启对快照版本下载的支持。参见repositories/repository/releases元素
 
 <profiles>
    
    <profile>
        
        <id>testid> 

        
        <activation>
            <activeByDefault>falseactiveByDefault> 
            <jdk>1.5jdk>  
            
            <os>
                <name>Windows XPname> 
                <family>Windowsfamily>  
                <arch>x86arch> 
                <version>5.1.2600version> 
            os>
            
            <property>
                <name>mavenVersionname> 
                <value>2.0.3value> 
            property>
            
            <file>
                <exists>${basedir}/file2.propertiesexists> 
                <missing>${basedir}/file1.propertiesmissing> 
            file>
        activation>

        
        <repositories>
            
            <repository>
                <id>codehausSnapshotsid> 
                <name>Codehaus Snapshotsname>    
                <url>http://snapshots.maven.codehaus.org/maven2url>  
                <layout>defaultlayout> 
                
                <releases>
                    <enabled>trueenabled> 
                    <updatePolicy>alwaysupdatePolicy> 
                    <checksumPolicy>warnchecksumPolicy> 
                releases>
                
                <snapshots>
                    <enabled>falseenabled> 
                    <updatePolicy>alwaysupdatePolicy> 
                    <checksumPolicy>warnchecksumPolicy> 
                snapshots>
            repository>
        repositories>

        
        <pluginRepositories>
            
            <pluginRepository>
                <id>codehausSnapshotsid> 
                <name>Codehaus Snapshotsname>    
                <url>http://snapshots.maven.codehaus.org/maven2url>  
                <layout>defaultlayout> 
                
                <releases>      
                    <enabled>trueenabled> 
                    <updatePolicy>alwaysupdatePolicy> 
                    <checksumPolicy>warnchecksumPolicy>
                releases>
                
                <snapshots>
                    <enabled>falseenabled> 
                    <updatePolicy>alwaysupdatePolicy> 
                    <checksumPolicy>warnchecksumPolicy> 
                snapshots>
            pluginRepository>
        pluginRepositories>
        
    profile>
profiles>

1.9 activeProfiles

activeProfiles:手动激活profiles的列表,按照profile被应用的顺序定义activeProfile。任何在activeProfile中定义的profile id,不论环境设置如何,其对应的profile都会被激活。如果没有匹配的profile,则什么都不会发生。

例如,env-test是一个activeProfile,则在pom.xml(或者profile.xml)中对应id的profile会被激活。如果运行过程中找不到这样一个profile,Maven则会像往常一样运行。

<activeProfiles>
    <activeProfile>env-testactiveProfile>
activeProfiles>

2. pom.xml

POM( Project Object Model):项目对象模型,是 Maven 工程的基本工作单元,是一个XML文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖等。

执行任务或目标时,Maven 会在当前目录中查找 POM,它读取 POM,获取所需的配置信息,然后执行目标。

POM 中可以指定以下配置:

  • 项目依赖
  • 插件
  • 执行目标
  • 项目构建 profile
  • 项目版本
  • 项目开发者列表
  • 相关邮件列表信息

2.1 本项目信息

 
<modelVersion> 4.0.0 modelVersion> 

 
<packaging> jar packaging> 

 
<groupId>xxxgroupId> 

 
<artifactId>xxxartifactId> 

 
<version> 1.0-SNAPSHOT version> 

 
<name> xxx-maven name> 

 
<url> http://maven.apache.org url> 

 
<description> A maven project to study maven. description> 

2.2 父项目信息

 
<parent> 
     
    <artifactId>xxxartifactId>

    
    <groupId>xxxgroupId> 

     
    <version>xxxversion>

     
    <relativePath>xxxrelativePath> 
parent> 

2.3 prerequisites

 
<prerequisites> 
     
    <maven>maven> 
prerequisites> 

2.4 issueManagement

 
<issueManagement> 
     
    <system> jira system> 

     
    <url> http://jira.baidu.com/banseon url> 
issueManagement> 

2.5 ciManagement

 
<ciManagement> 
     
    <system>system> 

     
    <url>url> 

     
    <notifiers> 
         
        <notifier> 
             
            <type>type> 

             
            <sendOnError>sendOnError> 

             
            <sendOnFailure>sendOnFailure> 

             
            <sendOnSuccess>sendOnSuccess> 

             
            <sendOnWarning>sendOnWarning> 

             
            <address>address> 

             
            <configuration>configuration> 
        notifier> 
    notifiers> 
ciManagement> 

2.6 inceptionYear

 
<inceptionYear>inceptionYear>

2.7 mailingLists

 
<mailingLists> 
     
    <mailingList> 
         
        <name> Demo name> 

         
        <post> [email protected] post> 

         
        <subscribe> [email protected] subscribe> 

         
        <unsubscribe> [email protected] unsubscribe> 

         
        <archive> http:/hi.baidu.com/banseon/demo/dev/ archive> 
    mailingList> 
mailingLists> 

2.8 developers

 
<developers> 
     
    <developer> 
         
        <id> HELLO WORLD id>
        
         
        <name> banseon name> 

         
        <email> [email protected] email> 

         
        <url>url> 

         
        <roles> 
            <role> Project Manager role> 
            <role> Architect role> 
        roles> 

         
        <organization> demo organization> 

         
        <organizationUrl> http://hi.baidu.com/xxx organizationUrl> 

         
        <properties> 
            <dept> No dept> 
        properties> 

         
        <timezone> -5 timezone> 
    developer> 
developers> 

2.9 contributors

 
<contributors> 
     
    <contributor> 
         
        <name>name>

        
        <email>email>

        
        <url>url>

        
        <organization>organization>

        
        <organizationUrl>organizationUrl>

         
        <roles> 
            <role> Project Manager role> 
            <role> Architect role> 
        roles>

         
        <timezone>timezone>
        
         
        <properties> 
            <dept> No dept> 
        properties>  
    contributor> 
contributors> 

2.10 licenses

 
<licenses> 
     
    <license> 
         
        <name> Apache 2 name> 

         
        <url> http://www.baidu.com/banseon/LICENSE-2.0.txt url> 

         
        <distribution> repo distribution> 

         
        <comments> A business-friendly OSS license comments> 
    license> 
licenses> 

2.11 scm

 
<scm> 
     
    <connection> 
        scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)
    connection> 

     
    <developerConnection> 
        scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk 
    developerConnection> 

     
    <tag>tag> 

     
    <url> http://svn.baidu.com/banseon url> 
scm> 

2.12 organization

 
<organization> 
     
    <name> demo name> 

     
    <url> http://www.baidu.com/banseon url> 
organization> 

2.13 build

 
<build> 
     
    <sourceDirectory>sourceDirectory> 

     
    <scriptSourceDirectory>scriptSourceDirectory> 

     
    <testSourceDirectory>testSourceDirectory> 

     
    <outputDirectory>outputDirectory> 

     
    <testOutputDirectory>testOutputDirectory> 

     
    <extensions> 
         
        <extension> 
             
            <groupId>groupId> 

             
            <artifactId>artifactId> 

             
            <version>version> 
        extension> 
    extensions> 

     
    <defaultGoal>defaultGoal> 

     
    <resources> 
         
        <resource> 
             
            <targetPath>targetPath> 

             
            <filtering>filtering>

             
            <directory>directory>

             
            <includes>
                <include>include>
            includes>

            
            <excludes>
                <exclude>exclude>
            excludes>
        resource> 
    resources> 

     
    <testResources> 
         
        <testResource> 
             
            <targetPath>targetPath> 

             
            <filtering>filtering>

             
            <directory>directory>

             
            <includes>
                <include>include>
            includes>

            
            <excludes>
                <exclude>exclude>
            excludes> 
        testResource> 
    testResources> 

     
    <directory>directory> 

     
    <finalName>finalName> 

     
    <filters>filters> 

     
    <pluginManagement> 
         
        <plugins> 
             
            <plugin> 
                 
                <groupId>groupId> 

                 
                <artifactId>artifactId> 

                 
                <version>version> 

                 
                <extensions>true/falseextensions> 

                 
                <executions> 
                     
                    <execution> 
                         
                        <id>id>

                         
                        <phase>phase>

                         
                        <goals>goals> 

                         
                        <inherited>true/falseinherited> 

                         
                        <configuration>configuration>
                    execution> 
                executions> 

                 
                <dependencies>
                     
                    <dependency> 
                    dependency> 
                dependencies> 

                 
                <inherited>true/falseinherited>

                 
                <configuration>configuration>
            plugin> 
        plugins> 
    pluginManagement> 

     
    <plugins> 
         
        <plugin> 
             
            <groupId>groupId> 

             
            <artifactId>artifactId> 

             
            <version>version> 

             
            <extensions>true/falseextensions> 

             
            <executions> 
                 
                <execution> 
                     
                    <id>id>

                     
                    <phase>phase>

                     
                    <goals>goals> 

                     
                    <inherited>true/falseinherited> 

                     
                    <configuration>configuration>
                execution> 
            executions> 

             
            <dependencies>
                 
                <dependency> 
                dependency> 
            dependencies> 

             
            <inherited>true/falseinherited> 

             
            <configuration>configuration> 
        plugin> 
    plugins>
build> 

2.14 profiles

 
<profiles> 
     
    <profile> 
         
        <id>id>

         
        <activation> 
             
            <activeByDefault>true/falseactiveByDefault> 

             
            <jdk>jdk版本,如:1.7jdk> 

             
            <os> 
                 
                <name> Windows XP name> 

                 
                <family> Windows family> 

                 
                <arch> x86 arch> 

                 
                <version> 5.1.2600 version> 
            os> 

             
            <property> 
                 
                <name> mavenVersion name> 

                 
                <value> 2.0.3 value> 
            property> 

             
            <file> 
                 
                <exists> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ exists> 

                 
                <missing> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ missing> 
            file> 
        activation> 

         
        <build> 
            <defaultGoal /> 
            <resources> 
                <resource> 
                    <targetPath>targetPath>
                    <filtering>filtering>
                    <directory>directory>
                    <includes>
                        <include>include>
                    includes>
                    <excludes>
                        <exclude>exclude>
                    excludes>
                resource> 
            resources> 
            <testResources> 
                <testResource> 
                    <targetPath>targetPath>
                    <filtering>filtering>
                    <directory>directory>
                    <includes>
                        <include>include>
                    includes>
                    <excludes>
                        <exclude>exclude>
                    excludes> 
                testResource> 
            testResources> 
            <directory>directory>
            <finalName>finalName>
            <filters>filters> 
            <pluginManagement> 
                <plugins> 
                     
                    <plugin> 
                        <groupId>groupId>
                        <artifactId>artifactId>
                        <version>version>
                        <extensions>true/falseextensions> 
                        <executions> 
                            <execution> 
                                <id>id>
                                <phase>phase>
                                <goals>goals>
                                <inherited>true/falseinherited>
                                <configuration>configuration> 
                            execution> 
                        executions> 
                        <dependencies> 
                             
                            <dependency> 
                            dependency> 
                        dependencies> 
                        <goals>goals>
                        <inherited>true/falseinherited>
                        <configuration>configuration>
                    plugin> 
                plugins> 
            pluginManagement> 
            <plugins> 
                 
                <plugin> 
                    <groupId>groupId>
                    <artifactId>artifactId>
                    <version>version>
                    <extensions>true/falseextensions> 
                    <executions> 
                        <execution> 
                            <id>id>
                            <phase>phase>
                            <goals>goals>
                            <inherited>true/falseinherited>
                            <configuration>configuration> 
                        execution> 
                    executions> 
                    <dependencies> 
                         
                        <dependency> 
                        dependency> 
                    dependencies> 
                    <goals>goals>
                    <inherited>true/falseinherited>
                    <configuration>configuration> 
                plugin> 
            plugins> 
        build> 

         
        <modules>
            
            <module>module>
        modules> 

         
        <repositories> 
             
            <repository> 
                <releases> 
                    <enabled><enabled>
                    <updatePolicy>updatePolicy>
                    <checksumPolicy>checksumPolicy> 
                releases> 
                <snapshots> 
                    <enabled><enabled>
                    <updatePolicy>updatePolicy>
                    <checksumPolicy>checksumPolicy> 
                snapshots> 
                <id>id>
                <name>name>
                <url>url>
                <layout>layout> 
            repository> 
        repositories> 

         
        <pluginRepositories> 
             
            <pluginRepository> 
                <releases> 
                    <enabled><enabled>
                    <updatePolicy>updatePolicy>
                    <checksumPolicy>checksumPolicy> 
                releases> 
                <snapshots> 
                    <enabled><enabled>
                    <updatePolicy>updatePolicy>
                    <checksumPolicy>checksumPolicy>
                snapshots> 
                <id>id>
                <name>name>
                <url>url>
                <layout>layout> 
            pluginRepository> 
        pluginRepositories> 

         
        <dependencies> 
             
            <dependency> 
            dependency> 
        dependencies> 

         
        <reports>reports> 

         
        <reporting>reporting> 

         
        <dependencyManagement> 
            <dependencies> 
                 
                <dependency> 
                dependency> 
            dependencies> 
        dependencyManagement> 

         
        <distributionManagement> 
        distributionManagement> 

         
        <properties /> 
    profile> 
profiles> 

2.15 modules

 
<modules>
    
    <module>module>
modules> 

2.16 repositories

 
<repositories> 
     
    <repository> 
         
        <releases> 
             
            <enabled><enabled> 

             
            <updatePolicy>updatePolicy> 

             
            <checksumPolicy>checksumPolicy> 
        releases> 

         
        <snapshots> 
            <enabled><enabled>
            <updatePolicy>updatePolicy>
            <checksumPolicy>checksumPolicy> 
        snapshots> 

         
        <id> banseon-repository-proxy id> 

         
        <name> banseon-repository-proxy name> 

         
        <url> http://192.168.1.169:9999/repository/ url> 

         
        <layout> default layout> 
    repository> 
repositories> 

2.17 pluginRepositories

 
<pluginRepositories> 
     
    <pluginRepository> 
    pluginRepository> 
pluginRepositories> 

2.18 dependencies

 
<dependencies> 
    <dependency> 
         
        <groupId> org.apache.maven groupId> 

         
        <artifactId> maven-artifact artifactId> 

         
        <version> 3.8.1 version> 

         
        <type> jar type> 

         
        <classifier>classifier> 

         
        <scope> test scope> 

         
        <systemPath>systemPath> 

         
        <exclusions> 
            <exclusion> 
                <artifactId> spring-core artifactId> 
                <groupId> org.springframework groupId> 
            exclusion> 
        exclusions> 

         
        <optional> true optional> 
    dependency> 
dependencies> 

2.19 reporting

 
<reporting> 
     
    <excludeDefaults /> 

     
    <outputDirectory /> 

     
    <plugins> 
         
        <plugin> 
             
            <groupId>groupId> 
             
            <artifactId>artifactId> 

             
            <version>version> 

             
            <inherited>true/falseinherited> 

             
            <configuration>configuration> 

             
            <reportSets> 
                 
                <reportSet> 
                     
                    <id>id> 

                     
                    <configuration>configuration> 

                     
                    <inherited>true/falseinherited> 

                     
                    <reports>reports> 
                reportSet> 
            reportSets> 
        plugin> 
    plugins> 
reporting> 

2.20 dependencyManagement

 
<dependencyManagement> 
    <dependencies> 
         
        <dependency> 
        dependency> 
    dependencies> 
dependencyManagement> 

2.21 distributionManagement

 
<distributionManagement> 
     
    <repository> 
         
        <uniqueVersion /> 
        <id> banseon-maven2 id> 
        <name> banseon maven2 name> 
        <url> file://${basedir}/target/deploy url> 
        <layout>layout> 
    repository> 

     
    <snapshotRepository> 
        <uniqueVersion /> 
        <id> banseon-maven2 id> 
        <name> Banseon-maven2 Snapshot Repository name> 
        <url> scp://svn.baidu.com/banseon:/usr/local/maven-snapshot url> 
        <layout>layout>
    snapshotRepository> 

     
    <site> 
         
        <id> banseon-site id> 

         
        <name> business api website name> 

         
        <url> 
            scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web 
        url> 
    site> 

     
    <downloadUrl /> 

     
    <relocation> 
         
        <groupId>groupId> 

         
        <artifactId>artifactId> 

         
        <version>version> 

         
        <message>message> 
    relocation> 

     
    <status>status> 
distributionManagement> 

2.22 properties

 
<properties>
    <name>valuename>
properties> 

你可能感兴趣的:(Java,java,maven,xml)