버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

목차

Maven Deploy는 Maven으로 빌드한 바이너리 및 소스코드 등을 Maven Repository에 업로드하여 Maven Repository를 통해 배포하는 것을 의미합니다.

정보
title참고
  • Nexus Repository 란 ?

...

  • 오픈소스 repository로, 사설 라이브러리 및 포워딩 용도로 사용할 수

...

  • 있습니다.
  • 본 문서는 Deploy 위주로 작성되어 설치와 설정은 간략하게 나와있습니다.

...

  • Maven Deploy 페이지를 보시면 설치부터 미러링까지 보다 자세하게 알 수 있습니다.
  • 설치환경
    • Host OS : Windows 10 Pro
    • Guest OS (VM Virtual Box) 

...

    • : CentOS 7
    • Guest에 Nexus Repository Server 3 설치

Vagrant + CentOS 7에서 Nexus Repository Server 설치

Vagrant 접속

  • Vagrant로 VM VirtualBox를 실행하려면, Windows command 창에 vagrant up 명령어 실행 후 vagrant ssh 명령어로 shell 을 실행합니다.
  • (Vagrant Provision을 사용해도 되지만 설치 과정에서 에러가 생길 수 있어서 shell로 접속하여 설치하는게 안전합니다)

패키지 다운로드

코드 블럭
linenumberstrue
# nexus repository 패키지 설치
$ wget install https://download.sonatype.com/nexus/3/latest-unix.tar.gz   --no-check-certificate
# 설치 후 압축 해제
$ tar -xvf latest-unix.tar.gz
# 압축 해제한 파일을 /opt 디렉토리 밑에 옮김
$ sudo mv nexus-3.29.2-02 /opt/

설치 후 기본 설정

  • 설치 후 nexus-default.properties 파일을 편집모드로 열어 application-port=8089 부분의 포트를 변경합니다. (보통 8080 으로 설정합니다)

...

코드 블럭
$ sudo groupadd nexus && adduser nexus -g nexus

서비스 등록

  • 서비스 등록에는 많은 방법이 있는데 저는 systemd를 이용하는 방식을 사용하였습니다.
  • 서비스 등록은 https://help.sonatype.com/repomanager3/installation/run-as-a-service 을 참고하시면 자세히 나와있습니다.
  • nexus.service를 편집기로 열어 다음의 내용을 작성합니다. (저는 vagrant 계정이 기본으로 되어있어 vagrant로 설정하였습니다.)

...

  • log는 tail -f /opt/sonatype-work/nexus3/log/nexus.log 명령어로 확인할 수 있습니다.
  • 마지막으로 다음의 화면이 나오면 Nexus 서버 접속에 성공한 것입니다!

브라우저 접속

image

외부 Repositories 등록 후 Windows에서 Nexus Server 미러링

외부 Repositories 등록

  • 다음은 외부 저장소를 등록하는 화면입니다. 저는 spring repository를 등록하였습니다.
  • 저장소는 test라는 Blob store를 따로 생성하고 지정하였습니다. (저장소는 Blob stores 메뉴를 보시면 됩니다.)

settings.xml 파일 생성 및 미러링 

  • 다음은 Windows 환경에서 C:/Users/User/.m2 경로에 settings.xml 파일을 만들고 VMBox의 Nexus Repository 미러링 내용을 작성합니다.

...

코드 블럭
titlesettings.xml
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>maven-spring-public</id>
      <name>maven-spring-public</name>
      <url>http://192.168.33.10:8089[maven repository url]:[maven repository port]/repository/spring-central/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
</settings>

...

  • Maven install이 끝나면 다음과 같은 component 들이 등록되어 있는것을 확인할 수 있습니다.

maven deploy 커맨드로 Spring Boot의 빌드한 JAR 파일을 Nexus에 배포

Repositories에 등록되어

...

있는 maven-snapshots repository를 이용하여 배포할 계획입니다.

정리하자면, maven-public repository에서 pom.xml에 있는 파일들을 미러링→ 해당 jar 파일들을 다운로드 → maven-snapshots repository에 배포한다는 계획입니다.

다음은 settings.xml에 deploy 설정을 추가한 내용입니다.

코드 블럭
languagexml
title<USER_HOME>/.m2/settings.xml
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
			
	<mirrors>
		<mirror>
		  <id>maven-public</id>
		  <name>maven-public</name>
		  <url>http://192.168.33.10:8089[maven repository url]:[maven repository port]/repository/maven-public/</url>
		  <mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>

	<!-- pom.xml의 snapshotRepository id와 Nexus username 및 password를 입력해줍니다. -->
	<servers>
	   <server>
		  <id>nexus-snapshots</id>
		  <username>admin</username>
		  <password>****</password>
	   </server>
	</servers>

</settings>

다음은 pom.xml 파일입니다. Maven Deploy를 위해서 distributionManagement를 추가하였습니다.

코드 블럭
languagexml
title<PROJECT_HOME>/pom.xml
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"... 생략

	<build>
        <plugins>
            ... 생략
            <plugin>xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apachespringframework.maven.plugins<boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <artifactId>maven-deploy-plugin</artifactId>
