[JAVA]_빌드 툴 (build tool)_Maven

전희주·2023년 4월 25일
0

JAVA

목록 보기
21/24

빌드 툴 (build tool)

maven 개념 및 특징, 장점

https://velog.io/@suwon-city-boy/Maven%EA%B3%BC-Gradle-%EB%B9%8C%EB%93%9C-%EA%B4%80%EB%A6%AC-%EB%8F%84%EA%B5%AC%EC%97%90-%EB%8C%80%ED%95%B4

  • 현재

    • 소스파일
      +) jar 다운로드하고 build path
    • 컴파일
    • 실행
  • ✨ 빌드 툴 실행 순서 (maven으로 자동화 가능)

  • 개발시 2~6을 자동 수행해주는 툴: maven (pom.xml), gradle(build.gradle)

    • 1) 소스 파일 작성
    • 2) jar 다운로드 + build path
      • (pom.xml에서 지정)
    • 3) compile : 리소스 복사 후 컴파일 실행
      • => 명령어: mvn compile
    • 4) 소스 파일 검증 (특정 기능 검증), 단위 테스트
      • mvn test
    • 5) 패키징 (압축: jar, war)
      • mvn package
    • 6) 배포
      • 로컬 mvn install
      • maven의 로컬 저장소 경로: C:\Users\TECH5-20.m2\repository\com\app\MavenTest\0.0.1-SNAPSHOT
      • 원격

maven 프로젝트 생성



pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.app</groupId>
  <artifactId>MavenTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
  
 <build>
 	<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
 </build>
</project>


 


maven 실행 단계

compile 수행





install 수행

  • local 까지 배포





jar 다운로드 + build path 수행 (maven dependencies)

https://mvnrepository.com/artifact/org.mybatis/mybatis/3.5.13

    • maven dependencies

  • mvn clean

  • maven dependencies

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.app</groupId>
  <artifactId>MavenTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
  
    
 <dependencies>
     <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
		<dependency>
		    <groupId>org.junit.jupiter</groupId>
		    <artifactId>junit-jupiter-engine</artifactId>
		    <version>5.8.2</version>
		    <scope>test</scope>
		</dependency>
		<dependency>
		    <groupId>com.jslsolucoes</groupId>
		    <artifactId>ojdbc6</artifactId>
		    <version>11.2.0.1.0</version>
		</dependency>
		<dependency>
		    <groupId>org.mybatis</groupId>
		    <artifactId>mybatis</artifactId>
		    <version>3.5.4</version>
		</dependency>
 </dependencies>   
    

    
    
 <build>
 	<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
 </build>
</project>

소스 파일 검증 (특정 기능 검증), 단위 테스트

  • 검증



  • 녹색불 나오면 검증 성공

  • 검증 실패

  • maven으로 상기와 동일 작업 수행

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.app</groupId>
  <artifactId>MavenTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
  
    
 <dependencies>
     <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
		<dependency>
		    <groupId>org.junit.jupiter</groupId>
		    <artifactId>junit-jupiter-engine</artifactId>
		    <version>5.8.2</version>
		    <scope>test</scope>
		</dependency>
		<dependency>
		    <groupId>com.jslsolucoes</groupId>
		    <artifactId>ojdbc6</artifactId>
		    <version>11.2.0.1.0</version>
		</dependency>
		<dependency>
		    <groupId>org.mybatis</groupId>
		    <artifactId>mybatis</artifactId>
		    <version>3.5.4</version>
		</dependency>
 </dependencies>   
    

    
    
 <build>
 	<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      
      
       
       <plugin>
	    <groupId>org.apache.maven.plugins</groupId>
	    <artifactId>maven-surefire-plugin</artifactId>
	    <!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
	    <version>2.22.0</version>
	   </plugin>
    </plugins>
 </build>
</project>

0개의 댓글