---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configure-maven.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-maven.md
  - href: ru/sourcecraft/operations/configure-maven.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/ru/llms.txt

# Настроить Maven для работы с реестром SourceCraft

1. [Создайте](https://sourcecraft.dev/portal/docs/ru/sourcecraft/security/pat.md#create) персональный токен (PAT).
1. Откройте файл с глобальными настройками Maven.

    По умолчанию файл с настройками расположен в директории `.m2` текущего пользователя (`~/.m2/settings.xml` для Unix-подобных ОС и `%USERPROFILE%\.m2\settings.xml` для Windows). Подробнее о структуре файла настроек в [документации Maven](https://maven.apache.org/settings.html).
1. В раздел `repositories` файла с настройками добавьте новый репозиторий:

    ```xml
    <repository>
        <id>local</id>
        <url>pkg.sourcecraft.tech/maven/<слаг_организации>/<идентификатор_реестра></url>
    </repository>
    ```

    <!-- source: ru/_includes/sourcecraft/get-slug-registry-id-notice.md -->
    {% note tip %}

    Слаг организации и идентификатор реестра вы можете узнать на странице реестра в интерфейсе SourceCraft.

    {% endnote %}
    <!-- endsource: ru/_includes/sourcecraft/get-slug-registry-id-notice.md -->

1. В раздел `servers` настроек Maven добавьте новый сервер:

    ```xml
    <server>
        <id>local</id>
        <username>${env.REGISTRY_USERNAME}</username>
        <password>${env.REGISTRY_PASSWORD}</password>
    </server>
    ```

1. Создайте переменную окружения `REGISTRY_PASSWORD`:

    ```bash
    export REGISTRY_USERNAME=iam
    export REGISTRY_PASSWORD=<персональный_токен>
    ```

    Где `<персональный_токен>` — содержимое полученного ранее персонального токена.

## Шаблон файла с глобальными настройками Maven {#config-template}

```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 https://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>sourcecraft</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>sourcecraft</id>

      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
        </repository>
        <repository>
          <id>sourcecraft</id>
          <url>https://pkg.sourcecraft.tech/maven/<слаг_организации>/<идентификатор_реестра></url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>sourcecraft</id>
      <username>iam</username>
      <password><персональный_токен></password>
    </server>
  </servers>

</settings>
```

#### Полезные ссылки {#see-also}

* [Взаимосвязь ресурсов SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/concepts/index.md)
* [Создать реестр (registry) в SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/packages-management.md)
* [Подключить реестр (registry) к репозиторию SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/connect-registry.md)
* [Настроить npm для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-npm.md)
* [Настроить NuGet для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-nuget.md)
* [Настроить PyPI для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-pypi.md)
* [Настроить Docker для работы с реестром SourceCraft](https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/configure-docker.md)