<version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    <version>${maven-deploy-plugin.version}</version>parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <configuration><name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <skip>true</skip><java.version>1.8</java.version>
                </configuration>
        <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
    </plugin>properties>
    <dependencies>
        <plugin><dependency>
                <groupId>org.sonatypespringframework.plugins<boot</groupId>
                <artifactId>nexus-staging-maven-plugin<<artifactId>spring-boot-starter</artifactId>
        </dependency>

        <version>1.5.1</version><dependency>
                <executions><groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        <execution>
    <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
    <id>default-deploy</id>
    <plugins>
            <plugin>
        <phase>deploy</phase>
        <groupId>org.springframework.boot</groupId>
                <goals><artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
    <goal>deploy</goal>
            <groupId>org.apache.maven.plugins</groupId>
            </goals>
    <artifactId>maven-source-plugin</artifactId>
                </execution><version>3.2.1</version>
                </executions><executions>
                <configuration>    <execution>
                    <serverId>nexus</serverId>
    <id>attach-sources</id>
                <nexusUrl>http://192.168.33.10:8089/repository/maven-snapshots/</nexusUrl>
        <goals>
            <skipStaging>true</skipStaging>
                <<goal>jar</configuration>goal>
            </plugin>
        </plugins>
    </build>
goals>
    <distributionManagement>
        <snapshotRepository>
        </execution>
    <id>nexus-snapshots</id>            </executions>
            <url>http://192.168.33.10:8089/repository/maven-snapshots/</url>plugin>
        </snapshotRepository>
    <plugin>
             </distributionManagement>

... 생략
  • 설정이 완료 되었다면, maven clean deploy -Dmaven.test.skip=true 명령어를 통해 maven을 실행시킵니다. (저는 Windows에 maven설치가 안되어 있어 spring boot 프로젝트의 mvnw 파일을 통해 mvn 명령어로 실행하였습니다.)
   <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 Repository URL]:[Nexus Port]/repository/maven-snapshots/</nexusUrl>
                    <skipStaging>true</skipStaging>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <url>http://[Nexus Repository URL]:[Nexus Port]/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

</project>

설정이 완료 되었다면, maven clean deploy -Dmaven.test.skip=true 명령어를 통해 maven을 실행시킵니다.

코드 블럭
languagetext
titlemaven deploy
linenumberstrue
C:\Users\hyunaoh\git\nexus-maven-demo>mvn clean deploy
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting C:\Users\hyunaoh\git\nexus-maven-demo\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\hyunaoh\git\nexus-maven-demo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\hyunaoh\git\nexus-maven-demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\hyunaoh\git\nexus-maven-demo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
23:05:54.746 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframewo
rk.test.context.cache.DefaultCacheAwareContextLoaderDelegate]

