Reputation: 37722
I use sbt
to publish new artifacts to a nexus-maven2 repository (my-maven-repo). The new artefacts appear in the nexus interface. Another sbt project uses these artefacts. When using exact requirements; he finds those, but when using a range; he fetches the list of available artifacts and that list is never up to date.
Methods / workarounds I have tried and their result:
curl -v -u user:pass -X DELETE http://my-server/nexus/service/local/metadata/repositories/my-maven-repo/content
(error: Http method DELETE is not supported by this URL )NOTES:
sbt
versions, this does not seem to be an sbt
issue; see related questioncurl -X GET --header 'Accept: application/json' 'http://my-server/nexus/service/siesta/rest/beta/search?repository=my-maven-repo&name=mylib_2.12&version=2.4.0'
); but sbt
still does not find them when not specifying the exact version number.EDIT:
The incomplete list can be obtained using wget http://my-server/nexus/repository/my-maven-repo/org/company/mylib_2.12/maven-metadata.xml
EDIT2 upgrading to nexus-3.13 did not solve the problem.
Upvotes: 8
Views: 11686
Reputation: 27
I know this is an old question, but I stumbled onto this with the same problem and thought I'd share my solution. We have an application where we upload artifacts to a Nexus repository using the REST API, and this does not create the proper maven-metadata.xml files. For example, for com/test/artifact version 2.0.0, it creates com/test/artifact/2.0.0/maven-metadata.xml but not com/test/artifact/maven-metadata.xml. gschizas' answer above was helpful in finding a solution, but his answer is for the rebuildIndex task, which is not the one you want. You need the 'Repair - Rebuild Maven repository metadata' task. Unfortunately there is no REST API to create tasks, only to list and run. I too monitored network traffic while creating this task. Here's a solution which is working for me in the form of a bash snippet:
# create the task
response=$(curl \
--silent \
--fail \
--user $NEXUS_USERNAME:$NEXUS_PASSWORD \
--header "Content-Type: application/json" \
--data '{"action":"coreui_Task","method":"create","data":[{"id":"NX.coreui.model.Task-1","typeId":"repository.maven.rebuild-metadata","enabled":true,"name":"rebuild maven metadata","alertEmail":"","notificationCondition":"FAILURE","schedule":"manual","properties":{"repositoryName":"maven-hosted","groupId":"","artifactId":"","baseVersion":"","rebuildChecksums":"false"},"recurringDays":[],"startDate":null,"timeZoneOffset":"+00:00"}],"type":"rpc","tid":0}' \
http://$NEXUS_SERVER/service/extdirect)
if [ $? -eq 0 ]; then
taskid=$(echo $response | jq -r .result.data.id)
if [[ "$taskid" != "null" ]]; then
# run the task
curl \
--silent \
--user $NEXUS_USERNAME:$NEXUS_PASSWORD \
--header 'accept: application/json' \
--header "Content-Type: application/json" \
--request 'POST' \
--data '' \
http://$NEXUS_SERVER/service/rest/v1/tasks/${taskid}/run
fi
fi
We're using Nexus OSS 3.41.
Upvotes: 1
Reputation: 90
I cheated by monitoring network traffic, and I ended up with the following:
curl \
--silent \
--user $NEXUS_USERNAME:$NEXUS_PASSWORD \
--header "Content-Type: application/json" \
--data '{"action":"coreui_Repository","method":"rebuildIndex","data":[$NEXUS_REPOSITORY],"type":"rpc","tid":0}' \
http://$NEXUS_SERVER/service/extdirect
This does work for me. Even though "tid" is supposed to be some auto-incrementing number, but it does not seem to matter.
Upvotes: 0
Reputation: 37722
I found a workaround using the new API present in nexus repository manager-3.13:
Repair - Rebuild Maven repository metadata (maven-metadata.xml)
)curl -v -u user:pass -X GET http://my-server/nexus/service/rest/v1/tasks
to get the id of this taskcurl -v -u user:pass -X POST http://my-server/nexus/service/rest/v1/tasks/c42ab5f5-4bd6-4ed3-b2f1-d061c24a9b90/run
to trigger the recreation of all maven-metadata.xmlDownsides:
sbt publish
to make sure maven-metadata.xml is up to dateUpvotes: 9