Nexus Repository Manager 구축하기 ( for maven )

2013. 9. 23. 16:31Java

http://ncanis.tistory.com

Nexus Repository Manager 구축하기 ( for maven )


1. http://www.sonatype.org/ 에서 최신 버전 설치



2. 다운로드 받은 것을 풀고 설치한다.

D:\Tool\nexus-2.6.2-01\bin\jsw\windows-x86-64 (64비트 os 인경우) 에서

install-nexus.bat 실행 (windows service에 등록되어 구동된다.)

3. nexus manager web에 접속


4. Repository 설정

   -  이용가능한 Repositories에 Cetral를 제외하고 모두 등록하고 저장한다.



   - Download Remote Indexes를 True로 설정한다. (기본은 리모트에 접속해서 받아오는걸로 되어있다. 이렇게 하면 느리므로, 다운로드 받아올수 있게 설정한다.)



     이 동기화 부분은 좀 느린데, 작성 진행 상황은 아래 위치에서 확인할 수 있다.

    Administration/Scheduled Tasks



     완료가 되면 Repositories/Central 의 Browse Index 를 누르면 제대로 등록된것을 확인할 수 있다.



5. 이제 Eclispe m2e로 이렇게 셋팅된 Repository를 이용해 라이브러리를 추가해 보자

- 중앙 Repository와 써드파티 저장소 2개를 추가했다.
- 작업중인 프로젝트 배포는 Releases 와 Snapshots 주소르 업로드 하도록 설정한다.

<pom.xml>

<repositories>

    <repository> 

        <id>central</id>

        <url>http://127.0.0.1:8081/nexus/content/groups/public</url>

        <releases><enabled>true</enabled></releases>

        <snapshots><enabled>true</enabled></snapshots>

    </repository>

<repository> 

        <id>thirdparty</id>

        <url>http://127.0.0.1:8081/nexus/content/repositories/thirdparty</url>

        <releases><enabled>true</enabled></releases>

        <snapshots><enabled>true</enabled></snapshots>

    </repository>    

</repositories>

  

<pluginRepositories>

    <pluginRepository>

        <id>central</id>

        <url>http://127.0.0.1:8081/nexus/content/groups/public</url>

        <releases><enabled>true</enabled></releases>

        <snapshots><enabled>true</enabled></snapshots>

    </pluginRepository>

</pluginRepositories>

<distributionManagement>  

    <!-- use the following if you're not using a snapshot version. -->  

    <repository>  

      <id>Releases</id>  

      <url>http://localhost:8081/nexus/content/repositories/releases/</url>  

    </repository>  

    <!-- use the following if you ARE using a snapshot version. -->  

    <snapshotRepository>  

      <id>Snapshots</id>  

      <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>  

    </snapshotRepository>  

  </distributionManagement>

- releases, snapshots는 작업중인 프로젝트의 빌드버전을 deploy 해서 nexus에 업로드는 하는것이기 때문에 권한 설정이 필요하다.

  nexus/Security/Users로 가서 이렇게 사용할 계정을 발급하도록 한다. (여기서는 ncanis/ncanis로 발급하였다.)

  권한은 모든 repository에 접속 가능하도록 셋팅했다.(테스트용이므로)


Save 한다.


-위에서 설정한 계정정보를 maven 에도 알려주어야 한다. settings.xml 이 그것이다.

maven repository에 있는 settings.xml에 아래 server tag 부분을 집어 넣는다.

보통 디폴트로 settings.xml 은 C:\Users\ncanis\.m2 폴더 안에 존재하나 없으면 생성해도 된다.

<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">


<servers>

    <server>

      <id>Releases</id>

      <username>ncanis</username>

      <password>ncanis</password>

    </server>

    <server>

      <id>Snapshots</id>

      <username>ncanis</username>

      <password>ncanis</password>

    </server>    

  </servers>


</settings>

- Eclipse m2e로 라이브러리를 추가해 본다. commons로 검색해보았는데, 등록되어있는아이디 들이 제대로 나오는것을 확인할 수 있다. 이제 원하는 걸 찾아 OK를 누르면 라이브러리를 사용할 수 있다.

  


