In Android dependency management, it’s common to configure multiple remote repositories like jcenter, jitpack, google(), and more. Some large projects, such as “Zuiyou”, depend on over 10 repositories. This becomes a significant problem during initial project setup, dependency changes, or network issues — troubleshooting builds becomes a nightmare.
I had noticed this issue long ago but kept putting off addressing it. This post documents the Nexus setup process.
Installing and Configuring Nexus#
Prerequisite: JDK 8+.
1
2
3
4
5
6
7
8
9
10
11
12
| # Download and extract Nexus
mkdir /app && cd /app
wget -O nexus.tar.gz https://download.sonatype.com/nexus/3/latest-unix.tar.gz
tar -xvf nexus.tar.gz
mv nexus-3* nexus
# Create a dedicated user
adduser nexus
# Set ownership
chown -R nexus:nexus /app/nexus
chown -R nexus:nexus /app/sonatype-work
|
Configure the runtime user:
1
2
3
| vi /app/nexus/bin/nexus.rc
# Add the following line
run_as_user="nexus"
|
To customize storage paths, edit the JVM options:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| vi /app/nexus/bin/nexus.vmoptions
-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=/nexus/nexus-data
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
|
Setting Up Systemd Service#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| vi /etc/systemd/system/nexus.service
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
User=nexus
Group=nexus
ExecStart=/app/nexus/bin/nexus start
ExecStop=/app/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
|
1
2
3
| # Enable and start
chkconfig nexus on
systemctl start nexus
|
Initial Configuration#
- Open
http://<ip>:8081 - Click Sign In
- Retrieve the default password:
cat /app/sonatype-work/nexus3/admin.password - Change the password to complete setup
1
2
| systemctl stop nexus
systemctl restart nexus
|
Setting Up Proxy Repositories#
Nexus defines three fundamental repository types:
| Type | Description |
|---|
| group | Combines multiple repositories into a single endpoint |
| hosted | Stores private artifacts internally |
| proxy | Proxies and caches remote sources (e.g., Maven Central) |
The optimization strategy is to aggregate all remote repositories behind a Nexus group repository, so clients only need to configure a single repository URL. This reduces network requests during dependency resolution and speeds up builds significantly.
References#