Maven Build 시 test 건너뛰기 

Maven Build (install) 시 Maven Test 이후에 Build를 하게 된다.

이때 jUnit 테스트 에서 Exception 발생 및 Assert not Equal 등으로 Test가 실패할 경우 Build 는 실패 (Fail) 하게 된다.

jUnit Test 가 실패해도 Build 는 되게끔 Maven Test 단계를 건너뛰는 방법은 아래와 같다.

 

1. CMD 에서 빌드시

mvn install -DskipTests 

 

2. IDE Run configurations 에서 빌드시

1. Goals 에 다음과 같이 옵션 부여 : install -DskipTests 

2. Skip Tests 체크박스 체크 후 run

3. pom 수정 : surefire plugin 사용 (skipTests 속성 값 true/false 로 지정)

1
2
3
4
5
6
7
8
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M4</version>
    <configuration>
      <skipTests>true</skipTests>
    </configuration>
</plugin>
cs

 

surefire doc:

https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html

반응형

Maven error (Missing artifact error)

pom.xml 내의 dependency 설정이 잘못되었거나 repository 로 부터 dependency jar 들을 가져오지 못하는 경우 발생하는 에러.

 

pom.xml 에 딱히 이상이 없고 project clean 을 해봐도 해당 에러가 해결되지 않는다면,

Update maven 에서 Snapshots/Releases 강제 업데이트 옵션을 체크 후 maven update.

 

참고 : https://examples.javacodegeeks.com/enterprise-java/maven/maven-resolve-missing-artifact-error-example/

반응형

운영, 테스트서버, 개발서버 와 같이 서버가 3개가 구성되어있고,

각각의 서버별로 사용하는 jar가 달라야 할 때, 서버 환경에 맞게 jar를 빌드하여 서버에 배포해보자.

 

* 서버 환경별로 jar 내부적으로 소켓통신을 하는 목적지 ip가 달라 jar가 총 3개 존재했고..

   war 를 어떤 서버에 배포하느냐에 따라 jar를 바꿔서 빌드 후, 서버에 배포해야 했던 상황

** 소스내에서 갖다 쓰는 jar 내부의 메소드 자체를 수정하여 목적지 서버 ip를 파라미터로 받게끔 처리해주는게 베스트..

    하지만 jar 만드신 분이 본인보다 상급자라면 별 수 없다.

 

 

1) pom.xml 에 profiles 설정 및 local repository 설정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<repositories>
      <repository>
         <id>local-repository</id>
         <url>file:${basedir}/repo</url>
      </repository>
       </repositories>
    
    <profiles>
      <profile>
         <id>dev</id>
         <dependencies>
            <dependency>
               <groupId>chat</groupId>
               <artifactId>chatmodule-dev</artifactId>
               <version>0.0.6</version>
            </dependency>
         </dependencies>
      </profile>
      <profile>
         <id>tb</id>
         <dependencies>
            <dependency>
               <groupId>chat</groupId>
               <artifactId>chatmodule-tb</artifactId>
               <version>0.0.6</version>
            </dependency>
         </dependencies>
      </profile>
      <profile>
         <id>live</id>
         <dependencies>
            <dependency>
               <groupId>chat</groupId>
               <artifactId>chatmodule-</artifactId>
               <version>0.0.6</version>
            </dependency>
         </dependencies>
      </profile>
   </profiles>
cs

 

2) 프로젝트 내에 local repository 구성

repo > chat > chatmodule/chatmodule-dev/chatmodule-tb > 0.0.6 > chatmodule-~.jar 와 같이 구성

chatmodule-~.jar : 운영서버 배포시 사용될 jar

chatmodule-tb~.jar : 테스트서버 배포시 사용될 jar

chatmodule-dev~.jar : 개발서버 배포시 사용될 jar

 

 

3) Maven Profile 선택

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Maven > Select Maven Profiles 클릭.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

활성화 시킬 profile(dev/tb/live) 선택

 

 

4) Maven update

 

5) Maven Build (war 파일 생성)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

profile(dev/tb/live) 선택

 

 

6) war 파일 및 jar 확인

빌드가 성공적으로 끝났으면,

workspace/프로젝트/war파일명/target/WEB-INF/lib/

경로로 이동하여 지정한 profile 의 jar가 잘 들어갔는지 확인.

 

 

위와 같이 profile 을 사용하여 환경별 jar 를 동적으로 사용하는게 아닌,

단순히 로컬(프로젝트 내)에 존재하는 jar 1개를 사용하고자 할 경우

local repository 를 잡을 필요 없이 아래와 같이 scope 를 system 으로 주고 프로젝트 내에서 jar 를 가져다 사용할 수 있다.

1
2
3
4
5
6
7
<dependency>
    <groupId>chat</groupId>
    <artifactId>mobile</artifactId>
    <version>0.0.1</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/chat_0.0.1.jar</systemPath>
</dependency>
cs

 

반응형

+ Recent posts