I have a local repository which I have been installing jars to for a while from different projects. We also have a nexus server running, but it does not have all the jars that I have locally.
I can try to synchronize jars up to nexus one by one. But is there a more efficient way to synchronize up to nexus? Ideally I would want to execute a single command which would look through all the artifacts in my local repo, and push anything which is missing in nexus.
If a cmd script is the only way, it would be very useful with specific tips around this as well.
I might give an update on my progress so far
echo off
echo MavenSync
setlocal EnableDelayedExpansion
for /R . %%f in (*) do (
set jarfile=%%~dpnxf
set name=%%~dpnf
set pomFile=!name!.pom
set clientJar=!name!-client.jar
if [!jarfile:~-4!]==[.jar] (
echo !jarfile!
echo !pomFile!
set repo=http://server/nexus/content/repositories/releases/
if [!jarfile:~-10!]==[client.jar] (
rem Handled elsewhere
) else (
if [!jarfile:~-12!]==[SNAPSHOT.jar] (
set repo=http://server/nexus/content/repositories/snapshots/
)
if EXIST !clientJar! (
echo mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=nexus -Durl=!repo! -DpomFile="!pomFile!" -Dfile="!jarfile!" -Dfiles="!clientJar!" -Dtypes=client-jar -Dclassifiers=bin
) else (
echo mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=nexus -Durl=!repo! -DpomFile="!pomFile!" -Dfile="!jarfile!"
)
)
)
)
There is no means of doing this easily without writing a custom script. However, if you have a build which build everything and installs it locally via
mvn installthen you can deploy it to your nexus by doingmvn deploy. For this to work you need to add a section to your pom fordistributionManagement:This will just deploy the latest version of each project however, and not the back history of the older versions.
Depending on the version of nexus that you are using it may be possible to copy the contents of your file system. Nexus 2 uses file system based storage, so you could potentially compare your .m2 repo with the remote one and copy over the different projects as required. Once the necessary changes were copied across, a reindex of the remote repo should pick up the changes you made. Nexus 3 stores the artefacts in a database however, so if you are using that version this wouldn't be possible.