Maven的POM文件详解


一、POM文件总体配置说明

  1 <project xmlns="http://maven.apache.org/POM/4.0.0" 
  2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> 
  4 
  5      
  7     <parent> 
  8          
  9         <artifactId>xxxartifactId>
 10 
 11         
 12         <groupId>xxxgroupId> 
 13 
 14          
 15         <version>xxxversion>
 16 
 17          
 20         <relativePath>xxxrelativePath> 
 21     parent> 
 22 
 23      
 25     <modelVersion> 4.0.0 modelVersion> 
 26 
 27      
 29     <groupId>xxxgroupId> 
 30 
 31      
 34     <artifactId>xxxartifactId> 
 35 
 36      
 37     <packaging> jar packaging> 
 38 
 39      
 40     <version> 1.0-SNAPSHOT version> 
 41 
 42      
 43     <name> xxx-maven name> 
 44 
 45      
 46     <url> http://maven.apache.org url> 
 47 
 48      
 51     <description> A maven project to study maven. description> 
 52 
 53      
 54     <prerequisites> 
 55          
 56         <maven>maven> 
 57     prerequisites> 
 58 
 59      
 60     <issueManagement> 
 61          
 62         <system> jira system> 
 63 
 64          
 65         <url> http://jira.baidu.com/banseon url> 
 66     issueManagement> 
 67 
 68      
 69     <ciManagement> 
 70          
 71         <system>system> 
 72 
 73          
 74         <url>url> 
 75 
 76          
 77         <notifiers> 
 78              
 79             <notifier> 
 80                  
 81                 <type>type> 
 82 
 83                  
 84                 <sendOnError>sendOnError> 
 85 
 86                  
 87                 <sendOnFailure>sendOnFailure> 
 88 
 89                  
 90                 <sendOnSuccess>sendOnSuccess> 
 91 
 92                  
 93                 <sendOnWarning>sendOnWarning> 
 94 
 95                  
 96                 <address>address> 
 97 
 98                  
 99                 <configuration>configuration> 
