After all it's not that tricky. Build fails with Maven 3.0.x, make sure to use a later version, 3.2.3 seems to be working fine. You'll also need the http.ssl hacks.
Pre-requisities
You'll need git. Using Ubuntu/Debian, a
sudo apt-get install git
will do, or on FreeBSD you can use
sudo portmaster devel/git
And now the fun part. On FreeBSD, the lines involving maven can be omitted if a version is already installed via ports via a "sudo portmaster devel/maven3"
cd ~/tools
wget http://apache.cu.be/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz
tar xvzf apache-maven-3.2.3-bin.tar.gz
ln -s ~/tools/apache-maven-3.2.3 ~/tools/maven
export PATH=~/tools/maven/bin:$PATH
export MAVEN_OPTS="-XX:PermSize=1500m -XX:MaxPermSize=1800m -Xmx4g"
cd ~/dev
git clone https://github.com/sonatype/nexus-oss.git
cd nexus-oss
# if you don't need https just uncomment below
cat >> etc/org.sonatype.nexus.cfg << FILE_SEPARATOR
application-port-ssl=8443
FILE_SEPARATOR
mvn -Dskip-testsuite -DskipTests -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
sudo unzip -d /opt assemblies/nexus-base-template/target/nexus-base-template-*.zip
sudo ln -s /opt/nexus-base-template-* /opt/nexus
Autostart on Ubuntu/Debian
As of today, the wrapper service we can use in Karaf to autostart things does not work.
As a workaround to autostart, create a /etc/init.d/nexus file:
#!/bin/bash
NEXUS_HOME=/opt/nexus
case "$1" in
start)
log_begin_msg "Starting Nexus OSS..."
$NEXUS_HOME/bin/start
log_end_msg 0
;;
stop)
log_begin_msg "Shutting down Nexus OSS..."
$NEXUS_HOME/bin/stop
log_end_msg 0
;;
*)
;;
esac
...and execute this statement:
sudo update-rc.d nexus defaults 98 02
Autostart on FreeBSD
Start by putting the following script to /etc/rc.d/nexus:
#!/bin/sh
. /etc/rc.subr
name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7
nexus_start() {
\$NEXUS_HOME/bin/start
}
nexus_stop() {
\$NEXUS_HOME/bin/stop
}
load_rc_config \${name}
run_rc_command "\$1"
...and adapt appropriately to your system of course. You'll need to make it executable:
chmod +x /etc/rc.d/nexus
To activate it, you need to add the following to your /etc/rc.conf:
nexus_enable="YES"
If you need this often
If you need to re-do the same thing from time to time in different environments for different projects, you prefer to simplify things. So here is the single-copy-paste-prepared version; the same as above, this time without the explanation, automated.
cat > /etc/rc.d/nexus << FILE_SEPARATOR
#!/bin/sh
. /etc/rc.subr
name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7
nexus_start() {
\$NEXUS_HOME/bin/start
}
nexus_stop() {
\$NEXUS_HOME/bin/stop
}
load_rc_config \${name}
run_rc_command "\$1"
FILE_SEPARATOR
chmod +x /etc/rc.d/nexus
cat >> /etc/rc.conf << FILE_SEPARATOR
nexus_enable="YES"
FILE_SEPARATOR
service nexus start
Usage
To deploy to the locally installed Nexus, you can
- - change your pom.xmls to refer to this local nexus for deployment
- - change your settings.xml use the local nexus for deployment
<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">
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus</name>
<mirrorOf>external:*</mirrorOf>
<url>http://127.0.0.1:8081/content/groups/public/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>jnc</id>
<username>tomcat</username>
<privateKey>${user.home}/.ssh/id_rsa</privateKey>
</server>
<server>
<id>nexus</id>
<username>admin</username>
<password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
</server>
<server>
<id>releases</id>
<username>admin</username>
<password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
</server>
</servers>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<nexus.url>http://127.0.0.1:8081</nexus.url>
<repos.public.url>${nexus.url}/content/groups/public</repos.public.url>
<repos.release.url>${nexus.url}/content/repositories/releases</repos.release.url>
<repos.snapshot.url>${nexus.url}/content/repositories/snapshots</repos.snapshot.url>
</properties>
<repositories>
<repository>
<id>nexus</id>
<name>public</name>
<url>${repos.public.url}</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
<repository>
<id>snapshots</id>
<name>snapshots</name>
<url>${repos.snapshot.url}</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
<repository>
<id>releases</id>
<name>releases</name>
<url>${repos.release.url}</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>public</name>
<url>${repos.public.url}</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<name>snapshots</name>
<url>${repos.snapshot.url}</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<enabled>false</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>releases</id>
<name>releases</name>
<url>${repos.release.url}</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
...and this goes to settings-security.xml, using the default password for authentication. If following this guide, on your local, firewalled server the default username/password combination might do. Otherwise change your password in nexus and update your settings.xml and settings-security.xml appropriately as described
here.
<settingsSecurity>
<master>{KFp2s9kTyrcHsy+BT4dooaLri1eMcy+32raBPgydYvw=}</master>
</settingsSecurity>
- use the following construct which overrides your default deployment directory:
mvn clean deploy -DaltDeploymentRepository=nexus::default::http://127.0.0.1:8081/content/repositories/snapshots
Possible errors
Using Maven versions earlier than 3.2.3 may yield to the following error:
Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty