This repo contains scripts + explanation for sending .m2 local artifacts (pom & jar files) into SonaType nexus repository manager.
Note
Setup Used:
- Windows 10, 11
- Sonatype Nexus Repository Manager 3.55.0-01.
Important
If you're going to use this script on Windows, git bash is needed which is installed with git installer.
Extracting list of artifacts has been adopted1 and a custom argument path has been added to it.
- copy
extract-artifacts.sh&upload-artifacts.shscripts to~/.m2folder - run following command, would create
artifactsfile in current folder:
./"extract-artifacts.sh"example 1: This
./extract-artifacts.sh, will generate list of artifact files under~/.m2path
example 2:
./extract-artifacts.sh './repository/some/path/to/deploy/its/artifacts', will generate list of artifact files under./repository/some/path/to/deploy/its/artifactspath
- Supposing
maven-releasesrepository ofhostedtype has been already created in Nexus which is hosted athttp://nexus.example.com - fill
NEXUS_BASE_URL&NEXUS_REPOSITORY_IDvariables insideupload-artifacts.sh
Important
NEXUS_REPOSITORY_ID should be set as repositoryId which is set inside settings.xml for maven.
for following maven settings.xml file, NEXUS_REPOSITORY_ID value should be set equal to NEXUS-MAVEN-REPO-NAME
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
.
.
<profiles>
<profile>
<id>NEXUS-MAVEN-PROFILE-ID</id>
<repositories>
<repository>
<id>NEXUS-MAVEN-REPO-NAME</id>
<name>Nexus Repository</name>
<url>http://nexus.example.com/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
.
.
</repository>
</repositories>
.
.
</profile>
</profiles>
.
.
</settings>- running following command, all maven artifacts inside generated
artifactsfile, will be deployed to appropriate path in repository:
./"upload-artifacts.sh"- username and password with privileges to push to
maven-releasesrepository should be updated in correspondingsettings.xmlfile located at conf folder for maven
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
.
.
<servers>
<server>
<id>NEXUS-SERVER-ID</id>
<username>USERNAME</username>
<password>PASSWORD</password>
</server>
</servers>
.
.
</settings>- if deploying project artifact from
pom.xmlfile for corresponding project is wanted, add following section to itspom.xmlfile:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
.
.
.
<distributionManagement>
<repository>
<id>NEXUS-MAVEN-REPO-NAME</id>
<name>Nexus Repository</name>
<url>http://nexus.example.com/repository/maven-releases</url>
</repository>
</distributionManagement>
</project>then run following command on dir which contains pom.xml
mvn clean deploy
I needed to deploy local .m2 artifacts into nexus to speed up my work process, so I come up with this script. I wanted to deploy to maven-releases repository. You can make your changes for maven-snapshots repository.
Good luck!