# Maven

---

## Overview

Your private Maven artifacts and public dependencies from Maven Central, all managed through one registry.

---

## Supported Clients

JFrog Fly supports Maven artifacts with:

- **Maven CLI** (`mvn deploy`, `mvn install`) - The standard Apache Maven build tool

---

## Upload / Deploy Artifact

### With Fly App

Activate Maven in your Fly App to configure Maven globally with Fly, then deploy as usual:

```bash
mvn clean deploy
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure Maven credentials** by editing `~/.m2/settings.xml`:

```xml
<settings>
  <servers>
    <server>
      <id>fly-maven</id>
      <username><your-fly-username></username>
      <password><your-fly-token></password>
    </server>
  </servers>
  
  <profiles>
    <profile>
      <id>fly</id>
      <repositories>
        <repository>
          <id>fly-maven</id>
          <url>https://<your-fly-subdomain>.jfrog.io/artifactory/maven</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
  
  <activeProfiles>
    <activeProfile>fly</activeProfile>
  </activeProfiles>
</settings>
```

**3. Configure your project's `pom.xml`** - add the distribution management section:

```xml
<distributionManagement>
  <repository>
    <id>fly-maven</id>
    <url>https://<your-fly-subdomain>.jfrog.io/artifactory/maven</url>
  </repository>
  <snapshotRepository>
    <id>fly-maven</id>
    <url>https://<your-fly-subdomain>.jfrog.io/artifactory/maven</url>
  </snapshotRepository>
</distributionManagement>
```

> [!IMPORTANT]
> The `<id>` value (`fly-maven`) must match the server id in your `settings.xml`.

**4. Deploy artifact:**

```bash
mvn clean deploy
```

---

## Download / Install Dependencies

### With Fly App

Activate Maven in your Fly App to configure Maven globally with Fly, then install as usual:

```bash
mvn clean install
```

### Manual Configuration

**1. Generate an access token** in Fly Token Management

**2. Configure Maven** by editing `~/.m2/settings.xml` as shown in the Deploy section above.

**3. Install dependencies:**

```bash
mvn clean install
```

### From Public Registry

When you install a dependency that isn't in your Fly Registry, JFrog Fly automatically fetches it from Maven Central and caches it for future use.

```bash
mvn clean install
```

---

## Upload/Download Artifacts with CI

To deploy and install Maven artifacts with CI, update your GitHub Actions workflow to include the Fly action.

Simply ask your coding agent: **"Configure my workflows with Fly"** and Fly MCP will configure your GitHub Actions workflow yml file, as follows:

**1. Add permissions** (top level, after `on:`):
```yaml
permissions:
  contents: read
  id-token: write
```

**2. Add Fly Action** (after `actions/setup-java`, before Maven commands):
```yaml
- uses: jfrog/fly-action@v1              # Setup Fly package managers
```

### GitHub Action Example

```yaml
name: Build and Deploy Maven Artifact

on:
  push:
    branches: [main]

permissions:
  contents: read
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'

      - uses: jfrog/fly-action@v1              # Setup Fly package managers

      - run: mvn clean deploy                  # Build and deploy to Fly registry
```

---

*Back to [Package Managers →](../)*
