Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1144828
  • 博文数量: 312
  • 博客积分: 12522
  • 博客等级: 上将
  • 技术积分: 3376
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-27 18:35
文章分类

全部博文(312)

文章存档

2016年(3)

2015年(1)

2013年(1)

2012年(28)

2011年(101)

2010年(72)

2009年(13)

2008年(93)

分类: 项目管理

2010-04-21 00:43:51

对于团队来说,建立统一的开发环境是必须的,而maven能很好帮助建立统一的环境。下面就介绍如何更有效的进行统一的配置。
准备工作:
   下载必须的软件:
maven2:  最主要的
maven-proxy:用来代理repository,使用代理来访问多个远程库
            
continuum:一个不错的持续整合工具,用于自动build。支持ant,maven
svn:版本控制工具

创建一致的开发环境
   在共享的开发环境中,更好的建议是保持maven的两个不同的配置文件分别管理,包括共享和用户自定义设置。共同的配置包括在安装目录中,而单独的开发设置保存在用户本地目录。
    全局的配置文件settings.xml
xml 代码
  1.    <servers>  
  2.        //公司内部库,所有的release版本,serverid对应于repository id,用于在deploy时,访问使用,主要保存用户名和密码  
  3. <server>  
  4. <id>internalid>  
  5. <username>${website.username}username>  
  6. <password>${website.pwd}password>  
  7. <filePermissions>664filePermissions>  
  8. <directoryPermissions>775directoryPermissions>  
  9. server>  
  10. //目前的开发库,用于snapshot库  
  11. <server>  
  12. <id>snapshotid>  
  13. <username>${website.username}username>  
  14. <password>${website.pwd}password>  
  15. <filePermissions>664filePermissions>  
  16. <directoryPermissions>775directoryPermissions>  
  17. server>  
  18. servers>  
  19.   
  20. <profiles>  
  21.   
  22. <profile>  
  23. <id>central-repoid>  
  24. <repositories>  
  25. <repository>  
  26. <id>centralid>  
  27. <name>Internal Repositoryname>  
  28. <url>url>  
  29. repository>  
  30. repositories>  
  31. <pluginRepositories>  
  32. <pluginRepository>  
  33. <id>centralid>  
  34. <name>Internal Repositoryname>  
  35. <url>url>  
  36. pluginRepository>  
  37. pluginRepositories>  
  38. profile>  
  39.   
  40.   
  41. <profile>  
  42. <id>internal-repoid>  
  43. <repositories>  
  44. <repository>  
  45. <id>internalid>  
  46. <name>Internal Repositoryname>  
  47. <url>url>  
  48. <releases>  
  49. <enabled>trueenabled>  
  50. <updatePolicy>neverupdatePolicy>  
  51. <checksumPolicy>warnchecksumPolicy>  
  52. releases>  
  53. repository>  
  54. repositories>  
  55. <pluginRepositories>  
  56. <pluginRepository>  
  57. <id>internalid>  
  58. <name>Internal Plugin Repositoryname>  
  59. <url>url>  
  60. <releases>  
  61. <enabled>trueenabled>  
  62. <updatePolicy>neverupdatePolicy>  
  63. <checksumPolicy>warnchecksumPolicy>  
  64. releases>  
  65. pluginRepository>  
  66. pluginRepositories>  
  67. profile>  
  68.   
  69. <profile>  
  70. <id>snapshot-repoid>  
  71. <repositories>  
  72. <repository>  
  73. <id>snapshotid>  
  74. <name>Internal Repositoryname>  
  75. <url>url>  
  76. <snapshots>  
  77. <enabled>trueenabled>  
  78. <updatePolicy>interval:60updatePolicy>  
  79. <checksumPolicy>warnchecksumPolicy>  
  80. snapshots>  
  81. repository>  
  82. repositories>  
  83. <pluginRepositories>  
  84. <pluginRepository>  
  85. <id>snapshotid>  
  86. <name>Internal Plugin Repositoryname>  
  87. <url>url>  
  88. <snapshots>  
  89. <enabled>trueenabled>  
  90. <updatePolicy>interval:60updatePolicy>  
  91. <checksumPolicy>warnchecksumPolicy>  
  92. snapshots>  
  93. pluginRepository>  
  94. pluginRepositories>  
  95. profile>  
  96. profiles>  
  97.   
  98. <activeProfiles>  
  99. <activeProfile>central-repoactiveProfile>  
  100. <activeProfile>internal-repoactiveProfile>  
  101. <activeProfile>snapshot-repoactiveProfile>  
  102. activeProfiles>  
  103.   
  104. <pluginGroups>  
  105. <pluginGroup>com.mycompany.pluginspluginGroup>  
  106. pluginGroups>  

