반응형

Maven - Build Automation


(원문 위치 : http://www.tutorialspoint.com/maven/maven_build_automation.htm )


Build Automation은 프로젝트 빌드가 성공적으로 완료된 이후  의존적 프로젝트가 안정적으로 되어질 수 있도록 의존적 프로젝트 빌드 프로세스가 시작되는 시나리오를 정의한다.


Example

팀이 다른 두 프로젝트 app_web_ui와 app_desktop_ui가 종속된 프로젝트를 개발하고 있다고 가정하자. bus_core_api 프로젝트는 C:\ > MVN 디렉토리에 있고 app_web_ui와 app_desktop_ui는 C:\ > MVN > projects 디렉토리에 있다.


app_web_ui 프로젝트는 bus_cor_api프로젝트의 1.0-SNAPSHOT을 사용하고 있다.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>app_web_ui</groupId>
   <artifactId>app_web_ui</artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
   <name>app_web_ui</name>
   <url>http://maven.apache.org</url>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
	  <dependency>
         <groupId>bus_core_api</groupId>
         <artifactId>bus_core_api</artifactId>
         <version>1.0-SNAPSHOT</version>
		 <scope>system</scope>
		 <systemPath>C:\MVN\bus_core_api\target\bus_core_api-1.0-SNAPSHOT.jar</systemPath>
      </dependency>
   </dependencies>
</project>

app-desktop_ui프로젝트는 bus_core_api프로젝트의 1.0-SNAPSHOT을 사용하고 있다.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>app_desktop_ui</groupId>
   <artifactId>app_desktop_ui</artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
   <name>app_desktop_ui</name>
   <url>http://maven.apache.org</url>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>
	  <dependency>
         <groupId>bus_core_api</groupId>
         <artifactId>bus_core_api</artifactId>
         <version>1.0-SNAPSHOT</version>
		 <scope>system</scope>
		 <systemPath>C:\MVN\bus_core_api\target\bus_core_api-1.0-SNAPSHOT.jar</systemPath>
      </dependency>
   </dependencies>
</project>

bus_core_api 프로젝트

<project xmlns="http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>bus_core_api</groupId>
   <artifactId>bus_core_api</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>   
</project>

이제 app_web_ui와 app_desktop_ui 프로젝트의 팀은 bus_core_api 프로젝트가 변하는 언제라도 빌드 프로세스가 시작되어야 할 필요가 있다.


Snapshot을 사용하는 것은 최종 bus_core_api플젝트가 사용되어지는 것을 확실하게 하지만 필요한 위의 요청을 만나는 것은 추가적인 작 무엇인가가 필요하다.


두가지 방법이 있다.

- app_web_ui가 시작되기 위한 bus_core_api pom에 post_build 목표를 추가하고 app_desktop_ui를 빌드한다.

- 자동적으로 build automation을 관리하기 위한 Hudson같은 Continuous Integration(CI) 서버를 사용한다.

Using Maven

bus_core_api프로젝트 pom을 갱신하자.

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>bus_core_api</groupId>
   <artifactId>bus_core_api</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <build>
      <plugins>
         <plugin>            
            <artifactId>maven-invoker-plugin</artifactId>
            <version>2.0.0</version>
            <configuration>
               <debug>true</debug>		
			   <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>			   
	           <projectsDirectory>C:/MVN/projects</projectsDirectory>			   
            </configuration>			
            <executions>
               <execution>
                  <id>integration-test</id>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>     
   </dependencies>
</project>

콘솔을 열고 C:\ > MVN > bus_core_api디렉토리로 가서 아래 mvn명령을 실행한다.

C:\MVN\bus_core_api>mvn verify

Maven은 bus_core_api프로젝트 빌딩을 시작할 것이다.

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bus_core_api 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ bus_core_api ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\bus_core_api\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ bus_core_api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ bus_core_api ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\bus_core_api\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ bus_core_api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ bus_core_api ---
[INFO] Surefire report directory: C:\MVN\bus_core_api\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running bus_core_api.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ bus_core_api ---
[INFO]
[INFO] --- maven-invoker-plugin:2.0.0:run (integration-test) @ bus_core_api ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Building: app_desktop_ui\pom.xml
[INFO] ..SUCCESS (10.7 s)
[INFO] Building: app_web_ui\pom.xml
[INFO] ..SUCCESS (11.5 s)
[INFO] Building: bus_core_api\pom.xml
[INFO] ..SUCCESS (12.8 s)
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 3, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 42.421 s
[INFO] Finished at: 2015-09-27T17:41:42+05:30
[INFO] Final Memory: 12M/247M
[INFO] ------------------------------------------------------------------------

Using Continuous Integration Service with Maven

CI서버를 사용하는 것은 개발자가 매번 새로운 프로젝트마다 bus_core_api pom을 갱신할 필요가 없어 더욱 낫다. 예를 들머 app-mobil-ui가 bus_core_api 프로젝트에 의존하도록 추가되었다. Hudson은 자동적으로 Maven dependency management를 사용하여 build automation을 관리한다.

automated build

Hudson은 job으로써 각 프로젝트를 생각한다. 프로젝트 코드가 SVN(또는 Hudson에 매핑돈 어떤 소스 관리 툴)에 체크인된 이후, Hudson은 이것의 빌드 잡을 시작하고 job이 완료된 이후 자동적으로 다른 의존된 job(다른 의존 프로젝트)를 시작한다.

위 예제에서 bus-core-ui소스코드가 SVN에 갱신되었을 때, Hudson은 이것의 빌드를 시작한다. 빌드가 성곧적으로 끝난 이후 Hudson은 자동적으로 의존하는 프로젝트를 찾고 spp_web_ui와 app_desktop_ui프로젝트 빌딩을 시작한다.

반응형

+ Recent posts