---
schema_version: "1"
id: a1c94f815f571d534964b9a209acd96b6e0aa09f3eecdbff1658a2cdb0227a58
title: Uploading a Custom Policy to Exchange
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-gateway/policies-custom-upload-to-exchange.md
canonical_url: https://docs.mulesoft.com/mule-gateway/policies-custom-upload-to-exchange
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9250839652a7bc3b34187372e174dacb051321a3843e2915694a01ec71d67585
description: MuleSoft Documentation Site
latest: true
---
---
product: Mule Gateway
keywords: custom policy, upload, Exchange
---

# Uploading a Custom Policy to Exchange

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Exchange provides an API to publish or consume assets using a Maven client. You must have a unique
artifact name and organization ID to publish your asset. API Manager lists custom policies published
as assets of your organization.

For more information about the Exchange Maven Facade asset, see
[Exchange Maven Facade](https://anypoint.mulesoft.com/exchange/portals/anypoint-platform/f1e97bc6-315a-4490-82a7-23abe036327a.anypoint-platform/exchange-maven-facade-api-http/).

## Prerequisites

To upload a custom policy to Exchange, you must have the Exchange Contributors role.

## Deploying a Policy Created Using the Maven Archetype

If you create your custom policy project using the provided Maven archetype, the plugins necessary
to upload the policy to Exchange are already defined for you. See
[Setting Up a Project with the Archetype](https://docs.mulesoft.com/mule-gateway/policies-custom-getting-started#setting-up-a-project-with-the-archetype).

To deploy a policy created using the Maven archetype:

1.  In your Maven `.m2` directory, update the `settings.xml` file with your Exchange credentials.

    ```xml
    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
           <id>exchange-server</id>
           <username>myusername</username>
           <password>mypassword</password>
         </server>
      </servers>
    </settings>
    ```

    > [!NOTE] For information about how to authenticate using a token rather than using credentials,
    > see
    > [Publish and Consume Federated Assets](https://docs.mulesoft.com/exchange/to-publish-assets-maven#publish-and-consume-federated-assets).

2.  Run `mvn clean deploy` to publish the policy to Exchange.

    The custom policy is now available for you to apply to APIs that belong to the specified
    organization.

    > [!NOTE] For Java 17 support, add `supportedJavaVersions: ["8", "11", "17"]` to the policy
    > definition YAML. See
    > [YAML Configuration File](https://docs.mulesoft.com/mule-gateway/policies-custom-mule-4-reference#yaml-configuration-file).

## Deploying a Policy Created Without Using the Maven Archetype

If you did not create your custom policy project using the provided Maven archetype, you must
manually define the Exchange deployment configuration.

To deploy a policy created without using the Maven archetype:

1.  In Anypoint Platform, find the organization ID to use as follows:

    1.  Go to **Access Management > Organization**.

    2.  Click the name of your organization.

    3.  Copy the UUID from the browser address. For example, copy
        _2a4b93c3-7899-4ea7-9374-f787744d8784_ from the URL.

2.  Update your `pom.xml` file as follows:

    1.  Replace the `groupId` value with the organization ID from the preceding step:

        ```XML
        <groupId>{orgId}</groupId>
        ```

    2.  Add the following properties and replace `{orgId}` with the organization ID from the
        preceding step:

        ```XML
        <properties>
          <exchange.url>https://maven.anypoint.mulesoft.com/api/v3/organizations/{OrgId}/maven</exchange.url>
          <mule.maven.plugin.version>3.2.0</mule.maven.plugin.version> <!-- check for last available version -->
        </properties>
        ```

    3.  Define Exchange as a repository:

        ```XML
        <repository>
        	<id>exchange-server</id>
        	<name>MuleSoft Exchange Environment</name>
        	<url>${exchange.url}</url>
        	<snapshots>
        		<enabled>true</enabled>
        	</snapshots>
        </repository>
        ```

    4.  Set up your Exchange server as a distribution management repository:

        ```XML
        <distributionManagement>
            <repository>
                <id>exchange-server</id>
                <name>Corporate Repository</name>
                <url>${exchange.url}</url>
                <layout>default</layout>
            </repository>
        </distributionManagement>
        ```

    5.  Add the following build plugins:

        - Mule Maven plugin: Verifies that all necessary files are present and that all requirements
          are met to correctly package the policy.

        - Maven Deploy plugin: Communicates with the Exchange repository and uploads the policy JAR
          and YAML files.

          ```XML
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.mule.tools.maven</groupId>
                      <artifactId>mule-maven-plugin</artifactId>
                      <version>${mule.maven.plugin.version}</version>
                      <extensions>true</extensions>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-deploy-plugin</artifactId>
                      <executions>
                          <execution>
                              <id>upload-template</id>
                              <phase>deploy</phase>
                              <goals>
                                  <goal>deploy-file</goal>
                              </goals>
                              <configuration>
                                  <repositoryId>exchange-server</repositoryId>
                                  <url>${exchange.url}</url>
                                  <file>${project.basedir}/${project.artifactId}.yaml</file>
                                  <generatePom>false</generatePom>
                                  <groupId>${project.groupId}</groupId>
                                  <artifactId>${project.artifactId}</artifactId>
                                  <version>${project.version}</version>
                                  <packaging>yaml</packaging>
                                  <classifier>policy-definition</classifier>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
          ```

    6.  Add the following plugin repository:

        ```XML
        <pluginRepositories>
            <pluginRepository>
                <id>mule-plugin</id>
                <name>Mule Repository</name>
                <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
            </pluginRepository>
        </pluginRepositories>
        ```

3.  In your Maven `.m2` directory, update the settings.xml file with your Exchange credentials:

    ```XML
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
           <id>exchange-server</id>
           <username>myusername</username>
           <password>mypassword</password>
         </server>
      </servers>
    </settings>
    ```

    > [!NOTE] For information about how to authenticate using a token rather than using credentials,
    > see
    > [Publish and Consume Federated Assets](https://docs.mulesoft.com/exchange/to-publish-assets-maven#publish-and-consume-federated-assets).

4.  Deploy the policy using the `mvn clean deploy` command.

    > [!NOTE] The IDs defined for your Exchange repositories must match.

    The custom policy is now available for you to apply to APIs that belong to the specified
    organization.

    > [!NOTE] For Java 17 support, add `supportedJavaVersions: ["8", "11", "17"]` to the policy
    > definition YAML. See
    > [YAML Configuration File](https://docs.mulesoft.com/mule-gateway/policies-custom-mule-4-reference#yaml-configuration-file).

## See Also

- [Packaging a Custom Policy](https://docs.mulesoft.com/mule-gateway/policies-custom-package)

- [Reviewing Custom Policy Concepts](https://docs.mulesoft.com/mule-gateway/policies-custom-mule-4-reference)
