본문 바로가기

Study/CI&CD

Maven Central Portal 배포하기 (기존 OSSRH 배포 방식 변경)

반응형

OSSRH 배포 방식이 바뀌었다고 migration 권고 메일이 왔다.

OSSRH (Open Source SW Repository Hosting) 배포에 대해서는 기존 글을 참고하면 된다.

2021.07.20 - [Study/Java] - maven central repository에 라이브러리 배포하기

Maven Central Portal 배포로 변경되면서  2025년 6월 30일에 OSSRH 서비스가 종료되기 때문에 그전에 migration을 진행해야 한다고 한다.

OSSRH Migrate 하기

관련 내용은 이곳에서 확인할 수 있다.

https://central.sonatype.org/faq/what-is-different-between-central-portal-and-legacy-ossrh/#self-service-migration

 

What is different between Central Portal and Legacy OSSRH?

What is different between Central Portal and Legacy OSSRH? I am considering migrating from Legacy OSSRH to Central Portal, and I would like to know the differences between them. Publishing Publishing to Maven Central via the Central Portal and via Legacy O

central.sonatype.org

OSSRH 계정은 더 이상 사용되지 않고 OSSRH 계정 프로필은 central portal에서 사용하는 것과 동일하게 통합되었다고 한다.

https://central.sonatype.org/faq/ossrh-account-management/

 

OSSRH Account Password Update

OSSRH Account Password Update Question How can I update my OSSRH password ? Answer Our previous OSSRH Account Management Portal has been decomissioned. The OSSRH account profiles were merged with the same authentication provider used by Central Portal. To

central.sonatype.org

배포 방식이 바뀌었으니 일단 maven central에 로그인하고 namespace를 확인해 보았다.

https://central.sonatype.com/publishing/namespaces

 

Maven Central: Publishing

Maven Central: Publishing

central.sonatype.com

Migrate Namespace 버튼이 있고 해당 버튼을 눌러보면

migrate 가능한지 체크 후 별 문제없을 시 central portal로 migrate 진행 가능하다고 안내가 뜬다.

동의하고 migrate를 선택하면 해당 작업이 얼마간 진행된 후 다음과 같이 화면이 변경된다.

처음 Maven Central Portal을 사용하는 사람은 해당 사이트에서 계정을 생성한 후 namespace를  만들고 승인 절차를 거치면 된다.

관련 방법은 아래 링크에 안내되어 있다.

https://central.sonatype.org/register/namespace/

 

Register a Namespace

Register a Namespace Choosing a Namespace If you are new to the Central Portal you will have no verified namespaces and will see a prompt to view instructions for verifying namespaces: Important If you do not see this pop-up AND you signed up with GitHub,

central.sonatype.org

 

Maven Plugin을 사용하여 Central Portal로 배포하기

https://central.sonatype.org/publish/publish-portal-maven/

 

Maven

Publishing By Using the Maven Plugin Central Publisher Portal supports publishing via Maven. In order to do this, you need to configure your project to use the central-publishing-maven-plugin. Note The plugin does not generate all of the prerequisites for

central.sonatype.org

이제 대상 프로젝트에서 기존 OSSRH 사용 방식의 배포에서 Central Portal을 사용한 방식의 배포로 변경해야 한다.

내 경우 Maven을 통해 배포를 하였었다.

배포를 위한 Portal Token 생성하기

https://central.sonatype.org/publish/generate-portal-token/

 

Generating a Portal Token for Publishing

Generating a Portal Token for Publishing OSSRH Publishers This documentation is for publishing via the Central Publisher Portal. For publishing via OSSRH, please see the OSSRH token documentation. You must use a user token to publish artifacts to the Centr

central.sonatype.org

계정 페이지에서 User Token을 생성한다.

https://central.sonatype.com/account

 

Maven Central: My Account

Maven Central: My Account

central.sonatype.com

 

Maven Repository settings.xml 설정하기

생성된 User Token을 maven repository의 settings.xml에 추가한다.

<settings>
	<servers>
		<server>
			<id>central</id>
			<username>******</username>
			<password>******************</password>
		</server>
	</servers>
</settings>

 

프로젝트에 central-publishing-maven-plugin 설정 추가하기

기존 배포 설정 중 maven-source-plugin, maven-javadoc-plugin, maven-gpg-plugin은 그대로 유지된다

OSSRH 관련 설정인 nexus-staging-maven-plugin을 지우고 central-publishing-maven-plugin을 다음과 같이 추가해 준다.

<build>
	<plugins>
		<plugin>
			<groupId>org.sonatype.central</groupId>
			<artifactId>central-publishing-maven-plugin</artifactId>
			<version>0.7.0</version>
			<extensions>true</extensions>
			<configuration>
				<publishingServerId>central</publishingServerId>
				<autoPublish>true</autoPublish>
			</configuration>
		</plugin>
	<plugins>
</build>

혹시 기존 OSSRH 방식의 설정이 궁금하다면 이 문서를 참고하면 된다.

https://central.sonatype.org/publish/publish-maven/

 

Apache Maven