100             notifier> 
101         notifiers> 
102     ciManagement> 
103 
104      
105     <inceptionYear /> 
106 
107      
108     <mailingLists> 
109          
110         <mailingList> 
111              
112             <name> Demo name> 
113 
114              
115             <post> banseon@126.com post> 
116 
117              
118             <subscribe> banseon@126.com subscribe> 
119 
120              
121             <unsubscribe> banseon@126.com unsubscribe> 
122 
123              
124             <archive> http:/hi.baidu.com/banseon/demo/dev/ archive> 
125         mailingList> 
126     mailingLists> 
127 
128      
129     <developers> 
130          
131         <developer> 
132              
133             <id> HELLO WORLD id>
134             
135              
136             <name> banseon name> 
137 
138              
139             <email> banseon@126.com email> 
140 
141              
142             <url>url> 
143 
144              
145             <roles> 
146                 <role> Project Manager role> 
147                 <role> Architect role> 
148             roles> 
149 
150              
151             <organization> demo organization> 
152 
153              
154             <organizationUrl> http://hi.baidu.com/xxx organizationUrl> 
155 
156              
157             <properties> 
158                 <dept> No dept> 
159             properties> 
160 
161              
162             <timezone> -5 timezone> 
163         developer> 
164     developers> 
165 
166      
167     <contributors> 
168          
169         <contributor> 
170              
171             <name>name>
172 
173             
174             <email>email>
175 
176             
177             <url>url>
178 
179             
180             <organization>organization>
181 
182             
183             <organizationUrl>organizationUrl>
184 
185              
186             <roles> 
187                 <role> Project Manager role> 
188                 <role> Architect role> 
189             roles>
190 
191              
192             <timezone>timezone>
193             
194              
195             <properties> 
196                 <dept> No dept> 
197             properties>  
198         contributor> 
199     contributors> 
200 
201      
203     <licenses> 
204          
205         <license> 
206              
207             <name> Apache 2 name> 
208 
209              
210             <url> http://www.baidu.com/banseon/LICENSE-2.0.txt url> 
211 
212              
215             <distribution> repo distribution> 
216 
217              
218             <comments> A business-friendly OSS license comments> 
219         license> 
220     licenses> 
221 
222      
223     <scm> 
224          
225         <connection> 
226             scm:svn:http://svn.baidu.com/banseon/maven/banseon/banseon-maven2-trunk(dao-trunk)
227         connection> 
228 
229          
230         <developerConnection> 
231             scm:svn:http://svn.baidu.com/banseon/maven/banseon/dao-trunk 
232         developerConnection> 
233 
234          
235         <tag>tag> 
236 
237          
238         <url> http://svn.baidu.com/banseon url> 
239     scm> 
240 
241      
242     <organization> 
243          
244         <name> demo name> 
245 
246          
247         <url> http://www.baidu.com/banseon url> 
248     organization> 
249 
250      
251     <build> 
252          
254         <sourceDirectory>sourceDirectory> 
255 
256          
258         <scriptSourceDirectory>scriptSourceDirectory> 
259 
260          
262         <testSourceDirectory>testSourceDirectory> 
263 
264          
265         <outputDirectory>outputDirectory> 
266 
267          
268         <testOutputDirectory>testOutputDirectory> 
269 
270          
271         <extensions> 
272              
273             <extension> 
274                  
275                 <groupId>groupId> 
276 
277                  
278                 <artifactId>artifactId> 
279 
280                  
281                 <version>version> 
282             extension> 
283         extensions> 
284 
285          
286         <defaultGoal>defaultGoal> 
287 
288          
290         <resources> 
291              
292             <resource> 
293                  
296                 <targetPath>targetPath> 
297 
298                  
300                 <filtering>filtering>
301 
302                  
303                 <directory>directory>
304 
305                  
306                 <includes>
307                     <include>include>
308                 includes>
309 
310                 
311                 <excludes>
312                     <exclude>exclude>
313                 excludes>
314             resource> 
315         resources> 
316 
317          
318         <testResources> 
319              
320             <testResource> 
321                  
324                 <targetPath>targetPath> 
325 
326                  
328                 <filtering>filtering>
329 
330                  
331                 <directory>directory>
332 
333                  
334                 <includes>
335                     <include>include>
336                 includes>
337 
338                 
339                 <excludes>
340                     <exclude>exclude>
341                 excludes> 
342             testResource> 
343         testResources> 
344 
345          
346         <directory>directory> 
347 
348          
349         <finalName>finalName> 
350 
351          
352         <filters>filters> 
353 
354          
356         <pluginManagement> 
357              
358             <plugins> 
359                  
360                 <plugin> 
361                      
362                     <groupId>groupId> 
363 
364                      
365                     <artifactId>artifactId> 
366 
367                      
368                     <version>version> 
369 
370                      
372                     <extensions>true/falseextensions> 
373 
374                      
375                     <executions> 
376                          
377                         <execution> 
378                              
379                             <id>id>
380 
381                              
382                             <phase>phase>
383 
384                              
385                             <goals>goals> 
386 
387                              
388                             <inherited>true/falseinherited> 
389 
390                              
391                             <configuration>configuration>
392                         execution> 
393                     executions> 
394 
395                      
396                     <dependencies>
397                          
398                         <dependency> 
399                         dependency> 
400                     dependencies> 
401 
402                      
403                     <inherited>true/falseinherited>
404 
405                      
406                     <configuration>configuration>
407                 plugin> 
408             plugins> 
409         pluginManagement> 
410 
411          
412         <plugins> 
413              
414             <plugin> 
415                  
416                 <groupId>groupId> 
417 
418                  
419                 <artifactId>artifactId> 
420 
421                  
422                 <version>version> 
423 
424                  
426                 <extensions>true/falseextensions> 
427 
428                  
429                 <executions> 
430                      
431                     <execution> 
432                          
433                         <id>id>
434 
435                          
436                         <phase>phase>
437 
438                          
439                         <goals>goals> 
440 
441                          
442                         <inherited>true/falseinherited> 
443 
444                          
445                         <configuration>configuration>
446                     execution> 
447                 executions> 
448 
449                  
450                 <dependencies>
451                      
452                     <dependency> 
453                     dependency> 
454                 dependencies> 
455 
456                  
457                 <inherited>true/falseinherited> 
458 
459                  
460                 <configuration>configuration> 
461             plugin> 
462         plugins>
463     build> 
464 
465      
466     <profiles> 
467          
468         <profile> 
469              
470             <id>id>
471 
472              
475             <activation> 
476                  
477                 <activeByDefault>true/falseactiveByDefault> 
478 
479                  
481                 <jdk>jdk版本,如:1.7jdk> 
482 
483                  
484                 <os> 
485                      
486                     <name> Windows XP name> 
487 
488                      
489                     <family> Windows family> 
490 
491                      
492                     <arch> x86 arch> 
493 
494                      
495                     <version> 5.1.2600 version> 
496                 os> 
497 
498                  
501                 <property> 
502                      
503                     <name> mavenVersion name> 
504 
505                      
506                     <value> 2.0.3 value> 
507                 property> 
508 
509                  
511                 <file> 
512                      
513                     <exists> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ exists> 
514 
515                      
516                     <missing> /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ missing> 
517                 file> 
518             activation> 
519 
520              
521             <build> 
522                 <defaultGoal /> 
523                 <resources> 
524                     <resource> 
525                         <targetPath>targetPath>
526                         <filtering>filtering>
527                         <directory>directory>
528                         <includes>
529                             <include>include>
530                         includes>
531                         <excludes>
532                             <exclude>exclude>
533                         excludes>
534                     resource> 
535                 resources> 
536                 <testResources> 
537                     <testResource> 
538                         <targetPath>targetPath>
539                         <filtering>filtering>
540                         <directory>directory>
541                         <includes>
542                             <include>include>
543                         includes>
544                         <excludes>
545                             <exclude>exclude>
546                         excludes> 
547                     testResource> 
548                 testResources> 
549                 <directory>directory>
550                 <finalName>finalName>
551                 <filters>filters> 
552                 <pluginManagement> 
553                     <plugins> 
554                          
555                         <plugin> 
556                             <groupId>groupId>
557                             <artifactId>artifactId>
558                             <version>version>
559                             <extensions>true/falseextensions> 
560                             <executions> 
561                                 <execution> 
562                                     <id>id>
563                                     <phase>phase>
564                                     <goals>goals>
565                                     <inherited>true/falseinherited>
566                                     <configuration>configuration> 
567                                 execution> 
568                             executions> 
569                             <dependencies> 
570                                  
571                                 <dependency> 
572                                 dependency> 
573                             dependencies> 
574                             <goals>goals>
575                             <inherited>true/falseinherited>
576                             <configuration>configuration>
577                         plugin> 
578                     plugins> 
579                 pluginManagement> 
580                 <plugins> 
581                      
582                     <plugin> 
583                         <groupId>groupId>
584                         <artifactId>artifactId>
585                         <version>version>
586                         <extensions>true/falseextensions> 
587                         <executions> 
588                             <execution> 
589                                 <id>id>
590                                 <phase>phase>
591                                 <goals>goals>
592                                 <inherited>true/falseinherited>
593                                 <configuration>configuration> 
594                             execution> 
595                         executions> 
596                         <dependencies> 
597                              
598                             <dependency> 
599                             dependency> 
600                         dependencies> 
601                         <goals>goals>
602                         <inherited>true/falseinherited>
603                         <configuration>configuration> 
604                     plugin> 
605                 plugins> 
606             build> 
607 
608              
610             <modules>
611                 
612                 <module>module>
613             modules> 
614 
615              
616             <repositories> 
617                  
618                 <repository> 
619                     <releases> 
620                         <enabled><enabled>
621                         <updatePolicy>updatePolicy>
622                         <checksumPolicy>checksumPolicy> 
623                     releases> 
624                     <snapshots> 
625                         <enabled><enabled>
626                         <updatePolicy>updatePolicy>
627                         <checksumPolicy>checksumPolicy> 
628                     snapshots> 
629                     <id>id>
630                     <name>name>
631                     <url>url>
632                     <layout>layout> 
633                 repository> 
634             repositories> 
635 
636              
637             <pluginRepositories> 
638                  
639                 <pluginRepository> 
640                     <releases> 
641                         <enabled><enabled>
642                         <updatePolicy>updatePolicy>
643                         <checksumPolicy>checksumPolicy> 
644                     releases> 
645                     <snapshots> 
646                         <enabled><enabled>
647                         <updatePolicy>updatePolicy>
648                         <checksumPolicy>checksumPolicy>
649                     snapshots> 
650                     <id>id>
651                     <name>name>
652                     <url>url>
653                     <layout>layout> 
654                 pluginRepository> 
655             pluginRepositories> 
656 
657              
659             <dependencies> 
660                  
661                 <dependency> 
662                 dependency> 
663             dependencies> 
664 
665              
666             <reports>reports> 
667 
668              
670             <reporting>reporting> 
671 
672              
673             <dependencyManagement> 
674                 <dependencies> 
675                      
676                     <dependency> 
677                     dependency> 
678                 dependencies> 
679             dependencyManagement> 
680 
681              
682             <distributionManagement> 
683             distributionManagement> 
684 
685              
686             <properties /> 
687         profile> 
688     profiles> 
689 
690      
691     <modules>
692         
693         <module>module>
694     modules> 
695 
696      
697     <repositories> 
698          
699         <repository> 
700              
701             <releases> 
702                  
703                 <enabled><enabled> 
704 
705                  
707                 <updatePolicy>updatePolicy> 
708 
709                  
710                 <checksumPolicy>checksumPolicy> 
711             releases> 
712 
713              
715             <snapshots> 
716                 <enabled><enabled>
717                 <updatePolicy>updatePolicy>
718                 <checksumPolicy>checksumPolicy> 
719             snapshots> 
720 
721              
722             <id> banseon-repository-proxy id> 
723 
724              
725             <name> banseon-repository-proxy name> 
726 
727              
728             <url> http://192.168.1.169:9999/repository/ url> 
729 
730              
732             <layout> default layout> 
733         repository> 
734     repositories> 
735 
736      
737     <pluginRepositories> 
738          
739         <pluginRepository> 
740         pluginRepository> 
741     pluginRepositories> 
742 
743      
745     <dependencies> 
746         <dependency> 
747              
748             <groupId> org.apache.maven groupId> 
749 
750              
751             <artifactId> maven-artifact artifactId> 
752 
753              
754             <version> 3.8.1 version> 
755 
756              
759             <type> jar type> 
760 
761              
764             <classifier>classifier> 
765 
766              
774             <scope> test scope> 
775 
776              
778             <systemPath>systemPath> 
779 
780              
782             <exclusions> 
783                 <exclusion> 
784                     <artifactId> spring-core artifactId> 
785                     <groupId> org.springframework groupId> 
786                 exclusion> 
787             exclusions> 
788 
789              
791             <optional> true optional> 
792         dependency> 
793     dependencies> 
794 
795      
796     <reports>reports> 
797 
798      
799     <reporting> 
800          
801         <excludeDefaults /> 
802 
803          
804         <outputDirectory /> 
805 
806          
807         <plugins> 
808              
809             <plugin> 
810                  
811                 <groupId>groupId> 
812                  
813                 <artifactId>artifactId> 
814 
815                  
816                 <version>version> 
817 
818                  
819                 <inherited>true/falseinherited> 
820 
821                  
822                 <configuration>configuration> 
823 
824                  
827                 <reportSets> 
828                      
829                     <reportSet> 
830                          
831                         <id>id> 
832 
833                          
834                         <configuration>configuration> 
835 
836                          
837                         <inherited>true/falseinherited> 
838 
839                          
840                         <reports>reports> 
841                     reportSet> 
842                 reportSets> 
843             plugin> 
844         plugins> 
845     reporting> 
846 
847      
850     <dependencyManagement> 
851         <dependencies> 
852              
853             <dependency> 
854             dependency> 
855         dependencies> 
856     dependencyManagement> 
857 
858      
860     <distributionManagement> 
861          
862         <repository> 
863              
865             <uniqueVersion /> 
866             <id> banseon-maven2 id> 
867             <name> banseon maven2 name> 
868             <url> file://${basedir}/target/deploy url> 
869             <layout>layout> 
870         repository> 
871 
872          
874         <snapshotRepository> 
875             <uniqueVersion /> 
876             <id> banseon-maven2 id> 
877             <name> Banseon-maven2 Snapshot Repository name> 
878             <url> scp://svn.baidu.com/banseon:/usr/local/maven-snapshot url> 
879             <layout>layout>
880         snapshotRepository> 
881 
882          
883         <site> 
884              
885             <id> banseon-site id> 
886 
887              
888             <name> business api website name> 
889 
890              
891             <url> 
892                 scp://svn.baidu.com/banseon:/var/www/localhost/banseon-web 
893             url> 
894         site> 
895 
896          
898         <downloadUrl /> 
899 
900          
901         <relocation> 
902              
903             <groupId>groupId> 
904 
905              
906             <artifactId>artifactId> 
907 
908              
909             <version>version> 
910 
911              
912             <message>message> 
913         relocation> 
914 
915          
918         <status>status> 
919     distributionManagement> 
920 
921      
923     <properties>
924         <name>valuename>
925     properties> 
926 project> 

