閑人野居
          好好學習,天天向上
          posts - 57,  comments - 137,  trackbacks - 0
          ??? 對于團隊來說,建立統一的開發環境是必須的,而maven能很好幫助建立統一的環境。下面就介紹如何更有效的進行統一的配置。
          準備工作:
          ?? 下載必須的軟件:
          maven2: http://maven.apache.org/download.html 最主要的
          maven-proxy:用來代理repository,使用代理來訪問多個遠程庫
          ?? ??? ??? ?http://maven-proxy.codehaus.org/
          continuum:一個不錯的持續整合工具,用于自動build。支持ant,maven
          http://maven.apache.org/continuum/
          svn:版本控制工具

          創建一致的開發環境
          ??
          ??? 在共享的開發環境中,更好的建議是保持maven的兩個不同的配置文件分別管理,包括共享和用戶自定義設置。共同的配置包括在安裝目錄中,而單獨的開發設置保存在用戶本地目錄。
          ???
          ??? 全局的配置文件settings.xml

          ??
          <servers>
          ?????? //公司內部庫,所有的release版本,serverid對應于repository id,用于在deploy時,訪問使用,主要保存用戶名和密碼
          <server>
          <id>internal</id>
          <username>${website.username}</username>
          <password>${website.pwd}</password>
          <filePermissions>664</filePermissions>
          <directoryPermissions>775</directoryPermissions>
          </server>
          //目前的開發庫,用于snapshot庫
          <server>
          <id>snapshot</id>
          <username>${website.username}</username>
          <password>${website.pwd}</password>
          <filePermissions>664</filePermissions>
          <directoryPermissions>775</directoryPermissions>
          </server>
          </servers>

          <profiles>
          <!--定義核心庫 maven 鏡像,由maven-proxy實現-->
          <profile>
          <id>central-repo</id>
          <repositories>
          <repository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:9999/repository</url>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:9999/repository</url>
          </pluginRepository>
          </pluginRepositories>
          </profile>

          <!--定義內部庫,包括公司的所有release版本-->
          <profile>
          <id>internal-repo</id>
          <repositories>
          <repository>
          <id>internal</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:8080/repo-local</url>
          <releases>
          <enabled>true</enabled>
          <updatePolicy>never</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </releases>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>internal</id>
          <name>Internal Plugin Repository</name>
          <url>http://192.168.0.2:8080/repo-local</url>
          <releases>
          <enabled>true</enabled>
          <updatePolicy>never</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </releases>
          </pluginRepository>
          </pluginRepositories>
          </profile>
          <!--定義內部開發庫 ,也可以合并snapshot和release-->
          <profile>
          <id>snapshot-repo</id>
          <repositories>
          <repository>
          <id>snapshot</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:8080/repo-snapshot</url>
          <snapshots>
          <enabled>true</enabled>
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>snapshot</id>
          <name>Internal Plugin Repository</name>
          <url>http://192.168.0.2:8080/repo-snapshot</url>
          <snapshots>
          <enabled>true</enabled>
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          </pluginRepository>
          </pluginRepositories>
          </profile>
          </profiles>
          <!-- 激活相應得配置-->
          <activeProfiles>
          <activeProfile>central-repo</activeProfile>
          <activeProfile>internal-repo</activeProfile>
          <activeProfile>snapshot-repo</activeProfile>
          </activeProfiles>
          <!-- 插件默認groupId -->
          <pluginGroups>
          <pluginGroup>com.mycompany.plugins</pluginGroup>
          </pluginGroups>

          包括了以下的共享因素:

          • 服務器設置典型是共同的,只有用戶名需要在用戶環境中設置。使用一致的定義來配置共同的設置
          • profile定義了共同的因素,內部開發庫,包括指定的組織或者部門發布的產品。這些庫獨立于核心開發庫。
          • 激活的profiles列表,用于激活相應的profile
          • plugin 組只有當你的組織中有自己定義的插件,用于命令行運行在pom中定義。

          對于單獨的用戶來說,設置如下:

          <settings>
          <profiles>
          <profile>
          <id>property-overrides</id>
          <properties>
          <website.username>myuser</website.username>
          <website.pwd>test</website.username>
          </properties>
          </profile>
          </profiles>
          </settings>


          創建共享開發庫
          ??? 大多數組織將會創建自己的內部開發庫,用于配置,而中心開發庫用于連接maven
          ??? 設置內部開發庫是簡單的,使用http協議,可以使用存在的http 服務器。或者創建新的服務,使用apache,或者jetty
          ??? 假設服務器地址192.168.0.2 ,端口8080
          ?? ?http://192.168.0.2:8080/repo-local
          ??? 設置另外一個開發庫,用于設置項目的snapshot庫http://192.168.0.2:8080/repo-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=http://repo1.maven.org/maven2
          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=http://localhost:9999


          創建標準的組織pom
          定義共同的內容,包括公司的結構,如組織,部門以及團隊。
          察看一下maven 的自身,可以作為很好的參考。
          如scm
          ?

          <project>
          <modelVersion>4.0.0</modelVersion>
          <parent>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-parent</artifactId>
          <version>1</version>
          </parent>
          <groupId>org.apache.maven.scm</groupId>
          <artifactId>maven-scm</artifactId>
          <url>http://maven.apache.org/maven-scm/</url>
          ...
          <modules>
          <module>maven-scm-api</module>
          <module>maven-scm-providers</module>
          ...
          </modules>
          </project>?? ?


          在maven父項目中可以看到如下定義:

          ?
          <project>
          <modelVersion>4.0.0</modelVersion>
          <parent>
          <groupId>org.apache</groupId>
          <artifactId>apache</artifactId>
          <version>1</version>
          </parent>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-parent</artifactId>
          <version>5</version>
          <url>http://maven.apache.org/</url>
          ...
          <mailingLists>
          <mailingList>
          <name>Maven Announcements List</name>
          <post>announce@maven.apache.org</post>
          ...
          </mailingList>
          </mailingLists>
          <developers>
          <developer>
          ...
          </developer>
          </developers>
          </project>?? ?


          maven 父pom包括了共享的元素,如聲明郵件列表,開發者。并且大多數項目繼承apache組織:
          ?
          <project>
          <modelVersion>4.0.0</modelVersion>
          <groupId>org.apache</groupId>
          <artifactId>apache</artifactId>
          <version>1</version>
          <organization>
          <name>Apache Software Foundation</name>
          <url>http://www.apache.org/</url>
          </organization>
          <url>http://www.apache.org/</url>
          ...
          <repositories>
          <repository>
          <id>apache.snapshots</id>
          <name>Apache Snapshot Repository</name>
          <url>http://svn.apache.org/maven-snapshot-repository</url>
          <releases>
          <enabled>false</enabled>
          </releases>
          </repository>
          </repositories>
          ...
          <distributionManagement>
          <repository>
          ...
          </repository>
          <snapshotRepository>
          ...
          </snapshotRepository>
          </distributionManagement>
          </project>?? ?


          對于項目自身來說,父pom很少更新。所以,最后的方式保存父pom文件在單獨的版本控制區域,它們能夠check out,更改和配置.

          使用Continuum持久整合

          ??? 持續整合自動build你的項目,通過一定的時間,包括所有的沖突在早期察覺,而不是發布的時候。另外持續整合也是一種很好的開發方式,使團隊成員能產生細微的,交互的變動,能更有效的支持平行開發進程。
          ??? 可以使用maven的continuum作為持久整合的服務。
          ??? 安裝continuum,比較簡,使用以下的命令:
          ??? C:\mvnbook\continuum-1.0.3> bin\win32\run
          ??? 可以通過http://localhost:8082/continuum來驗證
          ??? 為了支持continuum 發送e-mail提醒,你需要相應的smtp服務用于發送信息。默認使用localhost:25,如果你沒有設置,編輯上面的文件改變smtp-host設置。
          ??? 下一步,設置svn目錄:
          ??? svn co file://localhost/C:/mvnbook/svn/proficio/trunk proficio
          ??? 編輯pom.xml用于正確相應得e-mail地址。

          ?
          ...
          <ciManagement>
          <system>continuum</system>
          <url>http://localhost:8080/continuum
          <notifiers>
          <notifier>
          <type>mail</type>
          <configuration>
          <address>youremail@yourdomain.com</address>
          </configuration>
          </notifier>
          </notifiers>
          </ciManagement>
          ...
          <scm>
          <connection>
          scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk
          </connection>
          <developerConnection>
          scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk
          </developerConnection>
          </scm>
          ...
          <distributionManagement>
          <site>
          <id>website</id>
          <url>
          file://localhost/c:/mvnbook/repository/sites/proficio
          /reference/${project.version}
          </url>
          </site>
          </distributionManagement>?? ?


          提交相應的pom,然后執行mvn install

          如果你返回http://localhost:8082/continuum,你會看到相應的項目列表。

          一旦你登錄后,你可以選擇mavan 2.0項目用于增加相應的項目。你可以增加你的url或者提交你的本地內容。

          你可以使用本地pom url,如下file://localhost/c:mvnbook/proficio/pom.xml

          在提交了此url后,continuum將會返回相應的成功信息。
          以下的原則用于更好的幫助持續整合:
          早提交,經常提交:當用戶經常提交時,持續整合是最有效的。這并不意味著,提交不正確的代碼。
          經常運行build:用于最快檢測失敗
          盡快修正失敗:當失敗發生時,應該馬上修正失敗
          建議一個有效的版本
          運行clean build
          運行復雜的綜合測試
          build所有的項目結構分支
          持續運行項目的拷貝

          posted on 2007-01-07 19:41 布衣郎 閱讀(6573) 評論(5)  編輯  收藏 所屬分類: 配置管理

          FeedBack:
          # re: 使用maven2 進行團隊配置
          2007-01-09 15:18 | 三人行,必有我師焉
          自己沒用過,不過聽說傳說中的maven應該是很不錯的,可以自己建立項目的依賴項,不用一個個的為每個項目編寫Ant腳本。我們公司的項目用maven編譯的時間只是用ant腳本自動編譯時間的20%,讓我著實驚訝了一下,不過最后還是被上面的老大們否決了,最后用的是Eclipse官方的一套標準的編譯框架。  回復  更多評論
            
          # re: 使用maven2 進行團隊配置
          2007-05-15 09:31 | lee5593
          maven deploy好像不支持http協議呀,能不能清楚講解一些本地開發庫用http協議實現該如何進行設置,謝謝!  回復  更多評論
            
          # re: 使用maven2 進行團隊配置
          2007-05-15 20:29 | 布衣郎
          @lee5593
          在deploy的時候,支持如下的幾個協議:
          file:
          <repository>
          ...
          <url>file://${basedir}/target/deploy</url>
          </repository>

          ssh2
          <repository>
          ...
          <url>scp://sshserver.yourcompany.com/deploy</url>
          </repository>

          sftp
          <repository>
          ...
          <url>sftp://ftpserver.yourcompany.com/deploy</url>">ftp://ftpserver.yourcompany.com/deploy</url>
          </repository>

          ftp
          <repository>
          ...
          <url>ftp://ftpserver.yourcompany.com/deploy</url>">ftp://ftpserver.yourcompany.com/deploy</url>
          </repository>  回復  更多評論
            
          # re: 使用maven2 進行團隊配置
          2007-05-15 20:30 | 布衣郎
          一般本地開發庫,直接install就行了
            回復  更多評論
            
          # re: 使用maven2 進行團隊配置
          2008-07-28 14:15 | scmroad
          歡迎來配置管理之路(scmroad)分享關于配置管理的技術和工作感悟。  回復  更多評論
            

          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(12)

          隨筆分類(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 357329
          • 排名 - 155

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 明水县| 金门县| 焉耆| 临漳县| 新野县| 石楼县| 马山县| 城口县| 盈江县| 布拖县| 水富县| 桐梓县| 合作市| 民乐县| 长武县| 桂林市| 岳西县| 沽源县| 图片| 镇远县| 增城市| 三明市| 铁力市| 道孚县| 延寿县| 丘北县| 吉木乃县| 壤塘县| 昂仁县| 页游| 肇州县| 乐平市| 新丰县| 井研县| 洛隆县| 黄陵县| 尖扎县| 阆中市| 宁津县| 哈尔滨市| 封丘县|