반응형

※ 레거시 프로젝트를 운영하다가 정리하게 되었다.

1. pom.xml 에 Nexus 관련 설정을 추가한다

<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<url>http://${NEXUS-HOST}/nexus/content/repositories/releases/</url>
	</repository>

	<snapshotRepository>
		<id>nexus-snapshots</id>
		<url>http://${NEXUS-HOST}/nexus/content/repositories/snapshots/</url>
	</snapshotRepository>
</distributionManagement>

 

  • 여기서 id를 주목해야한다. 3번의 setting.xml 의 id와 동일해야한다.
  • 또한 대표저장소의 id 나 name 속성과 관련이없다.

 

2. pom.xml 에 Plugin 을 추가한다.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-deploy-plugin</artifactId>
<!--				<version>${maven-deploy-plugin.version}</version>-->
	<configuration>
		<skip>true</skip>
	</configuration>
</plugin>

<plugin>
	<groupId>org.sonatype.plugins</groupId>
	<artifactId>nexus-staging-maven-plugin</artifactId>
	<version>1.5.1</version>
	<executions>
		<execution>
			<id>default-deploy</id>
			<phase>deploy</phase>
			<goals>
				<goal>deploy</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<serverId>nexus</serverId>
		<nexusUrl>http://${NEXUS-HOST}/nexus/</nexusUrl>
		<skipStaging>true</skipStaging>
	</configuration>
</plugin>

 

3. settings.xml 에 서버설정을 추가한다.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<!--	<localRepository/>-->
<!--	<interactiveMode/>-->
<!--	<offline/>-->
<!--	<pluginGroups/>-->
	<servers>
		<server>
			<id>nexus-releases</id>
			<username>${id}</username>
			<password>${password}</password>
		</server>
		<server>
			<id>nexus-snapshots</id>
			<username>${id}</username>
			<password>${password}</password>
		</server>
	</servers>
<!--	<mirrors/>-->
<!--	<proxies/>-->
<!--	<profiles/>-->
<!--	<activeProfiles/>-->
</settings>

※ settings.xml 참고 링크 - maven.apache.org/settings.html#Quick_Overview

  • 위에도 언급했지만 id를 주목해야한다. pom.xml 에 설정한 id값과 동일해야한다.
  • 또한 대표저장소의 id 나 name 속성과 관련이없다.

 

4. mvn 명령어를 통해 빌드 결과물을 넥서스에 배포한다.

옵션을 주지않으면 테스트가 실행이 될텐데 아래의 옵션을 통해 스킵할 수 있다.
mvn clean deploy
mvn clean deploy -Dmaven.test.skip=true

 

※ deploy 명령어 참고 링크 - maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html

 

Maven – Guide to deploying 3rd party JARs to remote repository

Guide to deploying 3rd party JARs to remote repository Same concept of the install:install-file goal of the maven-install-plugin where the 3rd party JAR is installed in the local repository. But this time instead to local repository the JAR will be install

maven.apache.org

배포 작업의 경우에는 이 작업이 배포 파이프라인의 마지막 작업이어야 하므로 테스트를 건너뛰어도 좋습니다.  이러한 배포 파이프라인의 일반적인 예로는 Jenkins 작업의 연속이 있으며, 각 작업은 성공적으로 완료될 경우에만 다음 작업을 트리거합니다. 따라서 배포 작업이 실행될 때까지 프로젝트의 모든 테스트 제품군을 실행하는 것은 파이프라인의 이전 작업의 책임입니다. 모든 테스트는 이미 통과해야 합니다.

 

5. 결론

Maven 아티팩트를 Nexus로 배포하기 위한 간단하면서도 매우 효과적인 솔루션입니다. 또한 기본 maven-deploy-plugin 대신 nexus-staging-maven-plugin이 사용되고 스테이징 기능이 비활성화되는 등 어느 정도 의견이 분분합니다. 이러한 선택으로 솔루션을 간단하고 실용적으로 만들 수 있습니다.

 

참고자료) www.baeldung.com/maven-deploy-nexus

 

Maven Deploy to Nexus | Baeldung

Maven Deploy to Nexus - The Nexus Snapshot Repository in the pom and how to set up the Deployment Process.

www.baeldung.com

#

반응형

+ Recent posts