二、POM文件单项配置说明

1. localRepository

1  
2  <localRepository>usr/local/mavenlocalRepository>

2. interactiveMode

1  
2  <interactiveMode>trueinteractiveMode>

3. usePluginRegistry

1 
2  <usePluginRegistry>falseusePluginRegistry>

4. offline

1  
2  <offline>falseoffline>

5. pluginGroups

1 
2  <pluginGroups>
3   
4   <pluginGroup>org.codehaus.mojopluginGroup>
5  pluginGroups>

6. proxies

 1 
 2  <proxies>
 3   
 4   <proxy>
 5    
 6    <id>myproxyid>
 7    
 8    <active>trueactive>
 9    
10    <protocol>httpprotocol>
11    
12    <host>proxy.somewhere.comhost>
13    
14    <port>8080port>
15    
16    <username>proxyuserusername>
17    
18    <password>somepasswordpassword>
19    
20    <nonProxyHosts>*.google.com|ibiblio.orgnonProxyHosts>
21   proxy>
22  proxies>

7. servers

 1 
 2  <servers>
 3   
 4   <server>
 5    
 6    <id>server001id>
 7    
 8    <username>my_loginusername>
 9    
10    <password>my_passwordpassword>
11    
12    <privateKey>${usr.home}/.ssh/id_dsaprivateKey>
13    
14    <passphrase>some_passphrasepassphrase>
15    
16    <filePermissions>664filePermissions>
17    
18    <directoryPermissions>775directoryPermissions>
19   server>
20  servers>

