Top 10 Archiva Tips & Best Practices for Repo Management

Getting Started with Archiva — Installation to First RepositoryApache Archiva is an open-source build artifact repository manager primarily used for managing Maven repositories. It provides a central location to store and proxy build artifacts (JARs, POMs, plugins), control access, and improve build performance by caching remote dependencies. This guide walks you through installing Archiva, configuring it, and publishing your first repository and artifact.


Prerequisites

  • A server or VM (Linux, macOS, or Windows) with at least 2 GB RAM recommended for small teams.
  • Java JDK 11 or later installed and JAVA_HOME set.
  • Network access for downloading Archiva and any proxied repositories (e.g., Maven Central).
  • Basic command-line familiarity.

1. Downloading Archiva

  1. Visit the Archiva download page (Apache Archiva project) and download the latest binary distribution (ZIP or TAR.GZ).
  2. Extract the archive to a suitable directory on your server, e.g., /opt/archiva or C:rchiva.

Example (Linux):

cd /opt sudo tar xzf apache-archiva-<version>-bin.tar.gz sudo mv apache-archiva-<version> archiva 

2. Installing Java and setting JAVA_HOME

Archiva requires a Java runtime (JDK 11+). Verify Java:

java -version 

If Java is not installed, install OpenJDK 11 (example for Ubuntu/Debian):

sudo apt update sudo apt install openjdk-11-jdk 

Set JAVA_HOME (example for bash):

echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64' >> ~/.bashrc source ~/.bashrc 

3. Starting Archiva

From the Archiva installation directory, you can start Archiva using the provided scripts.

Linux/macOS:

cd /opt/archiva ./bin/archiva console 

Windows:

  • Use binrchiva.bat to start in a console or install as a Windows service with additional tools.

When started, Archiva runs an embedded web server (default port 8080). Visit http://localhost:8080/archiva to access the web UI.

Tip: For production use, run Archiva as a background service (systemd on Linux) and configure proper user permissions.


4. Initial Web Setup and Administrator Account

On first run, Archiva presents a setup wizard in the web UI:

  • Create the initial administrator account (username, password, email). Keep these credentials safe.
  • Configure basic settings like repository locations, indexing schedule, and mail server (optional).
  • Archiva will create default managed repositories (e.g., snapshots and releases) — you can keep or customize these.

5. Repositories in Archiva — Concepts

  • Managed Repository: A repository hosted by Archiva where you deploy your own artifacts (releases and snapshots).
  • Remote Repository: A proxy to a remote repository (e.g., Maven Central). Archiva caches artifacts from remotes for faster access.
  • Group Repository: A virtual collection of managed and remote repositories, used as the single URL clients consume.

Typical setup:

  • A “releases” managed repo for released artifacts.
  • A “snapshots” managed repo for snapshot builds.
  • A “central” remote repo that proxies Maven Central.
  • A group repo (e.g., “public”) combining the above for developers and CI to use.

6. Creating and Configuring a Managed Repository

  1. In the Archiva web UI, go to Administration → Repositories → Managed Repositories → Add Managed Repository.
  2. Fill in:
    • ID (e.g., company-releases)
    • Name (e.g., Company Releases)
    • Location (filesystem path where artifacts will be stored; Archiva will create directories)
    • Layout (default: Maven 2)
    • Snapshot handling (allow/deny snapshots)
    • Retention/policies (optional: how many snapshots to keep)
  3. Save the repository. Archiva will initialize it and update its index.