Maven Deploying to OSSRH with Apache Maven Apache Maven started the Central Repository by publishing all its components and required dependencies into the Central Repository - back then known as Maven Central. Maven is pre-configured to connect to and down

central.sonatype.org

 

PGP 인증서 생성 및 등록하기

기존 OSSRH 배포와 동일하게 PGP를 사용한다.

window 사용자라면 Gpg4Win을 설치하면 된다.

https://gnupg.org/download/index.html

 

GnuPG - Download

Note that you may also download the GNU Privacy Guard from a mirror site close to you. See our list of mirrors. The table below provides links to the location of the files on the primary server only. These are the canonical release forms of GnuPG. To use t

gnupg.org

설치 후 Kleopatra를 실행하여 새 OpenPGP 키 쌍을 생성한다.

생성된 인증서에 오른쪽 마우스 -> 자세히를 선택하여 인증서 정보에서 지문 옆의 복사버튼으로 키를 복사한 후

command 창에서 아래처럼 인증서를 keyserver.ubuntu.com에 업로드한다.

gpg --keyserver keyserver.ubuntu.com --send-keys {복사된키}

 

maven repository의 settings.xml에 pgp 설정하기

앞서 maven repository settings.xml에 maven central 배포를 위한 user Token을 설정하였었다.

해당 파일에 pgp관련 설정을 다음과 같이 추가한다.

<profiles>
    <profile>
        <id>central</id>
        <activation>
        <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
        <gpg.keyname>{pgpKey}</gpg.keyname>
        <gpg.executable>C:\Program Files (x86)\GnuPG\bin\gpg.exe</gpg.executable>
    </profile>
</profiles>

프로젝트에 maven-gpg-plugin 설정하기

프로젝트에 gpg plugin을 다음과 같이 설정한다.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>${maven-gpg-plugin.version}</version>
    <executions>
        <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
</plugin>

 

프로젝트 pom.xml plugin 설정 

snapshot 배포는 간단하게 가능하지만 release 배포를 위해서는 central-publishing-maven-plugin, maven-gpg-plugin 뿐만 아니라 maven-source-plugin, maven-javadoc-plugin도 설정해주어야 한다.

앞서 설명한 plugin과 합하면 다음과 같다.

<profiles>
    <profile>
        <id>central</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <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>${maven-gpg-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.central</groupId>
                    <artifactId>central-publishing-maven-plugin</artifactId>
                    <version>${central-publishing-maven-plugin.version}</version>
                    <extensions>true</extensions>
                    <configuration>
                        <publishingServerId>central</publishingServerId>
                        <autoPublish>true</autoPublish>
                        <waitUntil>published</waitUntil>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

 

위 내용 이외에 배포 관련 프로젝트에 관한 설정 정보들(description, url, inceptionYear, license, scm, developers)은 아래 페이지에서 확인할 수 있다.

https://central.sonatype.org/publish/requirements/#required-pom-metadata

 

Requirements

Why do we have Requirements In order to ensure a minimum level of quality of the components available in the Central Repository, we have established a number of requirements your deployment components have to meet. This allows your users to find all the re

central.sonatype.org

 

SNAPSHOT 배포

앞에서 전체 설정을 소개하였지만 snapshot 배포 시엔 굳이 필요하진 않다.
하지만 그렇다고 snapshot, release 설정을 분리해서 관리할게 아니니 일관되게 설정하고 배포하는 게 속편 하다.

https://central.sonatype.org/publish/publish-portal-snapshots/

 

Publish Portal Snapshots

Publishing -SNAPSHOT Releases -SNAPSHOT releases are intended for developers to make pre-release versions of their projects available for testing. While the versions of components retrieved from Maven Central are guaranteed to not change, -SNAPSHOT version

central.sonatype.org

일정 기간 (90일) 이후 SNAPSHOT은 정리된다고 한다.

SNAPSHOT의 경우 유효성 검사는 수행되지 않는다.

SNAPSHOT 배포를 허용하려면 namespace에서 snapshot 배포를 허용한다.

그러면 다음과 같이 적용된 것을 확인할 수 있다.

repository에 다음과 같이 snapshot 배포 repository를 지정해 준다.

<repository>
    <name>Central Portal Snapshots</name>
    <id>central-portal-snapshots</id>
    <url>https://central.sonatype.com/repository/maven-snapshots/</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

 

RELEASE 배포

앞서 소개한 바와 같이 설정을 한 후 RELEASE 배포를 하면 배포가 다 된 듯 하지만 프로젝트에서 계속 대기 상태가 된다.

Maven Central의 Deployments에서 해당 배포에 대해 다음과 같이 표시가 된다.

https://central.sonatype.com/publishing/deployments

20여분 정도 기다리면 배포 완료 상태가 된다.

maven central repository에서 검색해 보면 배포된 라이브러리가 잘 검색되는 것을 확인할 수 있다.

예전엔 배포완료 후 검색 index가 갱신되는 것을 며칠씩 기다려야 했는데 20여분 내로 기간이 단축되어서 많이 좋아진 것 같다.

반응형