包括了以下的共享因素:
服务器设置典型是共同的,只有用户名需要在用户环境中设置。使用一致的定义来配置共同的设置
profile定义了共同的因素,内部开发库,包括指定的组织或者部门发布的产品。这些库独立于核心开发库。
激活的profiles列表,用于激活相应的profile
plugin 组只有当你的组织中有自己定义的插件,用于命令行运行在pom中定义。

对于单独的用户来说,设置如下:
xml 代码
  1. <settings>  
  2. <profiles>  
  3. <profile>  
  4. <id>property-overridesid>  
  5. <properties>  
  6. <website.username>myuserwebsite.username>  
  7. <website.pwd>testwebsite.username>  
  8. properties>  
  9. profile>  
  10. profiles>  
  11. settings>  

创建共享开发库
    大多数组织将会创建自己的内部开发库,用于配置,而中心开发库用于连接maven
    设置内部开发库是简单的,使用http协议,可以使用存在的http 服务器。或者创建新的服务,使用apache,或者jetty
    假设服务器地址192.168.0.2 ,端口8080
    
    设置另外一个开发库,用于设置项目的snapshot库
    中心镜像库,使用maven-proxy创建,当然也可以创建自己的镜像。用于下载本地库中没有的artifact
maven-proxy 设置
    从网上直接下载maven-proxy-standalone-0.2-app.jar和 proxy.properties
    在命令行中,直接运行java -jar maven-proxy-standalone-0.2-app.jar  proxy.properties
主要的配置:
设置repo.list 中增加相应的库就可以,如下定义:
repo.list=repo1.maven.org,...
#maven 的中心库
repo.repo1.maven.org.url=
repo.repo1.maven.org.description=maven.org
repo.repo1.maven.org.proxy=one
repo.repo1.maven.org.hardfail=false
repo.repo1.maven.org.cache.period=360000
repo.repo1.maven.org.cache.failures=true
以后所有的远程库,都通过此方式增加。顺便说一下,不要忘了注释原来的example,那是没有办法访问的。

其他配置如
端口号 port=9999
保存的位置 repo.local.store=target/repo
serverName=

创建标准的组织pom
定义共同的内容,包括公司的结构,如组织,部门以及团队。
察看一下maven 的自身,可以作为很好的参考。
如scm
 
xml 代码
  1. <project>  
  2. <modelVersion>4.0.0modelVersion>  
  3. <parent>  
  4. <groupId>org.apache.mavengroupId>  
  5. <artifactId>maven-parentartifactId>  
  6. <version>1version>  
  7. parent>  
  8. <groupId>org.apache.maven.scmgroupId>  
  9. <artifactId>maven-scmartifactId>  
  10. <url>url>  
  11. ...  
  12. <modules>  
  13. <module>maven-scm-apimodule>  
  14. <module>maven-scm-providersmodule>  
  15. ...  
  16. modules>  
  17. project>      
 

在maven父项目中可以看到如下定义:
 
xml 代码
  1. <project>  
  2. <modelVersion>4.0.0modelVersion>  
  3. <parent>  
  4. <groupId>org.apachegroupId>  
  5. <artifactId>apacheartifactId>  
  6. <version>1version>  
  7. parent>  
  8. <groupId>org.apache.mavengroupId>  
  9. <artifactId>maven-parentartifactId>  
  10. <version>5version>  
  11. <url>url>  
  12. ...  
  13. <mailingLists>  
  14. <mailingList>  
  15. <name>Maven Announcements Listname>  
  16. <post>announce@maven.apache.orgpost>  
  17. ...  
  18. mailingList>  
  19. mailingLists>  
  20. <developers>  
  21. <developer>  
  22. ...  
  23. developer>  
  24. developers>  
  25. project>       

