티스토리 뷰
springboot로 구현된 A,B프로젝트가 있다고 하자. 그리고 상황은 A프로젝트가 독립적으로 실행이 되어야 하고 또한 B 프로젝트에는 dependency로 포함이 되어야 한다.
그냥 똑같이 빌드해서 자체실행도 하고 다른 프로젝트에 dependency로 넣으면 안되냐고 할수 있다. 하지만 안된다.
이 상황을 해결한 방법은 Maven Profile에 따라서 빌드를 두번 해주는 방법이었다.
pom.xml에 Maven Profile 적용
<profiles> <profile> <id>dependencyPurpose</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>repackage</id> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>standalonePurpose</id> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </profile> </profiles>
위와 같이 <build> 라는 항목에 대해 profile에 따라 분기하였다. 이처럼 pom.xml 항목 중 최상위 속성(dependencies, properties..)들을 기준으로 profile을 적용할 수 있다.
필자는 하나의 application을 dependency와 standalone 용도에 따라 빌드를 하게 profile을 적용했다.
dependency로 A프로젝트가 B프로젝트로 들어가기 위해서는 repackage를 해줘야 했고 standalone으로 돌리기 위해서는 그냥 사용하던대로 spring-boot-maven-plugin만 있으면 된다.
Maven Profile 선택 후 빌드
1. dependencyPurpose profile 빌드
mvn clean install
profile 중 dependencyPurpose를 선택하기 위해서는 위와 같이 아무것도 입력하지 않아도 된다. 왜냐면 위의 pom.xml에서 dependencyPurpose를 activeByDefault로 해놨기 때문이다. 아무런 옵션을 주지 않아도 dependencyPurpose 라는 profile이 적용되어 다른 프로젝트로 들어갈 수 있는 jar로 빌드가 되게 된다.
2. standalonePurpose profile 빌드
mvn clean install -pl A프로젝트 -am -P standalonePurpose
activeByDefault가 아닌 빌드를 할 경우는 위와 같은 방식으로 한다. 프로젝트 명을 명시해 주고(-pl) 프로젝트 목록이 지정된 경우 목록에 필요한 프로젝트도 빌드하고(-am) standalonePurpose로 profile(-P) 빌드하라는 명령이다. 이와 같이 수행을 하면 독립적으로 실행할 수 있는 jar로 빌드가 되게 된다.
maven option은 다음 글을 참조하도록 하자.
Maven 명령어 및 옵션 모음
maven에서 사용할 수 있는 명령어들에 정리해본다. command desc compile 컴파일 수행 test 컴파일 수행 후 테스트 클래스 수행 package 컴파일을 수행하고 컴파일한 소스를 packaging 양식(war or jar)에 맞춰 프
oingdaddy.tistory.com
끝!
'CI,CD > Build' 카테고리의 다른 글
Maven Profile에 따라 dependency 변경하기 (0) | 2022.03.18 |
---|---|
Maven : Updating Maven Project has encountered a problem 오류 조치 (0) | 2022.02.21 |
Maven source code 포함해서 build 하기 (w. Springboot) (0) | 2021.11.09 |
Maven Build 중 ChecksumFailureException 오류 조치 (0) | 2021.06.23 |
Maven build 시 illegal character: '\ufeff' 오류 조치 (0) | 2021.05.27 |