1. 程式人生 > >maven的scm外掛介紹和使用

maven的scm外掛介紹和使用

Maven中為我們集成了軟體配置管理的(SCM:Software Configuration Management)功能,他可以支援我們常用SVN、CVS等,到現在我使用的1.8.1版本,共支援18個命令:

scm:branch - branch the project(建立專案的分支)
scm:validate - validate the scm information in the pom(校驗SCM的配置資訊)
scm:add - command to add file(增加一個檔案)
scm:unedit - command to stop editing the working copy(停止編輯當前COPY)
scm:export
- command to get a fresh exported copy(拉一個全新的分支) scm:bootstrap - command to checkout and build a project(checkout並編譯工程) scm:changelog - command to show the source code revisions(顯示原始碼版本) scm:list - command for get the list of project files(列出工程的檔案) scm:checkin - command for commiting changes(提交變更) scm:checkout - command
for getting the source code(獲取原始碼) scm:status - command for showing the scm status of the working copy(獲取本地專案的狀態) scm:update - command for updating the working copy with the latest changes(從伺服器獲取最新的版本) scm:diff - command for showing the difference of the working copy with the remote one(比較本地與遠端伺服器的差異) scm:update-subprojects - command
for updating all projects in a multi project build(更新子專案) scm:edit - command for starting edit on the working copy(編輯) scm:tag - command for tagging a certain revision(打標籤)

常用命令介紹

而我們常用只有以下這兩個命令:
Usage
The SCM Plugin maps a lot of commands to a variety of scm implementations. But there are only 2 frequently used commands:

checkin - 提交變更
update - 從伺服器上獲取最新的版本

配置及使用

其它的SCM都有自己獨特的命令來操作提交變更、或從伺服器上獲取最新的源嗎,如SVN及CVS的操作就很不相同,使用Maven擔任的SCM機制,就可以使得SCM的操作變得統一,以下是一個SVN配置示例,將以下的示例配置到pom.xml檔案中

<project>
  ...
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>SCM Sample Project</name>
  <url>http://somecompany.com</url>
  <scm>
    <connection>scm:svn:http://somerepository.com/svn_repo/trunk</connection>
    <developerConnection>scm:svn:https://somerepository.com/svn_repo/trunk</developerConnection>
    <url>http://somerepository.com/view.cvs</url>
  </scm>
  ...
</project>

照這樣配置好的,現在我們要做提交或者更新,就按如下按行命令
提交:

mvn -Dmessage="<commit_log_here>" scm:checkin

獲取最新版本:

mvn scm:update

SCM支援的連線型別

SCM支援兩種連線型別:connection 及 developerConnection。
以下是一個連線型別為connection的配置示例:

<project>
  ...
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
        <version>1.8.1</version>
        <configuration>
          <connectionType>connection</connectionType>
        </configuration>
      </plugin>
      ...
    </plugins
    ...
  </build>
  ...
</project>

以下是一個連線型別為developerConnection的配置示例:

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
        <version>1.8.1</version>
        <configuration>
          <connectionType>developerConnection</connectionType>
        </configuration>
      </plugin>
      ...
    </plugins
    ...
  </build>
  ...
</project>