---
schema_version: "1"
id: 8d1599418824a928998d38a2bd40017e92435412a421a4221bdb1612648c6c5a
title: 新規プロジェクトの作成
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/pdk/1.4/policies-pdk-create-project.md
canonical_url: https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-create-project
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 06166e69efc09aa3ec25502ee31ab9f89772ada95a68dbe0bc279cc36b9b785b
description: MuleSoft Documentation Site
release: "1.4"
latest: false
---
# 新規プロジェクトの作成

Flex Gateway ポリシー開発キット (PDK) を使用して新しいカスタムポリシーの開発を開始するには、新しいカスタムポリシープロジェクトを生成します。

新しいプロジェクトを作成するには、次のタスクを完了します。

1. [始める前に](#before-you-begin)
2. [新しいポリシープロジェクトを作成する](#create-a-new-policy-project)
3. [PDK ビルド環境のセットアップ](#setup-the-pdk-build-environment)
4. [プロジェクト構造](#project-structure)​を確認します。

## [](#before-you-begin)始める前に

カスタムポリシープロジェクトを作成する前に、すべての ​[PDK 前提条件](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-prerequisites)​がインストール済みであることを確認してください。

## [](#create-a-new-policy-project)新しいポリシープロジェクトを作成する

カスタムポリシープロジェクトを作成するには、PDK CLI ​`create`​ コマンドを実行します。​`<my-custom-policy>`​ には新しいポリシー名を指定してください

```ssh
anypoint-cli-v4 pdk policy-project create --name <my-custom-policy>
```

<table><tbody><tr><td class="icon"><i class="fa icon-note" title="Note"></i></td><td class="content">グループ ID が要求された場合は、​<a href="https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-troubleshooting#group-id-error" class="xref page">「グループ ID のトラブルシューティング」</a>​を参照してください。</td></tr></tbody></table>

`create`​ コマンドを実行すると指定した名前でカスタムポリシープロジェクトが作成されます。プロジェクトは、ポリシーと同じ名前の新しいディレクトリか、または ​`--output-dir`​ フラグで指定したディレクトリに保存されます。以下のチュートリアルでは、このディレクトリをプロジェクトのルートディレクトリと呼びます。

新しいポリシーの ​`assetID`​ は、ポリシーの名前を小文字にしてスペースを ​`-`​ に置き換えた文字列になります。たとえば、​`My Header Injection Policy`​ という名前のポリシーの ​`assetID`​ は、​`my-header-injection-policy`​ になります。

新しいポリシーの ​`groupID`​ は、Anypoint CLI で設定した組織の ID です。

`create`​ コマンドは、次のフラグをサポートします。

<table class="tableblock frame-all grid-all fit-content spread">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">フラグ</th>
<th class="tableblock halign-left valign-top">デフォルト値</th>
<th class="tableblock halign-left valign-top">必須</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>--name=&lt;value&gt;</code>​ または ​<code>-n</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>なし</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>はい</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>新しいポリシーの名前。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>--description=&lt;value&gt;</code>​ または ​<code>-d</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>なし</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>いいえ</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>新しいポリシーの説明。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>--output-dir=&lt;value&gt;</code>​ または ​<code>-o</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>assetID</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>いいえ</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>新しいポリシーが作成されるディレクトリ。<br>
指定したディレクトリが存在しない場合は新たに作成されます。ディレクトリが指定されていない場合は、ポリシーの ​<code>assetID</code>​ がディレクトリ名になります。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>--version=&lt;value&gt;</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>1.0.0</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>いいえ</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>新しいポリシーのバージョン。<br>
バージョンの形式は ​<code>&lt;major-release&gt;.&lt;minor-release&gt;.&lt;patch-release&gt;</code>​ です。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>--group-id=&lt;value&gt;</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>なし</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>いいえ</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>ポリシーを所有する組織の組織 ID。<br>
このフラグの詳細は、​<a href="https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-troubleshooting#group-id-error" class="xref page">「グループ ID のトラブルシューティング」</a>​を参照してください。</p>
</div></div></td>
</tr>
</tbody>
</table>

## [](#setup-the-pdk-build-environment)PDK ビルド環境のセットアップ

[新しいポリシープロジェクトを作成](#create-a-new-policy-project)​したら、​`make setup`​ コマンドを実行して、追加のソフトウェア連動関係をダウンロードする必要があります。

```ssh
make setup
```

## [](#project-structure)プロジェクト構造

`make setup`​ コマンドを実行すると、ポリシーのルートディレクトリに、次のディレクトリツリーに示すディレクトリとファイルが作成されます。

├─ definition/  # Contains the files that describe the policy Definition
│  ├── target/  # Contains the build definition asset files
│  └── gcl.yaml # GCL file managed by the developer that describes the policy Definition
├─ target/      # Contains the implementation asset files and the output of the policy build
├─ src/         # Contains the implementation source code
├─ playground/  # Contains the artifacts required for running the policy locally
├─ tests/        # Contains the source and configuration files to write and run integration tests
├─ Makefile     # Provides all the callable actions required during the policy development lifecycle
├─ Cargo.toml   # Rust language standard file that contains the metadata required to build the policy
└─.project.yaml # Project manifest used by PDK

### [](#target-および-definitiontarget)target/ および definition/target/

2 つの別々の​`ターゲット`​ディレクトリです。

- `definition/target/`​: Exchange にパブリッシュされたポリシーアセット定義が保存されます。
- `target/`​: ポリシーの Exchange アセット実装用のファイルとプロジェクトビルドの出力が保存されます。

両方のターゲットディレクトリとそのコンテンツは ​`.gitignore`​ ファイルに保存されます。​`make build`​ コマンドを使用して、各デバイス上でターゲットをコンパイルする必要があります。たとえば、チームでポリシーを開発する場合は、チームとしてポリシーとソースコードをリモートリポジトリにパブリッシュできますが、各チームメンバーがポリシーの作業に取り掛かるためには、自分のデバイス上でターゲットをビルドする必要があります。

### [](#definition)definition/

`definition`​ ディレクトリには、ポリシーのメタデータと設定プロパティを定義する ​`gcl.yaml`​ ファイルが保存されます。

`gcl.yaml`​ の設定については、[policy-pdk-create-schema-definition.adoc](#policy-pdk-create-schema-definition.adoc)を参照してください。

### [](#cargo-toml)Cargo.toml

Flex Gateway のカスタムポリシーは Rust プログラミング言語で開発され、WebAssembly バイナリにコンパイルされます。

`Cargo.toml`​ は、Rust プロジェクトのマニフェストファイルです。​`[package]`​ セクションには、ポリシーの実装に関する基本情報が含まれています。​`Cargo.toml`​ で指定されたバージョンは、ポリシーアセットのバージョンと一致します。ポリシーのバージョンは、​`Cargo.toml`​ のバージョン番号を編集することで管理できます。バージョンの形式は ​`<major-version>.<minor-version>.<patch-version>`​ です。

### [](#src)src/

`src`​ ディレクトリにはポリシーのソースコードが保存されます。

- `lib.rs`​: ポリシーの動作を実装するメソッドのセットが保存されます。PDK は、これらのメソッドをインクルードしてカスタムポリシーの動作を実装します。これらのメソッドについての詳細は、​[Rust でのカスタムポリシー機能の実装](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-configure-features). For complete policy examples, see [カスタムポリシーの例](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-policy-templates)​を参照してください。
- `generated/config.rs`​ および ​`generated/mod.rs`​: `gcl.yaml`​ で定義されているポリシーの設定を、​`lib.rs`​ やポリシーのソースファイルで使用できるようにする自動生成モジュールです。

### [](#makefile)Makefile

Makefile には、​`make`​ コマンドなど、ポリシー開発のライフサイクルに必要な呼び出し可能なアクションがすべて含まれています。すべての ​`make`​ コマンドは、カスタムポリシーディレクトリのルートレベルで実行します。

- `make setup`​: Makefile の残りのゴールに必要な PDK の内部連動関係をインストールします。
    
    プロジェクトの設定についての詳細は、​[PDK ビルド環境のセットアップ](#setup-the-pdk-build-environment)​を参照してください。
- `make build-asset-files`​: ポリシーのビルド、実行、パブリッシュに必要なすべてのポリシーアセットファイルを生成します。このコマンドは、​`gcl.yaml`​ ファイルで定義されている最新の設定で ​`config.rs`​ ソースコードファイルを更新します。
    
    ポリシーのコンパイルの詳細については、[カスタムポリシーのコンパイル](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-compile-policies)を参照してください。
- `make build`​: `make build-asset-files`​ コマンドを実行して、ポリシーの WebAssembly バイナリをコンパイルします。
    
    ポリシーのコンパイルの詳細については、[カスタムポリシーのコンパイル](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-compile-policies)を参照してください。
- `make run`​: コンテナ化された Docker 環境でポリシーの現在のビルドを簡単に実行する方法を提供します。
    
    ポリシーの実行とデバッグの詳細については、[PDK デバッグプレイグラウンドでのカスタムポリシーのデバッグ](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-debug-local)を参照してください。
- `make test`​: PDK が提供するテストフレームワークを使用して、​`tests/`​ に保存されているテストを実行します。
    
    ポリシーのテストの詳細については、[インテグレーションテストの作成](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-integration-tests)を参照してください。
- `make publish`​: ポリシーアセットを Exchange でパブリッシュします。
    
    Exchange でのポリシーのパブリッシュについての詳細は、[Exchange へのカスタムポリシーのアップロード](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-publish-policies)を参照してください。
- `make release`​: ポリシーアセットを Exchange でリリースします。
    
    Exchange でのポリシーのリリースについての詳細は、[Exchange へのカスタムポリシーのアップロード](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-publish-policies)を参照してください。
- `make help`​: PDK が提供するすべての ​`make`​ コマンドをリスト表示します。

## [](#関連情報)関連情報

- [PDK のトラブルシューティング](https://docs.mulesoft.com/jp/pdk/1.4/policies-pdk-troubleshooting)