Created
April 6, 2025 14:08
-
-
Save senseilearning/6132d71dafe2a5fcf69ab676b2584aac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GitHub Packages に Kotlin Multiplatform ライブラリを組織内限定で公開する方法(ステップバイステップ) | |
1. GitHub リポジトリを用意 | |
- Organization 内にリポジトリを作成 | |
- リポジトリは「Private」に設定(パッケージも限定公開になる) | |
2. build.gradle.kts に以下を追加 | |
publishing { | |
repositories { | |
maven { | |
name = "GitHubPackages" | |
url = uri("https://maven.pkg.github.com/your-org/kmp-library") | |
credentials { | |
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") | |
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") | |
} | |
} | |
} | |
publications { | |
create<MavenPublication>("gpr") { | |
from(components["kotlin"]) | |
groupId = "com.example.kmplib" | |
artifactId = "hello-lib" | |
version = "0.1.0" | |
} | |
} | |
} | |
3. GitHub Personal Access Token を取得 | |
- https://github.com/settings/tokens にアクセス | |
- スコープに write:packages, read:packages を含める | |
4. 認証情報を gradle.properties に追加 | |
~/.gradle/gradle.properties | |
gpr.user=GITHUB_USERNAME | |
gpr.key=YOUR_PERSONAL_ACCESS_TOKEN | |
または環境変数を設定 | |
export GITHUB_ACTOR=your-username | |
export GITHUB_TOKEN=your-token | |
5. ライブラリを公開 | |
./gradlew publish | |
6. 使用側の設定(同じ組織の他のプロジェクト) | |
repositories { | |
maven { | |
url = uri("https://maven.pkg.github.com/your-org/kmp-library") | |
credentials { | |
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") | |
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") | |
} | |
} | |
mavenCentral() | |
} | |
dependencies { | |
implementation("com.example.kmplib:hello-lib:0.1.0") | |
} | |
7. 限定公開の仕組み | |
- リポジトリが Private なら組織内のメンバーだけがアクセス可能 | |
- 認証が必要なため、外部の人は利用できない | |
まとめ | |
- GitHub Packages はプライベートMavenとして使える | |
- 認証に Personal Access Token を使えばセキュアに運用できる | |
- 組織内で限定的にライブラリを配布したい場合に最適 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment