Created
April 7, 2025 23:36
-
-
Save senseilearning/995b36d4175110350b66510ec4bd0631 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
もちろん、以下が **Kotlin Multiplatform (KMP) プロジェクトで `git submodule` を使って別の KMP プロジェクトを参照する方法** の Markdown 形式のまとめです。 | |
--- | |
# Kotlin Multiplatform プロジェクトで git submodule を使って他の KMP プロジェクトを参照する方法 | |
## 前提 | |
- **メインプロジェクト**: `MainKMPProject` | |
- **サブプロジェクト(参照元)**: `SubKMPProject`(Git リポジトリ管理されている) | |
--- | |
## 手順 | |
### 1. サブモジュールを追加 | |
```bash | |
git submodule add https://github.com/your-org/SubKMPProject.git submodules/SubKMPProject | |
git submodule update --init --recursive | |
``` | |
> `submodules/SubKMPProject` にコードが配置されます。 | |
--- | |
### 2. `settings.gradle.kts` にプロジェクトを追加 | |
```kotlin | |
include(":SubKMPProject") | |
project(":SubKMPProject").projectDir = file("submodules/SubKMPProject") | |
``` | |
> サブプロジェクトがマルチモジュールの場合: | |
```kotlin | |
include(":SubKMPProject:shared") | |
project(":SubKMPProject:shared").projectDir = file("submodules/SubKMPProject/shared") | |
``` | |
--- | |
### 3. 依存関係を追加(`build.gradle.kts`) | |
```kotlin | |
dependencies { | |
implementation(project(":SubKMPProject")) | |
} | |
``` | |
> サブプロジェクトの中の特定モジュールを使いたい場合も同様に指定します。 | |
--- | |
### 4. ターゲットと `sourceSets` の整合性を確認 | |
- 両プロジェクトで `kotlin {}` ブロック内の `targets`(例: `android()`, `ios()`, `jvm()`)が一致していること | |
- `sourceSets` の命名や構造も整合させること | |
--- | |
### 5. サブモジュールの更新方法 | |
```bash | |
git submodule update --remote --merge | |
``` | |
> 最新の `main` や `master` ブランチを取り込めます。 | |
--- | |
### 6. GitHub 認証(プライベートリポジトリの場合) | |
- `.netrc` ファイルや GitHub CLI (`gh auth login`) を使って認証設定を行う必要があります。 | |
--- | |
## 補足 | |
- 共通の依存やビルドロジックが多い場合、`buildSrc` モジュールを使って共通化するのもおすすめです。 | |
--- | |
必要なら `buildSrc` のテンプレートや、複数モジュールでの `sourceSets` 共通化の例も出せます。必要ですか? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment