LoginSignup
0
0

More than 1 year has passed since last update.

ScalaのライブラリをMavenリポジトリで公開する

Posted at

Scalaのライブラリを公開する

開発が止まったライブラリ(プラグイン)をforkして、新しいバージョンでも利用できるようにしてから
Mavenリポジトリに公開するまでやってみた。

環境

Windows10
Gpg4win 4.0.0

手順

公開プロジェクトの作成

まずは公開するプロジェクトをオープンなリポジトリで公開しておく。

Githubで公開したこのプロジェクト

JIRAアカウントの作成

ここから名前とメールアドレスを登録しアカウントを作成する。

チケットを登録する

Githubで公開している場合以下のイメージで入力する。

項目 入力例
Group Id io.github.【Githubアカウント】
Project URL https://github.com/【Githubアカウント】/【公開プロジェクト】
SCM url必須 https://github.com/【Githubアカウント】/【公開プロジェクト】.git

自動で対応してくれており、問題なければすぐに準備してもらえる。

鍵の登録

gpg --gen-key
gpg --list-keys
gpg --keyserver keyserver.ubuntu.com --send-keys <list keys で表示された公開鍵>

組織内のネットワークだとPortが絞られていて送信できない場合がある。
keyserver.ubuntu.com:80で送ると送信できた。

プロジェクトにsbt-pgpを追加する

plugin.sbt
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")

sonatypeの資格情報を作成する

まずは、ファイルを作成する

$HOME/.sbt/1.0/sonatype.sbt

以下を書き込む

sonatype.sbt
credentials += Credentials($HOME / ".sbt" / "sonatype_credentials")

資格情報のファイルを作成する

~/.sbt/sonatype_credentials

以下を書き込む

sonatype_credentials
realm=Sonatype Nexus Repository Manager
host=s01.oss.sonatype.org
user=【JIRAのアカウント】
password=【JIRAのパスワード】

プロジェクトのbuild.sbtに追加する

build.sbt
version := "0.0.1-snapshot"

ThisBuild / organization := "io.github.【Githubアカウント】"
ThisBuild / organizationName := "【Githubアカウント】"
ThisBuild / organizationHomepage := Some(url("【ホームページのURL】"))

ThisBuild / scmInfo := Some(
  ScmInfo(
    url("https://github.com/【Githubアカウント】/【公開プロジェクト】"),
    "scm:git@github.【Githubアカウント】/【公開プロジェクト】.git"
  )
)

ThisBuild / developers := List(
  Developer(
    id    = "【Githubアカウント】",
    name  = "【名前】",
    email = "【メールアドレス】",
    url   = url("【ホームページのURL】")
  )
)

ThisBuild / description := "プロジェクトの説明"
ThisBuild / licenses := List("Apache 2" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt"))
ThisBuild / homepage := Some(url("https://github.com/【Githubアカウント】/【公開プロジェクト】"))

// Remove all additional repository other than Maven Central from POM
ThisBuild / pomIncludeRepository := { _ => false }

ThisBuild / publishTo := {
  val nexus = "https://s01.oss.sonatype.org/"
  if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
  else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

ThisBuild / publishMavenStyle := true

コマンド実行

sbt publishSigned

途中でPINの入力を求められるので、入力する。

JIRAアカウントを使って以下からログイン
https://s01.oss.sonatype.org/

1.png

snapshotsのリポジトリ内にアップロードされていることを確認する。

リリースする

build.sbt
version := "0.0.1"

snapshotを外して再度コマンドを実行する。

Stagingのリポジトリにアップロードされるので、Closeボタンを押してリポジトリを閉じた後に

Releaseボタンを押して公開する。

公開された

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0