... 생략

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-01-30 23:05:55.262  INFO 5840 --- [           main] com.example.demo.DemoApplicationTests    : Starting DemoApplicationTests using Java 1.8.0_252
on DESKTOP-G85CPR1 with PID 5840 (started by hyunaoh in C:\Users\hyunaoh\git\nexus-maven-demo)
2021-01-30 23:05:55.265  INFO 5840 --- [           main] com.example.demo.DemoApplicationTests    : No active profile set, falling back to default prof
iles: default
2021-01-30 23:05:55.657  INFO 5840 --- [           main] com.example.demo.DemoApplicationTests    : Started DemoApplicationTests in 0.619 seconds (JVM
running for 1.421)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.115 s - in com.example.demo.DemoApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
코드 블럭
titlemaven deploy
linenumberstrue
>mvn clean deploy -Dmaven.test.skip=true -e
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-cleanjar-plugin:3.12.0:cleanjar (default-cleanjar) @ demo ---
[INFO] DeletingBuilding jar: C:\Users\hyunaoh\git\nexus-maven-demo\target-maven-demo\target\demo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.2:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --->>> maven-resourcessource-plugin:3.2.01:resourcesjar (defaultattach-resourcessources) > generate-sources @ demo --->>>
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource<<< maven-source-plugin:3.2.1:jar (attach-sources) < generate-sources @ demo <<<
[INFO]
[INFO]
[INFO] --- maven-compilersource-plugin:3.82.1:compilejar (defaultattach-compilesources) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file toBuilding jar: C:\Users\hyunaoh\git\nexus-maven-demo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---demo-0.0.1-SNAPSHOT-sources.jar
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compilerinstall-plugin:32.85.12:testCompileinstall (default-testCompileinstall) @ demo ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---Installing C:\Users\hyunaoh\git\nexus-maven-demo\target\demo-0.0.1-SNAPSHOT.jar to C:\Users\hyunaoh\.m2\repository\com\example\demo\0.0.1-SNAPSH
OT\demo-0.0.1-SNAPSHOT.jar
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ demo ---Installing C:\Users\hyunaoh\git\nexus-maven-demo\pom.xml to C:\Users\hyunaoh\.m2\repository\com\example\demo\0.0.1-SNAPSHOT\demo-0.0.1-SNAPSHOT.
pom
[INFO] BuildingInstalling jar: C:\Users\hyunaoh\git\nexus-maven-demo\target\demo-0.0.1-SNAPSHOT-sources.jar to C:\Users\hyunaoh\.m2\repository\com\example\demo\0.0.
1-SNAPSHOT\demo-0.0.1-SNAPSHOT-sources.jar
[INFO]
[INFO] --- spring-boot- maven-deploy-plugin:2.48.2:repackagedeploy (repackagedefault-deploy) @ demo ---
[INFO] Replacing mainSkipping artifact with repackaged archivedeployment
[INFO]
[INFO] --- nexus-staging-maven-install-plugin:21.5.21:installdeploy (default-installdeploy) @ demo ---
[INFO] Performing deferred deploys (gathering into "C:\Users\hyunaoh\git\nexus-maven-demo\target\nexus-staging\deferred")...
[INFO] Installing C:\Users\hyunaoh\git\nexus-maven-demo\target\demo-0.0.1-SNAPSHOT.jar to C:\Users\hyunaoh\.m2\repository\hyunaoh\git\nexus-maven-demo\target\nexus-staging\de
ferred\com\example\demo\0.0.1-SNAPSHOT\demo-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\hyunaoh\git\nexus-maven-demo\pom.xml to C:\Users\hyunaoh\.m2\repositorygit\nexus-maven-demo\target\nexus-staging\deferred\com\example\demo
\0.0.1-SNAPSHOT\demo-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ demo --- Installing C:\Users\hyunaoh\git\nexus-maven-demo\target\demo-0.0.1-SNAPSHOT-sources.jar to C:\Users\hyunaoh\git\nexus-maven-demo\target\nexus-st
aging\deferred\com\example\demo\0.0.1-SNAPSHOT\demo-0.0.1-SNAPSHOT-sources.jar
[INFO] Skipping artifact deploymentDeploying remotely...
[INFO] Bulk deploying locally gathered artifacts from directory:
[INFO] --- nexus-staging-maven-plugin:1.5.1:deploy (default-deploy) @ demo ---
[INFO] Performing deferred deploys (gathering into "C:\Users\hyunaoh\git\nexus-maven-demo\target\nexus-staging\deferred")...
[INFO] Installing C:\Users\hyunaoh\git\nexus-maven-demo\target\demo- * Bulk deploying locally gathered snapshot artifacts to URL http://192.168.33.10:8089/repository/maven-snapshots/
Downloading from nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml
Downloaded from nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT.jar to C:\Users\hyunaoh\git\nexus-maven-demo\target\nexus-staging\deferred\com\example\demo\/maven-metadata.xml (979 B at 9.7
kB/s)
Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT\/demo-0.0.1-SNAPSHOT-20210130.140557-3-sources
.jar
[INFO]Uploaded Installing C:\Users\hyunaoh\git\nexus-maven-demo\pom.xml to C:\Users\hyunaoh\git\nexus-maven-demo\target\nexus-staging\deferred\com\example\demo\0.0.1-SNAPSHOT\demo-0.0.1-SNAPSHOT.pom
[INFO] Deploying remotely...
[INFO] Bulk deploying locally gathered artifacts from directory:
[INFO]  * Bulk deploying locally gathered snapshot artifacts to URLto nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210130.140557-3-sources.
jar (2.6 kB at 286 B/s)
Downloading from nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/maven-metadata.xml
Downloaded from nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/maven-metadata.xml (275 B at 9.2 kB/s)
Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/
Downloading fromcom/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml (979 B at 107 B/s)

Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210130.101513-1.jarmaven-metadata.xml
Uploaded to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo/maven-0.0.1-20210130.101513-1.jar (8.5 MBmetadata.xml (275 B at 87230 kBB/s)
Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210130.101513140557-13.pomjar
Uploaded to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210130.101513140557-13.pomjar (28.95
 kBMB at 315 B/s)
Downloading from nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/maven-metadata.xml895 kB/s)
Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xmldemo-0.0.1-20210130.140557-3.pom
Uploaded to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml (765 Bdemo-0.0.1-20210130.140557-3.pom (3.4
 kB at 84369 B/s)
Uploading to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded to nexus-snapshots: http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml (275979 B at 30107 B/s)

[INFO]  * Bulk deploy of locally gathered snapshot artifacts finished.
[INFO] Remote deploy finished with success.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  41.025 s01:01 min
[INFO] Finished at: 2021-01-30T1930T23:1506:5052+09:00
[INFO] ------------------------------------------------------------------------

다음은 배포 완료 후 Nexus Repository 화면입니다.

...

source 및 jar 파일이

...

생성되어 있는 것을 확인 할 수 있습니다.

Image RemovedImage Added

http://192.168.33.10:8089/repository/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20210130.103414-1.pom 를 확인하면 다음과 같습니다. (아래는 생략)

maven deploy nexus 설정에 대해 자세히 알고 싶다면, https://www.baeldung.com/maven-deploy-nexus을 참고하셔도 됩니다.