Etc

Maven Phase & Scope & Copy Dependencies

배고픈 징징이 ㅣ 2023. 2. 9. 13:32

1. 설명

  • maven-dependency-plugin의 copy-dependencies를 이용하여 Maven Dependency를 다른 경로로 복사한다.
  • outputDirectory는 복사될 디렉토리 경로 작성
  • excludeArtifactIds에는 복사에서 제외할 Dependency의 Artifact Id를 콤마(,)로 이어서 작성한다.

 

2. Phase

  • process-resources 
  • compile : 소스 코드 컴파일
  • process-test-resources
  • test-compile
  • test : 단위 테스트 프레임워크로 단위 테스트
  • package : 압축 진행
  • install : 로컬 저장소에 압축파일 배포 ( 개발자 PC )
  • deploy : 원격 저장소에 압축파일 배포 ( 메이븐 저장소 )

 

3. Scope

  • compile : Default 값, 프로젝트의 모든 상황에서 포함됨
  • provided : compile과 유사, 의존관계를 제공하는 JDK나 Container에 대해 적용
  • runtime : 컴파일시에는 필요하지 않지만, 실행시 필요함을 의미
  • test : 일반적인 Application에서는 필요 없고, 테스트 컴파일과 실행시에 필요함을 의미
  • system : 명시적으로 해당 Jar를 포함하는 것이 제공되어야 한다는 것을 제외하고 provided와 유사
  • import : dependencyManagement에서 pom의 의존관계에 대체에 사용됨

 

4. 코드

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ...
    
    <build>
        <defaultGoal>install</defaultGoal>
        <directory>${basedir}/server/ROOT/WEB-INF</directory>
        <finalName>${artifactId}-${version}</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/server/lib</outputDirectory>
                            <includeScope>runtime</includeScope>
                            <excludeArtifactIds>junit-jupiter, assertj-core</excludeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    ...
    
    <dependencies>
        ...
    </dependencies>
</project>

 

반응형

'Etc' 카테고리의 다른 글

WebRTC  (0) 2024.07.30
CQRS (Command and Query Responsibility Segregation)  (0) 2024.02.26
Window Fpp 인증 해제 및 신규 인증  (0) 2023.04.05
Git  (0) 2023.01.20
Rest API 참고  (0) 2023.01.19