Configuring Maven to work with a SourceCraft registry

  1. Create a personal access token (PAT).

  2. Open the file with the global Maven settings.

    By default, the configuration file is located in the current user's .m2 directory (~/.m2/settings.xml for Unix-like OSes and %USERPROFILE%\.m2\settings.xml for Windows). You can learn more about the configuration file structure in the Maven documentation.

  3. Add a new repository to the configuration file's repositories section:

    <repository>
        <id>local</id>
        <url>pkg.sourcecraft.tech/maven/<organization_slug>/<registry_ID></url>
    </repository>
    

    Tip

    You can find the organization slug and registry ID on the registry page in the SourceCraft UI.

  4. Add a new server to the servers section of the Maven settings:

    <server>
        <id>local</id>
        <username>${env.REGISTRY_USERNAME}</username>
        <password>${env.REGISTRY_PASSWORD}</password>
    </server>
    
  5. Create the REGISTRY_PASSWORD environment variable:

    export REGISTRY_USERNAME=iam
    export REGISTRY_PASSWORD=<personal_access_token>
    

    Where <personal_access_token> stands for contents of the previously obtained personal access token.

Template of a file with the global Maven settings

<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/<organization_slug>/<registry_ID></url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>sourcecraft</id>
      <username>iam</username>
      <password><personal_token></password>
    </server>
  </servers>

</settings>

See also