6. Maven Build 해서 Snapshots/Release nexus 저장소에 배포해보자

   Eclipse 에서  Run as/Maven Build를 수행한다.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

[INFO] Scanning for projects...

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building ted_core 1.0-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO] 

[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ ted_core ---

[debug] execute contextualize

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] Copying 2 resources

[INFO] 

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ ted_core ---

[INFO] Compiling 1 source file to D:\Workspace\dayagam\ted\ted_core\target\classes

[INFO] 

[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ ted_core ---

[debug] execute contextualize

[INFO] Using 'UTF-8' encoding to copy filtered resources.

[INFO] skip non existing resourceDirectory D:\Workspace\dayagam\ted\ted_core\src\test\resources

[INFO] 

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ ted_core ---

[INFO] Not compiling test sources

[INFO] 

[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ ted_core ---

[INFO] Tests are skipped.

[INFO] 

[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ ted_core ---

[INFO] Building jar: D:\Workspace\dayagam\ted\ted_core\target\ted_core-1.0-SNAPSHOT.jar

[INFO] 

[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ ted_core ---

[INFO] Installing D:\Workspace\dayagam\ted\ted_core\target\ted_core-1.0-SNAPSHOT.jar to C:\Users\ncanis\.m2\repository\com\tednet\ted\ted_core\

1.0-SNAPSHOT\ted_core-1.0-SNAPSHOT.jar

[INFO] Installing D:\Workspace\dayagam\ted\ted_core\pom.xml to C:\Users\ncanis\.m2\repository\com\tednet\ted\ted_core\1.0-SNAPSHOT\ted_core-1.0

-SNAPSHOT.pom

[INFO] 

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ ted_core ---

Downloading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/maven-metadata.xml

Downloaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/maven-metadata.xml (774 B at 4.1 KB/sec)

Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/ted_core-1.0-20130923.070422-2.jar

Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/ted_core-1.0-20130923.070422-2.pom

Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/ted_core-1.0-20130923.070422-2.pom (3 KB at

 33.1 KB/sec)

Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/ted_core-1.0-20130923.070422-2.jar (175 KB 

at 1616.2 KB/sec)

Downloading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/maven-metadata.xml

Downloaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/maven-metadata.xml (288 B at 15.6 KB/sec)

Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/maven-metadata.xml

Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/maven-metadata.xml

Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/1.0-SNAPSHOT/maven-metadata.xml (774 B at 16.1 KB/sec)

Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/com/tednet/ted/ted_core/maven-metadata.xml (288 B at 4.9 KB/sec)

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 5.377s

[INFO] Finished at: Mon Sep 23 16:04:22 KST 2013

[INFO] Final Memory: 19M/181M

[INFO] ------------------------------------------------------------------------



Snapshots URL로 현재 프로젝트가 빌드외서 Deploy된것을 확인할수 있다.


- Nexus에 접속해서 Repositories/Snapshots 선택, Browse Index로 들어가보면 업로드된 파일을 볼수 있다.


7. (기타) Maven repository에 존재하지 않은 Thrid party 라이브러리는 어떻게 등록하는가.

- 이것도 방법이 있다. 물론 Maven 자체에서 로컬로 걸어버리는 수도 있지만, Nexus를 이용하는게 훨씬 간편하고 좋다.

- Nexus/3rd party 리파지토리를 선택한후 Artifact Upload를 선택한다.

- Select Artifact for Upload를 선택한후 다운로드 받은 jar파일을 업로드 한다.

- Upload Artifact 를 실행한다.


여기서는 cpsuite junit extension를 올려보았는데(중앙 저장소에는 원래 없다.) 파일 업로드후 패키지를 분석해서 알아서 groupid, artifact를 생성해서 만들어놓는 것을 Browse Index에서 확인할 수 있다.


NHN,DAUM이 이런 중앙 저장소를 생성해서 사용한다. 다른곳에 문서들이 제대로 작업되어 있는곳이 없어 만들어 보았다.


8. (기타) Maven 빌드시 Workspace에 있는 프로젝트를 참조하지 못하는경우

   Eclipse  -> Run As -> Run Configurations... 에서 Profiles 설정의 Resolve Workspace artifacts에 체크하여 빌드한다.