Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force sonatype nexus 3 to recreate maven-metadata.xml for maven repository?

Tags:

maven

sbt

nexus

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:

  • NOT WORKING: using the nexus interface --> repositories --> my-maven-repo --> rebuild index
  • NOT WORKING: 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 )
  • WORKING : deleting another artefact in the same repository. But this is not really a nice solution; I don't want to start deleting artefacts AND this would require admin privileges.

NOTES:

  • tested with different sbt versions, this does not seem to be an sbt issue; see related question
  • nexus version 3.4.0-02
  • using the BETA API I can find the new versions (curl -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.

like image 812
Chris Maes Avatar asked Aug 14 '18 08:08

Chris Maes


People also ask

How is Maven metadata XML created?

The file at https://repo1.maven.org/maven2/com/octopus/randomquotes/maven-metadata.xml is created when a Maven artifact is published. It lists various details about the artifacts that have been published, like version number and the dates when the artifact was last updated.


1 Answers

I found a workaround using the new API present in nexus repository manager-3.13:

  • (using the web interface): create a new task to recreate ALL hosted maven repositories (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 task
  • curl -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.xml

Downsides:

  • need of administrator privileges
  • need of an additional step after sbt publish to make sure maven-metadata.xml is up to date
like image 149
Chris Maes Avatar answered Nov 15 '22 05:11

Chris Maes