8. mirrors

 1 
 2  <mirrors>
 3   
 4   <mirror>
 5    
 6    <id>planetmirror.comid>
 7    
 8    <name>PlanetMirror Australianame>
 9    
10    <url>http://downloads.planetmirror.com/pub/maven2url>
11    
12    <mirrorOf>centralmirrorOf>
13   mirror>
14  mirrors>

9. profiles

1  
2  <profiles>
3   
4   <profile>
5    
6    <id>testid>

10. Activation

 1 
 2    <activation>
 3     
 4     <activeByDefault>falseactiveByDefault>
 5     
 6     <jdk>1.5jdk>
 7     
 8     <os>
 9      
10      <name>Windows XPname>
11      
12      <family>Windowsfamily>
13      
14      <arch>x86arch>
15      
16      <version>5.1.2600version>
17     os>
18     
19     <property>
20      
21      <name>mavenVersionname>
22      
23      <value>2.0.3value>
24     property>
25     
26     <file>
27      
28      <exists>${basedir}/file2.propertiesexists>
29      
30      <missing>${basedir}/file1.propertiesmissing>
31     file>
32    activation>

11. Repositories

 1   
 2    <repositories>
 3     
 4     <repository>
 5      
 6      <id>codehausSnapshotsid>
 7      
 8      <name>Codehaus Snapshotsname>
 9      
10      <releases>
11       
12       <enabled>falseenabled>
13       
14       <updatePolicy>alwaysupdatePolicy>
15       
16       <checksumPolicy>warnchecksumPolicy>
17      releases>
18      
19      <snapshots>
20       <enabled/><updatePolicy/><checksumPolicy/>
21      snapshots>
22      
23      <url>http://snapshots.maven.codehaus.org/maven2url>
24      
25      <layout>defaultlayout>
26     repository>
27    repositories>
28    
29    <pluginRepositories>
30     
31           <pluginRepository>           
32      <releases>      
33       <enabled/><updatePolicy/><checksumPolicy/>
34      releases>
35      <snapshots>
36       <enabled/><updatePolicy/><checksumPolicy/>
37      snapshots>
38      <id/><name/><url/><layout/>
39           pluginRepository>
40         pluginRepositories>
41   profile>
42  profiles>

12. activeProfiles

1 
3    <activeProfiles>
4     <activeProfile>env-testactiveProfile>
5    activeProfiles>
6 settings>