7. Configuring a Remote Repository (Proxy)

  1. Administration → Repositories → Remote Repositories → Add Remote Repository.
  2. Provide:
    • ID and Name (e.g., central)
    • URL (e.g., https://repo1.maven.org/maven2)
    • Cache settings (time-to-live for cached artifacts)
    • Authentication if the remote requires it (rare for Maven Central)
  3. Save and test connection.

8. Creating a Group Repository

  1. Administration → Repositories → Group Repositories → Add Group Repository.
  2. Choose an ID (e.g., public) and add member repositories in order (managed and remote). Ordering matters for resolution.
  3. Save. Use the group repository URL for developer builds and CI (e.g., http://archiva-host:8080/repository/public).

9. Securing Archiva: Users, Roles, and Access Control

Archiva supports user management and fine-grained access control.

  • Users: Create accounts for developers and CI systems (Administration → Users).
  • Roles: Define roles with specific permissions (Administration → Roles). Examples: developers, read-only, CI.
  • Assign repositories to roles so users only deploy or read from allowed repositories.

For CI, create a machine user with credentials and grant “deploy” permission on the releases repo.


10. Deploying Your First Artifact

There are several ways to deploy artifacts to a managed repository:

A — Maven deploy (recommended for Maven projects)

  1. Add distribution management to your pom.xml:
<distributionManagement>   <repository>     <id>company-releases</id>     <url>http://archiva-host:8080/repository/company-releases</url>   </repository>   <snapshotRepository>     <id>company-snapshots</id>     <url>http://archiva-host:8080/repository/company-snapshots</url>   </snapshotRepository> </distributionManagement> 
  1. Add credentials to your Maven settings (~/.m2/settings.xml):
<servers>   <server>     <id>company-releases</id>     <username>ci-user</username>     <password>ci-password</password>   </server> </servers> 
  1. Run:
    
    mvn deploy 

    Maven will upload the artifact to Archiva’s managed repository.

B — Upload via Web UI

  • Administration → Repositories → Managed Repositories → Browse → Upload Artifact. Select files (POM, JAR, sources, javadoc) and upload.

C — REST API / CLI

  • Archiva exposes REST endpoints and supports scripted uploads — useful for automated pipelines.

11. Verifying the Artifact

  • In the Archiva web UI, browse the managed repository to confirm the artifact is present and index has been updated.
  • Use a sample project’s pom.xml to add the group repository URL and try building to verify artifact resolution.

Example settings for consuming artifacts (settings.xml or pom repositories block):

<repository>   <id>company-public</id>   <url>http://archiva-host:8080/repository/public</url> </repository> 

12. Indexing and Searching

Archiva maintains searchable indexes of repositories. Configure indexing schedules and enable remote indexing for faster searches. Use the web UI search to find artifacts by groupId, artifactId, version, or classifier.


13. Backups and Maintenance

  • Regularly back up the managed repository storage directory and Archiva configuration (conf/).
  • Monitor disk space; repository growth can be rapid.
  • Configure retention policies for snapshots to limit storage usage.
  • Keep Archiva and Java up to date for security patches.

14. Running Archiva in Production

  • Use a dedicated service account and systemd unit (Linux) to run Archiva.
  • Configure reverse proxy (Nginx or Apache) for TLS termination and virtual-host routing.
  • Set up monitoring (disk, process, memory) and automated restarts.
  • Consider externalizing the configuration directory and logs to persistent volumes if running in containers.

Example minimal systemd unit (adjust paths and user):

[Unit] Description=Apache Archiva After=network.target [Service] Type=simple User=archiva Group=archiva ExecStart=/opt/archiva/bin/archiva console WorkingDirectory=/opt/archiva Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target 

15. Troubleshooting Common Issues

  • Port conflicts: Ensure port 8080 is free or change the port in conf/server.xml.
  • Java memory errors: Increase JVM memory in bin/setenv (ARCHIVA_OPTS).
  • Permissions: Ensure the Archiva process user can read/write the repository storage directory.
  • Failed deployments: Check Archiva logs (logs/archiva.log) for authentication or validation errors.

16. Next Steps and Best Practices

  • Integrate Archiva with CI/CD (Jenkins, GitLab CI, GitHub Actions) for automated deploys.
  • Use signed artifacts and checksum validation for integrity.
  • Enforce repository cleanup policies for snapshots.
  • Limit anonymous access; use roles and audit logs to track deployments.

By following these steps you’ll have Archiva installed, secured, and serving as the single source for your project artifacts. This improves build reliability, speeds up dependency resolution, and centralizes artifact governance.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *