Last mod: 2024.11.27

Reposilite - lightweight proxy for maven repositories

Sometimes we need a local, lightweight proxy for maven packages. On the one hand, such a proxy will reduce the transfer of data from the internet, speed up project development and protect against internet connection failures.

Network diagram

Prepare environment

Reposilite 3.x requires Java11+ to work.

Let's check if we have Java:

java -version

On a new system (e.g. Ubuntu 24.04LTS) we will probably get: Screen-JavaVersion Install JDK21:

sudo apt update && sudo apt install openjdk-21-jre-headless -y

Check that the installation is correct:: Screen-JavaVersion2

Download and run

Go to https://reposilite.com/, click download and you will be redirected to download releases https://github.com/dzikoysk/reposilite/releases

cd /opt
sudo mkdir reposilite
sudo chown user: reposilite/
cd cd reposilite/
wget https://maven.reposilite.com/releases/com/reposilite/reposilite/3.5.18/reposilite-3.5.18-all.jar

I assume that the logged-in user has the login name 'user'.

Let's see what we have downloaded into the catalogue:

Screen-ll

Create bash file to run Reposilite:

vi ./run.sh

with body:

#!/bin/sh
java -jar /opt/reposilite/reposilite-3.5.18-all.jar --token admin:changeit

The value 'admin:changeit' is the login and password, I suggest changing this.

Save and add permission to execute and run:

chmod +x ./run.sh
./run.sh

We can go to the control panel http://localhost:8080

ScreenReposilite1

Next login admin/changeit. Go to 'Settings' tab, next 'Maven' tab, click '+' icon and insert repository address:

https://repo1.maven.org/maven2/

ScreenReposilite3

From this point on, Reposilite works as a proxy for repositories https://repo1.maven.org/maven2/. We can, of course, add other repositories. Reposilite offers much greater configuration possibilities.

Set Storage policy as STRICT. This is very important if we want to full offline work.

ScreenReposilite3

Run as service

Create service file:

sudo vi /etc/systemd/system/reposilite.service

with body:

[Unit]
Description=Reposilite
After=network.target

[Service]
WorkingDirectory=/opt/reposilite
ExecStart=/opt/reposilite/run.sh
Restart=always
User=user
Group=user

[Install]
WantedBy=multi-user.target

Save and exit. Next run:

sudo systemctl daemon-reload
sudo systemctl start reposilite.service

and check status:

sudo systemctl status reposilite.service

ScreenService1

If everything is ok we enable the service to start during system startup:

sudo systemctl enable reposilite.service

How to configure proxy on workstation

If we want to use it transparently for our projects, we need to create an file ~/.gradle/init.gradle with body:

allprojects {
    repositories {
        all { repo ->
            if (repo instanceof MavenArtifactRepository) {
                repo.url = uri('http://reposilite_proxy_address:8080/releases')
                repo.allowInsecureProtocol = true
            }
        }
    }
}

If we want to set it individually for projects, we can modify the gradle.properties files

systemProp.http.proxyHost=reposilite_proxy_address
systemProp.http.proxyPort=8080

Advanced configuration parameters

If you need change default port 8080, add SSL connections and other parameters, you can edit /opt/reposilite/configuration.cdn autogenerated when you run Reposilite first time.