ドキュメントには頻繁に更新が加えられ、その都度公開されています。本ページの翻訳はまだ未完成な部分があることをご了承ください。最新の情報については、英語のドキュメンテーションをご参照ください。本ページの翻訳に問題がある場合はこちらまでご連絡ください。

Configuring Apache Maven for use with GitHub Packages

You can configure Apache Maven to publish packages to GitHub パッケージレジストリ and to use packages stored on GitHub パッケージレジストリ as dependencies in a Java project.

GitHub パッケージレジストリ is available with GitHub Free, GitHub Pro, GitHub Team, and GitHub Enterprise Cloud. GitHub パッケージレジストリ is unavailable for per-repository plans, which are legacy billing plans. For more information, see "GitHub's products."

ここには以下の内容があります:

GitHub パッケージレジストリ への認証を行う

You need an access token to publish, install, and delete packages in GitHub パッケージレジストリ. You can use a personal access token to authenticate with your username directly to GitHub パッケージレジストリ or the GitHub API. You can use a GITHUB_TOKEN to authenticate using a GitHub Actions workflow.

Authenticating with a personal access token

You must use a personal access token with the appropriate scopes to publish and install packages in GitHub パッケージレジストリ. For more information, see "About GitHub パッケージレジストリ."

You can authenticate to GitHub パッケージレジストリ with Apache Maven by editing your ~/.m2/settings.xml file to include your personal access token. Create a new ~/.m2/settings.xml file if one doesn't exist.

In the servers tag, add a child server tag with an id, replacing USERNAME with your GitHub username, and TOKEN with your personal access token.

In the repositories tag, configure a repository by mapping the id of the repository to the id you added in the server tag containing your credentials. Replace REPOSITORY with the name of the repository you'd like to publish a package to or install a package from, and OWNER with the name of the user or organization account that owns the repository. 大文字はサポートされていないため、仮にGitHubのユーザあるいはOrganization名が大文字を含んでいても、リポジトリオーナーには小文字を使わなければなりません。

If you want to interact with multiple repositories, you can add each repository to separate repository children in the repositories tag, mapping the id of each to the credentials in the servers tag.

<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">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>
</settings>

Note: GitHub パッケージレジストリ does not support SNAPSHOT versions of Apache Maven. Make sure you disable SNAPHOT in your ~/.m2/settings.xml file.

Authenticating with the GITHUB_TOKEN

If you are using a GitHub Actions workflow, you can use a GITHUB_TOKEN to publish and consume packages in GitHub パッケージレジストリ without needing to store and manage a personal access token. For more information, see "Authenticating with the GITHUB_TOKEN."

パッケージを公開する

By default, GitHub uses the package name to create a repository where the package will be published. For example, GitHub will publish a package named com.example.test in a repository called OWNER/test.

If you would like to publish multiple packages to the same repository, you can include the URL of the repository in the <scm> element of the pom.xml file. GitHub このフィールドを元にしてリポジトリを照合します。 Since the repository name is also part of the distributionManagement element, there are no additional steps to publish multiple packages to the same repository.

For more information on creating a package, see the maven.apache.org documentation.

  1. Edit the distributionManagement element of the pom.xml file located in your package directory, replacing OWNER with the name of the user or organization account that owns the repository and REPOSITORY with the name of the repository containing your project.

    <distributionManagement>
       <repository>
         <id>github</id>
         <name>GitHub OWNER Apache Maven Packages</name>
         <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
       </repository>
    </distributionManagement>
    
  2. Publish the package.

    $ mvn deploy

After you publish a package, you can view the package on GitHub. For more information, see "Viewing packages."

パッケージをインストールする

To install an Apache Maven package from GitHub パッケージレジストリ, edit the pom.xml file to include the package as a dependency. If you want to install packages from more than one repository, add a repository tag for each. For more information on using a pom.xml file in your project, see "Introduction to the POM" in the Apache Maven documentation.

  1. Authenticate to GitHub パッケージレジストリ. 詳しい情報については「GitHub パッケージレジストリへの認証を行う」を参照してください。

  2. Add the package dependencies to the dependencies element of your project pom.xml file, replacing com.example.test with your package.

    <dependencies>
      <dependency>
        <groupId>com.example</groupId>
        <artifactId>test</artifactId>
        <version>1.0.0</version>
      </dependency>
    </dependencies>
    
  3. パッケージをインストールします。

    $ mvn install

参考リンク

担当者にお尋ねください

探しているものが見つからなかったでしょうか?

弊社にお問い合わせください