요즘은 java 프로젝트를 gradle로 많이 하지만 나는 maven을 사용 중이다.
맨날 쓰는 maven command line이 있지만, 정확히 어떤 의미인지를 파악해봐야겠다.
인텔리제이 로컬 환경에서 package명령어는 성공하나 deploy가 안되는데 그 이유가 궁금하여 확인해보게되었다.

아파치 공식문서

https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.

maven이란.

maven은 pom.xml에 description된 정보를 기반으로 프로젝트를 build한다.
goal이란 maven이 행할 수 있는 여러가지 동작을 수행하는 명령어를 의미.

어떤 goal이 있을까?

clean

  • 컴파일 결과물인 target 디렉토리 삭제.

compile

  • compile the source code of the project
  • 모든 소스코드를 컴파일하고 리소스파일은 target/classes 디렉토리에 복사.

package

  • take the compiled code and package it in its distributable format, such as a JAR.
  • compile 수행 후 pom에 있는 정보에 따라 패키징을 수행.
  • description example.
    <executions>
                   <execution>
                       <id>package</id>
                       <phase>package</phase>
                       <goals>
                           <goal>run</goal>
                       </goals>
                       <configuration>
                           <tasks>
                               <copy file="${project.build.directory}/${project.build.finalName}.jar.original"
                                     tofile="./deploy/my-project/${project.build.finalName}.jar"/>
                               <copy todir="./deploy/my-project/bin">
                                   <fileset dir="bin"/>
                               </copy>
                               <copy todir="./deploy/my-project/conf">
                                   <fileset dir="conf"/>
                               </copy>
                               <copy todir="./deploy/my-project/lib">
                                   <fileset dir="${project.build.directory}/dependency/"/>
                               </copy>
                           </tasks>
                       </configuration>
                   </execution>
                   ....
                 <executions>
                   <execution>
                       <phase>package</phase>
                       <goals>
                           <goal>copy-dependencies</goal>
                       </goals>
                       <configuration>
                           <outputDirectory>${project.build.directory}/dependency/</outputDirectory>
                       </configuration>
                   </execution>
               </executions>

install

  • install the package into the local repository, for use as a dependency in other projects locally
  • package 수행 후 local repo에 pakage를 설치. 로컬 다른 프로젝트에서 사용가능함.

validate

  • validate the project is correct and all necessary information is available
  • 프로젝트가 사용 가능한지 확인.

test

  • test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • unit test 수행

deploy

  • done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
  • 환경구성을 마치고 remote repository에 package들을 copy. 실제 릴리즈할때의 배포.

실제로 내가 배포할때 사용하는 명령어.

mvn -U clean --update-snapshots dependency:copy-dependencies package -Dmaven.test.skip=true -Dmaven.test.skip=true

+ Recent posts