ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Maven Central Repository에 배포하기
    카테고리 없음 2024. 9. 15. 13:38

     

    Java SDK를 만들고 Maven Central Repository에 배포하는 과정을 정리

     

     

    대부분의 블로그 포스팅이 Gradle을 이용한 배포방식이라

    Apache Maven을 이용한 배포과정에 대해서 적어봤다.

     

     

    'Maven Central Repository 배포 과정

    1. Namespace Verified

    2. GPG Key Generate

    3. pom.xml 수정

     

     

    Namespace Verified

    Namespace를 만들 수 있는데 Namespace는 Java의 패키지 규칙대로 도메인의 역순으로 기입한다.

     

    생성한 Namespace에 대한 유효성 검사를 진행하는데

    유효성검사는 실제로 도메인을 가지고 있는지 여부를 체크하기 위함이라고 한다.

     

    대부분의 경우 io.github.{UserName} 으로 생성하고 Github 계정으로 Maven Central에 로그인 했다면 자동으로 Verified가 된다고 한다.

     

    나의 경우 Organization으로 Namespace를 만들어서 자동 인증은 되지않고 수동으로 인증을 해야했다.

    따라서 io.github.{OrganizationName} 으로 Namespace를 만들고

    내 Organization Repository에 Verify Code와 동일한 Repository를 생성했다. 

     

    지금은 삭제했지만 별다른 작업없이 Repository를 생성하고 인증하면 인증은 끝난다.

     

    Namespace Verified

     

    GPG Key Generate

    GPG Key 생성은 별다른 어려움 없이 해당 내용을 따라하면 된다.

    GPG로 Sign하는 이유는 라이브러리에 대한 무결성을 보장하기 위함이라고 한다.

     

     

    Working with PGP Signatures

    GPG One of the requirements for publishing your artifacts to the Central Repository, is that they have been signed with PGP. GnuPG or GPG is a freely available implementation of the OpenPGP standard. GPG provides you with the capability to generate a signa

    central.sonatype.org

     

    pom.xml 수정

    1. Javadoc 제공
    2. GPG 파일 서명
    3. Metadata 추가
      1. 프로젝트 정보
      2. 라이센스 정보
      3. 개발자 정보
      4. SCM 정보 : 라이브러리의 Git Repository에 대한 정보

     

    전체 pom.xml 

    <?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"
             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>
        	...
        </parent>
        
        <-- GAV -->  
        <groupId>io.github.tracedin</groupId>
        <artifactId>tracedin-sdk</artifactId>
        <version>0.0.2</version>
    
        <-- 프로젝트 정보 -->
        <name>tracedin-sdk</name>
        <description>Tracedin Application SDK for Java</description>
        <url>https://tracedin.github.io</url>
    	
        <-- 라이센스 정보 -->
        <licenses>
            <license>
                <name>MIT License</name>
                <url>https://opensource.org/license/MIT</url>
            </license>
        </licenses>
        
        <-- 개발자 정보 -->
        <developers>
            <developer>
                <name>Sukkyun Hong</name>
                <email>goobghd@gmail.com</email>
                <organization>Chungbuk National Univ</organization>
                <organizationUrl>https://github.com/sukkyun2</organizationUrl>
            </developer>
        </developers>
    
        <-- SCM 정보 -->
        <scm>
            <connection>scm:git:github.com/tracedin/tracein-sdk-java.git</connection>
            <developerConnection>scm:git:ssh://github.com/tracedin/tracein-sdk-java</developerConnection>
            <url>https://github.com/tracedin/tracein-sdk-java/tree/main</url>
        </scm>
        
        <properties>
            <java.version>17</java.version>
            <spring-cloud.version>2023.0.3</spring-cloud.version>
            <opentelemetry.version>1.40.0</opentelemetry.version>
            <gpg.keyname>secret</gpg.keyname>
        </properties>
    
        <dependencies>
        	...
        </dependencies>
    
        <build>
            <finalName>${project.artifactId}-${project.version}</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.9.1</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>1.5</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                            <configuration>
                                <keyname>${gpg.keyname}</keyname>
                                <passphrase>${gpg.keyname}</passphrase>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.central</groupId>
                    <artifactId>central-publishing-maven-plugin</artifactId>
                    <version>0.5.0</version>
                    <extensions>true</extensions>
                    <configuration>
                        <publishingServerId>central</publishingServerId>
                        <autoPublish>true</autoPublish>
                        <waitUntil>publishing</waitUntil>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

     

     

Designed by Tistory.