maven 父pom包括了共享的元素,如声明邮件列表,开发者。并且大多数项目继承apache组织:
 
xml 代码
  1. <project>  
  2. <modelVersion>4.0.0modelVersion>  
  3. <groupId>org.apachegroupId>  
  4. <artifactId>apacheartifactId>  
  5. <version>1version>  
  6. <organization>  
  7. <name>Apache Software Foundationname>  
  8. <url>url>  
  9. organization>  
  10. <url>url>  
  11. ...  
  12. <repositories>  
  13. <repository>  
  14. <id>apache.snapshotsid>  
  15. <name>Apache Snapshot Repositoryname>  
  16. <url>url>  
  17. <releases>  
  18. <enabled>falseenabled>  
  19. releases>  
  20. repository>  
  21. repositories>  
  22. ...  
  23. <distributionManagement>  
  24. <repository>  
  25. ...  
  26. repository>  
  27. <snapshotRepository>  
  28. ...  
  29. snapshotRepository>  
  30. distributionManagement>  
  31. project>       

对于项目自身来说,父pom很少更新。所以,最后的方式保存父pom文件在单独的版本控制区域,它们能够check out,更改和配置
使用Continuum持久整合
    持续整合自动build你的项目,通过一定的时间,包括所有的冲突在早期察觉,而不是发布的时候。另外持续整合也是一种很好的开发方式,使团队成员能产生细微的,交互的变动,能更有效的支持平行开发进程。
    可以使用maven的continuum作为持久整合的服务。
    安装continuum,比较简,使用以下的命令:
    C:\mvnbook\continuum-1.0.3> bin\win32\run
    可以通过来验证
    为了支持continuum 发送e-mail提醒,你需要相应的smtp服务用于发送信息。默认使用localhost:25,如果你没有设置,编辑上面的文件改变smtp-host设置。
    下一步,设置svn目录:
    svn co file://localhost/C:/mvnbook/svn/proficio/trunk proficio
    编辑pom.xml用于正确相应得e-mail地址。
 
xml 代码
  1. ...  
  2. <ciManagement>  
  3. <system>continuumsystem>  
  4. <url>
  5. <notifiers>  
  6. <notifier>  
  7. <type>mailtype>  
  8. <configuration>  
  9. <address>youremail@yourdomain.comaddress>  
  10. configuration>  
  11. notifier>  
  12. notifiers>  
  13. ciManagement>  
  14. ...  
  15. <scm>  
  16. <connection>  
  17. scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk  
  18. connection>  
  19. <developerConnection>  
  20. scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk  
  21. developerConnection>  
  22. scm>  
  23. ...  
  24. <distributionManagement>  
  25. <site>  
  26. <id>websiteid>  
  27. <url>  
  28. file://localhost/c:/mvnbook/repository/sites/proficio  
  29. /reference/${project.version}  
  30. url>  
  31. site>  
  32. distributionManagement>      
 

提交相应的pom,然后执行mvn install
如果你返回,你会看到相应的项目列表。
一旦你登录后,你可以选择mavan 2.0项目用于增加相应的项目。你可以增加你的url或者提交你的本地内容。
你可以使用本地pom url,如下file://localhost/c:mvnbook/proficio/pom.xml
在提交了此url后,continuum将会返回相应的成功信息。
以下的原则用于更好的帮助持续整合:
早提交,经常提交:当用户经常提交时,持续整合是最有效的。这并不意味着,提交不正确的代码。
经常运行build:用于最快检测失败
尽快修正失败:当失败发生时,应该马上修正失败
建议一个有效的版本
运行clean build
运行复杂的综合测试
build所有的项目结构分支
持续运行项目的拷贝

阅读(1151) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~