#!/bin/bash
set -eux
mkdir -p tmp/use-maven-repository-from-mvn && cd tmp/use-maven-repository-from-mvn
#
# test the maven repository.
# install maven and the java development kit.
sudo apt-get install -y maven
sudo apt-get install -y default-jdk
sudo apt-get install -y xmlstarlet
# setup the user maven configuration to use nexus as a mirror the
# official maven repository.
# see https://help.sonatype.com/display/NXRM3/Maven+Repositories
# see https://maven.apache.org/guides/mini/guide-mirror-settings.html
mkdir -p ~/.m2
cat >~/.m2/settings.xml <<'EOF'
nexus
alice.doe
password
nexus
central
http://localhost:8081/repository/maven-public/
nexus
central
http://central
true
true
central
http://central
true
true
nexus
EOF
# test our nexus repository by creating an hello world project, which
# will pull from our nexus repository.
mvn \
--batch-mode \
archetype:generate \
-DgroupId=com.example.helloworld \
-DartifactId=example-helloworld \
-DarchetypeArtifactId=maven-archetype-quickstart
# test publishing a package.
pushd example-helloworld
# add the nexus repository to pom.xml.
xmlstarlet ed --inplace -N pom=http://maven.apache.org/POM/4.0.0 \
--subnode '/pom:project' \
--type elem \
--name distributionManagement \
--value '@@repositories@@' \
pom.xml
python -c '
xml = open("pom.xml").read().replace("@@repositories@@", """
nexus
Releases
http://localhost:8081/repository/maven-releases
nexus
Snapshot
http://localhost:8081/repository/maven-snapshots
""")
open("pom.xml", "w").write(xml)
'
# deploy.
mvn \
--batch-mode \
deploy
popd