티스토리 뷰

728x90
반응형

이번 포스팅에서는 지난 포스팅에서 구축한 Maven Dependency 리포지토리인 Nexus2 내부 저장소와의 연동 과정에 대해 알아보겠습니다.

지난 포스팅은 다음을 참고하시기 바랍니다.

 

[Spring Boot] git clone을 활용한 Spring Boot 프로젝트 repository 이관

[Spring Boot] gitlab & Eclipse 연동을 통한 Spring Boot 개발 프로젝트 구축

[Spring Boot] Spring Boot Maven 리포지토리 (Nexus2 OSS 내부 저장소) 구축

 

Nexus2 - Spring Boot 연동

1) Nexus2 3rd party URL 확인

먼저 구축이 완료된 Nexus2 Repository에 접속합니다.

접속 후 왼쪽 메뉴 바 → Repositories → 3rd party의 Repository Path를 확인합니다.

해당 URL을 클릭하면,

위와 같이 실제 Repository 목록을 확인할 수 있습니다.

실제 Maven Repository로 등록하기 위한 pom.xml 정보는 다음화면에서 확인할 수 있습니다.

이를 기반으로 Spring Boot Project에서 연동을 진행해 보겠습니다.

2) Spring Boot pom.xml, setting.xml 수정

Spring Boot 프로젝트에서 Dependency 관리를 위한 툴로는 대표적으로 Maven과 Gradle이 있습니다.

이미 해당 툴을 다루는 방법에 대해 기술한 적이 있으나, 이후 Spring Boot 포스팅의 연장으로 다시한번 다룰 예정입니다.

Spring Boot의 Maven Repository를 변경하기 위해서는 settings.xml과 pom.xml을 수정해야 합니다.

 

a) 수정 전 repository 초기화

변경에 앞서 정확한 테스트를 위해 포스팅에서 확인한 C:\Users\user\.m2\repository 경로의 Library를 모두 삭제하고 진행하겠습니다.

maven repository default 경로(C:\Users\user\.m2) 또는 Maven 사용자 지정 위치이며, repository 하위의 모든 라이브러리를 삭제합니다.

b) settings.xml 수정

먼저 settings.xml는 maven repository default 경로(C:\Users\user\.m2) 또는 Maven 사용자 지정 위치에 있습니다. 없을 경우에 생성하여 사용하면 됩니다.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

  <servers>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>central</id>
      <name>central</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

</settings>

위와 같이 기본 repository 경로는 https://repo.maven.apache.org/maven2로 지정되어 있으며, 이를 아래와 같이 local repository로 변경합니다.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

  <servers>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>central</id>
      <name>central</name>
      <url>http://222.234.124.6:8081/nexus/content/repositories/thirdparty/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

</settings>

위와 같이 내부 저장소의 위치로 경로를 지정하고 이클립스를 재기동합니다.

 

c) pom.xml 수정

pom.xml은 maven project의 핵심 요소입니다. 특히 Spring Boot에서 사용하고 싶은 라이브러리를 지정하고 등록하여 관리할 수 있으며, mvnw의 자동 버전 관리까지 가능하며, 가장 큰 장점은 쉽다는 것입니다.

	<repositories>
		<repository>
			<id>public</id>
			<url>https://repo.maven.apache.org/maven2</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

현재 Maven Repository는 https://repo.maven.apache.org/maven2을 사용중이며, 이를 내부 Repository로 변경해 보도록 하겠습니다.

	<repositories>
		<repository>
			<id>public</id>
			<url>http://222.234.124.6:8081/nexus/content/repositories/thirdparty/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

3) Maven clean & Maven Install

다음으로 Maven Dependency를 초기화 하고 재생성해 보도록 하겠습니다.

 

a) Maven Clean

pom.xml 우클릭 → Run As → Maven Clean

Clean이 성공하면 다음으로 Maven Install을 진행합니다.

 

b) Maven Install

pom.xml 우클릭 → Run As → Maven Install

[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< nrson.spring:template >------------------------
[INFO] Building Template 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.pom (6.4 kB at 113 kB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-plugins/25/maven-plugins-25.pom (9.6 kB at 955 kB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/maven-parent/24/maven-parent-24.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/maven-parent/24/maven-parent-24.pom (37 kB at 2.5 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/apache/14/apache-14.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/apache/14/apache-14.pom (15 kB at 2.1 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/plugins/maven-install-plugin/2.5.2/maven-install-plugin-2.5.2.jar (33 kB at 2.5 MB/s)
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ template ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ template ---
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/shared/maven-shared-incremental/1.1/maven-shared-incremental-1.1.pom
...
...
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar (21 kB at 1.9 MB/s)
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\user\git\hellogitrepo\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ template ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\user\git\hellogitrepo\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ template ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ template ---
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/surefire/maven-surefire-common/2.22.1/maven-surefire-common-2.22.1.pom
...
...
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/com/thoughtworks/qdox/qdox/2.0-M8/qdox-2.0-M8.jar (316 kB at 6.5 MB/s)
[INFO] 
[INFO] --- maven-war-plugin:3.2.2:war (default-war) @ template ---
[INFO] Packaging webapp
[INFO] Assembling webapp [template] in [C:\Users\user\git\hellogitrepo\target\template]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\user\git\hellogitrepo\src\main\webapp]
[INFO] Webapp assembled in [149 msecs]
[INFO] Building war: C:\Users\user\git\hellogitrepo\target\template.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.1.4.RELEASE:repackage (repackage) @ template ---
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/springframework/boot/spring-boot-loader-tools/2.1.4.RELEASE/spring-boot-loader-tools-2.1.4.RELEASE.pom
...
...
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/com/google/guava/guava/19.0/guava-19.0.jar (2.3 MB at 10 MB/s)
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ template ---
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/junit/junit/3.8.1/junit-3.8.1.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/junit/junit/3.8.1/junit-3.8.1.pom (998 B at 100 kB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/commons-codec/commons-codec/1.6/commons-codec-1.6.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/commons-codec/commons-codec/1.6/commons-codec-1.6.pom (11 kB at 1.4 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-parent/22/commons-parent-22.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/commons/commons-parent/22/commons-parent-22.pom (42 kB at 3.5 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.pom (4.0 kB at 506 kB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.pom
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.pom (3.1 kB at 449 kB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/junit/junit/3.8.1/junit-3.8.1.jar (121 kB at 4.8 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar (38 kB at 3.1 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/commons-codec/commons-codec/1.6/commons-codec-1.6.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/commons-codec/commons-codec/1.6/commons-codec-1.6.jar (233 kB at 7.3 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar (155 kB at 6.0 MB/s)
[INFO] Downloading from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.jar
[INFO] Downloaded from : http://222.234.124.6:8081/nexus/content/repositories/thirdparty/org/codehaus/plexus/plexus-utils/3.0.15/plexus-utils-3.0.15.jar (239 kB at 7.2 MB/s)
[INFO] Installing C:\Users\user\git\hellogitrepo\target\template.war to C:\Users\user\.m2\repository\nrson\spring\template\0.0.1-SNAPSHOT\template-0.0.1-SNAPSHOT.war
[INFO] Installing C:\Users\user\git\hellogitrepo\pom.xml to C:\Users\user\.m2\repository\nrson\spring\template\0.0.1-SNAPSHOT\template-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.870 s
[INFO] Finished at: 2019-07-28T23:49:48+09:00
[INFO] ------------------------------------------------------------------------

위와 같이 Console에서 표시되는 경로가 내부 로컬 레지스트리를 참고하여 라이브러리를 다운로드 받고 있는 것을 확인할 수 있습니다.

빌드에 성공하면 스프링 프로젝트를 수행할 수 있는 준비가 완료되었다고 볼 수 있습니다.

그럼 현재 버전의 pom.xml을 내부 gitlab에 commit & push 하도록 하겠습니다.

 

다음 포스팅에서는 Spring Boot의 구조에 대해 살펴보고 기본 샘플을 작성해 보는 시간을 갖도록 하겠습니다.

728x90
반응형