Nexus supports some housekeeping scheduled tasks, but some use cases are not covered.
Especially when it comes to Maven releases in private repositories, old artifacts can be removed after a certain time.
These releases have to be selectively picked in order to not remove artifacts that are still required.
This commandline utility uses the Nexus REST API to perform a GAV search, optionally including wildcards, and returns the results.
Once the GAV fits, --delete
will actually remove them remotely.
% go get github/jhinrichsen/nexus-mass-deletion % cd ${HOME}/go/src/github/jhinrichsen/nexus-mass-deletion % go install
The result is a standalone statically linked executable for your platform.
When called without any parameters, or -h, the Usage is displayed:
Usage: nexus-mass-deletion [options] [group...|@filename] @ references a file with groups separated by newline -artifact string Limit search to an artifact -count int Nexus count parameter in REST interface (default 200) -delete delete search results (otherwise only display them) -expect int expected number of results (default 1) -keepLatest keep lastest version (default true) -password string Nexus password (default "admin123") -port string Nexus port (default "8081") -repository string Nexus repository ID, empty for global search (default "releases") -server string Nexus server name (default "localhost") -throttle int throttle number of actions (default 1) -username string Nexus user (default "admin") -version string Limit search to specific version (may include wildcards)
- server, port
-
Remote location of Nexus installation
- expect
-
This is a safety net for removal. If a search returns more GAVs than expected, processing will not continue.
- throttle
-
Throttle will stop processing after the specified number.
- count
-
Nexus REST API supports a count parameter, but Nexus imposes a limit (either 100 or 200) which cannot be increased using
count
.
% nexus-mass-deletion --version='3.2.1' \ com.mycorp.product1.batch \ com.mycorp.product1.frontend \ com.mycorp.product1.db
will issue a REST search request against localhost:8081 using username admin
,
password admin123
, and show all matching GAV combinations on stdout.
% nexus-mass-deletion --version='3.2.1' --throttle=40 --delete \ com.mycorp.product1.batch \ com.mycorp.product1.frontend \ com.mycorp.product1.db
will issue the same request, and delete all artifacts (jars, test jars, source jars, poms, checksums, …) for the given group/ version combination. Processing will stop after 40 GAVs have been deleted (not counting packaging, extensions, and metadata).
% nexus-mass-deletion --keepLatest --throttle=40 --delete \ com.mycorp.product1.batch \ com.mycorp.product1.frontend \ com.mycorp.product1.db
will delete all versions except for the latest one. Processing will stop after 40 GAVs have been deleted (not counting packaging, extensions, and metadata).
If a mass deletion is operated on the same large number of groups, they can be kept in a file (each and every group on a separate line).
% cat product1-groups.txt com.mycorp.product1.batch com.mycorp.product1.frontend com.mycorp.product1.db % nexus-mass-deletion @product1-groups.txt (1)
-
Read groups from file
product1-groups.txt
, separated by newline.
When Nexus removes all artifacts for a GAV, it automatically rewrites Maven metadata in the GAV hierarchy above to indicate that this version is not available any more. This takes some time, and multiple mass deletions run in parallel will eventually synchronize in this step. Processing then takes longer than deleting in a random order, so groups are shuffled before processing to minimize parallel processing overhead.
Some actions are logged, such as the internal HTTP DELETE URL.
Logging happens on stderr which can easily be piped away using standard stderr
redirection such as 2>/dev/null
.
-
Re-run based on the REST search response if more artifacts are available
-
Make shuffle an option