1

I want to update maven-metadata.xml file in my nexus server programmatically. Is there any way I can do this? Can I use eclipse aether API for this?

carlspring
  • 31,231
  • 29
  • 115
  • 197
ѕтƒ
  • 3,547
  • 10
  • 47
  • 78
  • 2
    Why do you like to do that? Checked in Nexus to recreate the metadata task? – khmarbaise Feb 03 '15 at 09:48
  • Won't nexus just overwrite the metadata the next time the task runs? – Software Engineer Feb 03 '15 at 09:56
  • 1
    When I deleted a version of an artifact from nexus repository, the metadata file is not get updated. The deleted version is the latest version in maven-metadata.xml file. I tried "Rebuild metadata" option. But it doesn't worked. – ѕтƒ Feb 03 '15 at 10:33
  • Which version of Nexus do you use? Do you get any error message in the log file of Nexus? – khmarbaise Feb 03 '15 at 11:52

3 Answers3

2

The maven metadata files are maintained by Maven. Nexus updates them on deletion and has a scheduled task that can correct the files as well.

However depending on the way you delete the files, the metadata might not get updated. E.g. if you just delete the files in the storage and dont use the Nexus application.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
0

Use a Nexus restAPI call to have Nexus rebuild metadata after a deploy, a DELETE request to /service/local/metadata/repositories/<repo-id>/content.

For example:

curl -v -u userID:password -X DELETE http://localhost:8081/nexus/service/local/metadata/repositories/snapshots/content/com/foo/some/artifact
Das_Geek
  • 2,775
  • 7
  • 20
  • 26
0

I know this is an old question, but I stumbled onto this with the same problem and thought I'd share my solution for the next person in my shoes. 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. Nexus has a 'Repair - Rebuild Maven repository metadata' task which will do what you want. Unfortunately there is no REST API to create tasks, only to list and run. I monitored network traffic while creating this task in the web UI and came up with this solution 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.