Deploying site with Apache Maven SSH Wagon - apache

Introduction
I want that my Maven project(s) documentation (site) gets deployed at the docs folder of my website.
I'm using Apache Maven Wagon SSH at the moment to get the job done. The SSH connection works great, It pushes a zip file to the host and unpack's it.
I'm using fake names in these examples; provider.com, company.com and company
Problem
But the unpacking is placed in the wrong folder...
Instead it steps through the dirs; /domains/company.com/htdocs/docs/ and create these folders to put the documentation in: /${project.slug}/${project.artifactId}/${project.version}
It makes a new directory from the root: r.com/domains/company.com/htdocs/docs/${project.slug}/${project.artifactId}/${project.version}
Question
How can I manage the SSH/SCP to connect scp:ssh.provider.com, than walk through /domains/company.com/htdocs/docs/ directories and finally create the directories /${project.slug}/${project.artifactId}/${project.version} with the documentation inside?
Apendix. Files
Log
: scp:ssh.provider.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/docs/ - Session: Opened
[INFO] Pushing C:\Users\nberl\Code\company\company-maven-parent\target\site
[INFO] >>> to scp:ssh.provider.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/./
Executing command: mkdir -p "r.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/./"
Executing command: mkdir -p "r.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/."
Executing command: scp -t "r.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/./wagon4192311672559342478.zip"
Uploading: ./wagon4192311672559342478.zip to scp:ssh.provider.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/
##########
Transfer finished. 40802 bytes copied in 0.064 seconds
Executing command: cd "r.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/./"; unzip -q -o "wagon4192311672559342478.zip"; rm -f "wagon4192311672559342478.zip"
Executing command: chmod -Rf g+w,a+rX r.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/
scp:ssh.provider.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/ - Session: Disconnecting
scp:ssh.provider.com/domains/company.com/htdocs/docs/company/company-parent/1-SNAPSHOT/ - Session: Disconnected
POM configuration
The distribution management of the site:
<distributionManagement>
<site>
<id>company-docs</id>
<name>Company Docs</name>
<url>scp:ssh.provider.com/domains/company.com/htdocs/docs/${project.slug}/${project.artifactId}/${project.version}/docs</url>
</site>
</distributionManagement>
The site deploy profile:
<profile>
<id>deploy-site</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>site-deploy</id>
<phase>site</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Well after some research and a lot of just trying I found finally the solution!
In the distribution management sector you have to describe the absolute path from the absolute root of the server to the url.
Also you should use scp:// and end the domain with : (see the example below).
<distributionManagement>
<site>
<id>company-docs</id>
<name>Company Docs</name>
<url>scp://ssh.provider.com:/home/user/domains/company.com/htdocs/docs/${project.slug}/${project.artifactId}/${project.version}/docs</url>
</site>
</distributionManagement>
Now everything works like a charm!

Related

Cache node module library with plugin frontend-maven-plugin

I have a react project that I configured on Gitlab CICD Pipeline (with docker).
In my pipeline, I have a step for create the package that use frontend-maven-plugin plugin (Packaging)
Each time I run the pipeline all artifact are download. I want to use a cache in the pipeline but the configuration below doesn't work. I think that frontend-maven-plugin use a different location for cache.
How can I configure it ?
The pipeline Gitlab :
stages:
- build
- analyse
- package
- deploiement
cache:
paths:
- project_front/projectdir/node_modules/
variables:
MAVEN_CLI_OPTS: "-s ${MAVEN_PROJECT_SETTINGS} --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=${MAVEN_PROJECT_REPO}"
#
# Build de l'application
Build:
image: maven:3.5.2-jdk-8
stage: build
tags: [ 'project' ]
script:
# Récupération de la version du projet maven
- mvn $MAVEN_CLI_OPTS -U clean install -D maven.test.skip=true
#
# Step d'analyse SONAR
Qualimétrie:
image: maven:3.5.2-jdk-8
stage: analyse
tags: [ 'project' ]
script:
- mvn $MAVEN_CLI_OPTS -P sonarqubeproject,jacoco,nexus -U -D sonar.qualitygate.wait=true -D sonar.branch.name=$CI_COMMIT_BRANCH verify sonar:sonar
artifacts:
when: always
reports:
junit:
- "*/target/surefire-reports/TEST-*.xml"
#
# Génération du package de livraison
Packaging:
image: maven:3.5.2-jdk-8
stage: package
tags: [ 'project' ]
script:
# Packaging
- mvn $MAVEN_CLI_OPTS -P package_livraison -U package -Dmaven.test.skip=true -D HTTP_PROXY=${PROXY_SRV} -D HTTPS_PROXY=${PROXY_SRV}
artifacts:
paths:
- '**/target/*.tar.gz'
#
# Step de déploiement Ansible
Deploiement INT:
stage: deploiement
tags: [ 'project' ]
image: ansible/centos7-ansible
only:
- master
- develop
- feature-gitlab-cicd
when: manual
dependencies:
- Packaging
script:
#Installation de XMLLINT pour récupérer la version dans le POM
- yum -y install libxml2
# Récupération de la version du projet maven
- VERSION_PROJECT=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml`
# Execution du ssh-agent
- eval $(ssh-agent -s)
# Récupération de la clé privée de l'hote et envoi dans le container
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
# Création des répertoires
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# Recherche de l'hote
- ssh-keyscan myhost >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
# Envoi du package à la machine PROJECT
- cp project_deploiement/target/*.tar.gz /home/gitlab-runner/depot/
#Lancement du playbook
- ansible-playbook -v -i project_ansible/project-hosts project_ansible/ansible/project-install-playbook-int.yml -f 10 --extra-vars "project_version=${VERSION_PROJECT} -vvvv"
profile :
<profile>
<id>package_livraison</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
<workingDirectory>${frontend-src-dir}</workingDirectory>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
<executions>
<execution>
<id>install-frontend-tools</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
</execution>
<execution>
<id>yarn-install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<!-- Le proxy maven n'est pas utilisé, on le redéfinit-->
<yarnInheritsProxyConfigFromMaven>true</yarnInheritsProxyConfigFromMaven>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>build-frontend</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Properties :
<properties>
<frontend-src-dir>./projectdir</frontend-src-dir>
<node.version>v10.15.3</node.version>
<yarn.version>v1.15.2</yarn.version>
<frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>
</properties>
The directory Structure

Namenode not start after restart pc (hadoop 2.7.3)

i've configured hadoop 2.7.3 on ubuntu 16.04 and run all (word count and other mapReduce run all).
after restart pc, i launch start-dfs, but the namenode not started. other guide says remove temporay directory, but i don't have it.
that are my files:
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
Step 1: Create the folders like below:
-- sudo mkdir /dfs
-- sudo chown username:username /dfs/*
-- sudo chmod 755 /dfs/
-- cd /dfs
If the machine is name node then:
-- mkdir nn
if data node:
-- mkdir data
Step 2:
add below properties in hdfs-site.xml
<configuration>
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/dfs/nn</value>
</property>
</configuration>
<configuration>
<property>
<name>dfs.datanode.data.dir</name>
<value>/dfs/data</value>
</property>
</configuration>
</configuration>
step 3:
format the namenode: hadoop namenode -format
step 4:
start all services

Repeated password prompt with Maven deploy-file to scp repository

I'm trying to deploy an artifact to a remote repository accessible via scp and having a problem with repeated password prompts. My settings.xml contains this fragment:
<servers>
<server>
<id>example.com</id>
<username>myusername</username>
<password>mypassword</password>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration>
</configuration>
</server>
</servers>
The command line interaction looks like this:
$ mvn deploy:deploy-file -Dfile=ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.1.0 -DrepositoryId=example.com -Durl=scp://example.com/maven2/
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'deploy'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [deploy:deploy-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [deploy:deploy-file {execution: default-cli}]
Keyboard interactive required, supplied password is ignored
Password: : mypassword
Uploading: scp://example.com/maven2//com/oracle/ojdbc6/11.2.0.1.0/ojdbc6-11.2.0.1.0.jar
2061K uploaded (ojdbc6-11.2.0.1.0.jar)
[INFO] Retrieving previous metadata from example.com
Keyboard interactive required, supplied password is ignored
Password: : mypassword
[INFO] repository metadata for: 'artifact com.oracle:ojdbc6' could not be found on repository: example.com, so will be created
[INFO] Uploading repository metadata for: 'artifact com.oracle:ojdbc6'
Keyboard interactive required, supplied password is ignored
Password: : mypassword
[INFO] Uploading project information for ojdbc6 11.2.0.1.0
Keyboard interactive required, supplied password is ignored
Password: : mypassword
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30 seconds
[INFO] Finished at: Thu Sep 02 13:03:33 CEST 2010
[INFO] Final Memory: 5M/90M
[INFO] ------------------------------------------------------------------------
There are several problems here:
I'm prompted for a password even though it is is specified in the settings.xml
The password is echoed back on the console
It does not remember the password and instead asks me 4 times.
How can I configure maven so it either uses a password from settings.xml or asks me once without echoing my password to the screen?
Edit: This was on Ubuntu linux, a collegue just reproduced the same problem on Windows XP. As mounting the repository to a local path is not an option on Windows, I'm still looking for a solution.
I found the following on the maven-users list:
the sshd on the server used PasswordAuthentication no. After
switching to yes my maven config works fine.
Have you set either the repositoryId in your pom to use the correct server entry from the settings.xml, cause it looks like you don't set that so it uses the id: remote-repository. or did you changed the settings.xml accordingly.
As a workaround, I'm currently mounting the remote repository using sshfs and then using a file url in the maven command:
$ sudo adduser jh fuse
$ sudo mkdir -p /mnt/example.com/maven2
$ sudo chown -R jh:jh /mnt/example.com
$ sshfs username#example.com:/maven2 /mnt/example.com/maven2
$ mvn deploy:deploy-file -Dfile=ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.1.0 -Durl=file:///mnt/example.com/maven2/repository/
Configuring the server in settings.xml is not needed in this case, the repositoryId need not be specified on the command line and I can use shell autocompletion on the file url.
I would still be interested if anyone can reproduce the problem or suggest a solution using maven standards.
We have since installed Nexus as an repository manager and are using the web interface to upload third party jars.
I don't have an exact solution, but at least the following works:
Create a server entry in the file ~/.m2/settings.xml:
<server>
<id>example-dist</id>
<username>myusername</username>
<password>ignored</password>
</server>
Perform the deploy or deploy:deploy-file as follows:
mvn deploy -DrepositoryId=example-dist
You'll be asked for the password for the supplied username - the password in the settings.xml is ignored.
If you don't want to supply passwords each time, you can do so by generated a ssh key using ssh-keygen. The generated public key you'll have to store in the authorized_keys files at the distribution server (for a better explanation, see several tutorials on the web or the man page).
This bug seems related.
http://jira.codehaus.org/browse/WAGON-323
Im am getting the message "Keyboard interactive required, supplied password is ignored" - even with wagon-ssh-2.4.
Tried to set <interactiveMode>false</interactiveMode> but then auth fails right away.
As per #Gerbrand's response, you can skip providing user credentials with ssh keys. The steps are the following:
If you do not have one yet, generate a private/public key pair with ssh-keygen. Let's say you store the private key in /home/user/.ssh/id_rsa
Copy the public key to the destination server with ssh-copy-id -i /home/user/.ssh/id_rsa USER#serverhostname
Change your settings.xml to use your keys instead of password
<server>
<id>serverhostname</id>
<username>USER</username>
<privateKey>${user.home}/.ssh/id_rsa</privateKey>
<!-- Note there is no password tag specified -->
</server>
Next time you need to login to the server via Maven, no password will be requested.

Maven Glassfish Plugin: Deploy application as exploded directory/folder

I need my JavaEE-application to be deployed on Glassfish as a directory, not a packaged WAR file.
Is it possible to deploy a directory to Glassfish with the Maven Glassfish Plugin?
With the admin console, it's possible. But i want to be also able to do it on the command line.
The following configuration works for me (note that the artifact element points to a directory):
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.2-SNAPSHOT</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>${domain.username}</user>
<passwordFile>${glassfish.home}/domains/${project.artifactId}/master-password</passwordFile>
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>true</echo>
<skip>${test.int.skip}</skip>
<domain>
<name>${project.artifactId}</name>
<httpPort>8080</httpPort>
<adminPort>4848</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.build.finalName}</artifact>
</component>
</components>
</configuration>
</plugin>
The resulting asadmin command is:
asadmin --host localhost --port 4848 --user admin --passwordfile /home/pascal/opt
/glassfishv3/glassfish/domains/maven-glassfish-testcase/master-password --interac
tive=false --echo=true --terse=true deploy --name maven-glassfish-testcase --forc
e=false --precompilejsp=false --verify=false --enabled=true --generatermistubs=fa
lse --availabilityenabled=false --keepreposdir=false --keepfailedstubs=false --lo
gReportedErrors=true --upload=false --help=false /home/pascal/Projects/stackoverf
low/maven-glassfish-testcase/target/maven-glassfish-testcase
I did not get it to work with the maven plugin, but it is possible to deploy to glassfish from the command line using the asadmin command from the glassfish/bin directory:
asadmin deploy --contextroot context_root path_to_ear_or_directory

How can I download a specific Maven artifact in one command line?

I can install an artifact by install:install-file,
but how can I download an artifact?
For example:
mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST
You could use the maven dependency plugin which has a nice dependency:get goal since version 2.1. No need for a pom, everything happens on the command line.
To make sure to find the dependency:get goal, you need to explicitly tell maven to use the version 2.1, i.e. you need to use the fully qualified name of the plugin, including the version:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=url \
-Dartifact=groupId:artifactId:version
UPDATE: With older versions of Maven (prior to 2.1), it is possible to run dependency:get normally (without using the fully qualified name and version) by forcing your copy of maven to use a given version of a plugin.
This can be done as follows:
1. Add the following line within the <settings> element of your ~/.m2/settings.xml file:
<usePluginRegistry>true</usePluginRegistry>
2. Add the file ~/.m2/plugin-registry.xml with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<pluginRegistry xsi:schemaLocation="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0 http://maven.apache.org/xsd/plugin-registry-1.0.0.xsd"
xmlns="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<useVersion>2.1</useVersion>
<rejectedVersions/>
</plugin>
</plugins>
</pluginRegistry>
But this doesn't seem to work anymore with maven 2.1/2.2. Actually, according to the Introduction to the Plugin Registry, features of the plugin-registry.xml have been redesigned (for portability) and the plugin registry is currently in a semi-dormant state within Maven 2. So I think we have to use the long name for now (when using the plugin without a pom, which is the idea behind dependency:get).
With the latest version (2.8) of the Maven Dependency Plugin, downloading an artifact from the Maven Central Repository is as simple as:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=groupId:artifactId:version[:packaging[:classifier]]
where groupId:artifactId:version, etc. are the Maven coordinates
An example, tested with Maven 2.0.9, Maven 2.2.1, and Maven 3.0.4:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=org.hibernate:hibernate-entitymanager:3.4.0.GA:jar:sources
(Thanks to Pascal Thivent for providing his wonderful answer in the first place. I am adding another answer, because it wouldn't fit in a comment and it would be too extensive for an edit.)
Here's what worked for me to download the latest version of an artifact called "component.jar" with Maven 3.1.1 in the end (other suggestions did not, mostly due to maven version changes I believe)
This actually downloads the file and copies it into the local working directory
From bash:
mvn dependency:get \
-DrepoUrl=http://.../ \
-Dartifact=com.foo.something:component:LATEST:jar \
-Dtransitive=false \
-Ddest=component.jar \
Regarding how to get the artifact binary, Pascal Thivent's answer is it, but to also get the artifact sources jar, we can use:
mvn dependency:get -Dartifact=groupId:artifactId:version:jar:sources
e.g.
mvn dependency:get -Dartifact=junit:junit:4.12:jar:sources
This works because the artifact parameter actually consists of groupId:artifactId:version[:packaging][:classifier]. Just the packaging and classifier are optional.
With jar as packaging and sources as classifier, the maven dependency plugin understands we're asking for the sources jar, not the artifact jar.
Unfortunately for now sources jar files cannot be downloaded transitively, which does make sense, but ideally I do believe it can also respect the option downloadSources just like the maven eclipse plugin does.
One could use dependency:copy (http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html) which takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in either the local repository or the reactor.
Not all the properties of the plugin could be used in maven CLI. The properties which have "User Property:" property defined could be specified. In the below example I am downloading junit to my temp folder and stripping the vesion from the jar file.
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=junit:junit:4.11 -DoutputDirectory=/tmp -Dmdep.stripVersion=true
where
artifact=junit:junit:4.11 is the maven coordinates. And you specify artifcat as groupId:artifactId:version[:packaging[:classifier]]
(Thanks to Pascal Thivent for providing his https://stackoverflow.com/a/18632876/2509415 in the first place. I am adding another answer)
The usage from the official documentation:
https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#dependency:get
For my case, see the answer below:
mvn dependency:get -Dartifact=$2:$3:$4:$5 -DremoteRepositories=$1 -Dtransitive=false
mvn dependency:copy -Dartifact=$2:$3:$4:$5 -DremoteRepositories=$1 -Dtransitive=false -DoutputDirectory=$6
#mvn dependency:get -Dartifact=com.huya.mtp:hynswup:1.0.88-SNAPSHOT:jar -DremoteRepositories=http://nexus.google.com:8081/repository/maven-snapshots/ -Dtransitive=false
#mvn dependency:copy -Dartifact=com.huya.mtp:hynswup:1.0.88-SNAPSHOT:jar -DremoteRepositories=http://nexus.google.com:8081/repository/maven-snapshots/ -Dtransitive=false -DoutputDirectory=.
Use the command mvn dependency:get to download the specific artifact and use
the command mvn dependency:copy to copy the downloaded artifact to the destination directory -DoutputDirectory.
one liner to download latest maven artifact without mvn:
curl -O -J -L "https://repository.sonatype.org/service/local/artifact/maven/content?r=central-proxy&g=io.staticcdn.sdk&a=staticcdn-sdk-standalone-optimizer&e=zip&v=LATEST"
maven command:
if you use maven, you can use dependency:copy to download the artifact to the local folder.
mvn dependency:copy -Dartifact=groupId:artifactId:version[:packaging[:classifier]] -DoutputDirectory=<your local path>. -U
Refer: https://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html
Curl command:
# guide: https://help.sonatype.com/repomanager3/rest-and-integration-api/search-api
# https://msnexus.xxxx.com/service/rest/v1/search/assets?sort=version&repository=public&maven.groupId=<groupId>&maven.artifactId=<>&maven.baseVersion=1.46.0-SNAPSHOT&maven.extension=war
download_artifact() {
local host_url=$1
local group_id=$2
local artifact_id=$3
local artifact_type=$4
local artifact_version=$5
local final_name=$6
local location=$7
local search_version=$5
local prerelease="false"
if [[ "${artifact_version}" == *"SNAPSHOT" ]]; then
prerelease="true"
fi
if [[ "${artifact_version}" == "latest"* ]]; then
search_version="*"
fi
assets_url="${host_url}/service/rest/v1/search/assets?sort=version&repository=public&maven.groupId=${group_id}&maven.artifactId=${artifact_id}&maven.baseVersion=${search_version}&prerelease=${prerelease}&maven.extension=${artifact_type}"
echo "INFO: Assets url: $assets_url"
download_url=$(curl "$assets_url" -H "accept: application/json" | jq -r ".items[0].downloadUrl // empty")
echo "INFO: Downloading artifact from url: $download_url"
if [[ -z "$download_url" ]]; then
echo "ERROR: Artifact not exists in Nexus, please check your version [${version}] for [${service_name}]"
exit 1
fi
pre_dir=$(pwd)
if [[ ! -d "$location" ]]; then
mkdir -p $location
fi
cd $location
curl -o "${final_name}.${artifact_type}" "$download_url"
cd $pre_dir
}
Here's an example to get ASM-7 using Maven 3.6:
mvn dependency:get -DremoteRepositories=maven.apache.org -Dartifact=org.ow2.asm:7.0:sources:jar
Or you can download the jar from here: https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm and then
mvn install:install-file -DgroupId=org.ow2.asm -DartifactId=asm -Dversion=7.0 -Dclassifier=sources -Dpackaging=jar -Dfile=/path/to/asm-7.0.jar
To copy artifact in specified location use copy instead of get.
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:copy \
-DrepoUrl=someRepositoryUrl \
-Dartifact="com.acme:foo:RELEASE:jar" -Dmdep.stripVersion -DoutputDirectory=/tmp/
You can also do this using docker in PowerShell:
docker run -it --rm -v ${PWD}:/build/source -v ${HOME}/.m2:/build/.m2 --net=host aemdesign/centos-java-buildpack:jdk8 /bin/bash --login -c 'mvn dependency:get -Dmaven.repo.local=/build/.m2/repository -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact=io.prometheus.jmx:jmx_prometheus_javaagent:LATEST -Ddest=/build/source/jmx_prometheus_javaagent.jar'
or in bash:
docker run -it --rm -v $PWD:/build/source -v $HOME/.m2:/build/.m2 --net=host aemdesign/centos-java-buildpack:jdk8 /bin/bash --login -c 'mvn dependency:get -Dmaven.repo.local=/build/.m2/repository -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact=io.prometheus.jmx:jmx_prometheus_javaagent:LATEST -Ddest=/build/source/jmx_prometheus_javaagent.jar'
The command:
mvn install:install-file
Typically installs the artifact in your local repository, so you shouldn't need to download it. However, if you want to share your artifact with others, you will need to deploy the artifact to a central repository see the deploy plugin for more details.
Additionally adding a dependency to your POM will automatically fetch any third-party artifacts you need when you build your project. I.e. This will download the artifact from the central repository.
LATEST is deprecated, try with range [,)
./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \
-DremoteRepositories=repoId::default::https://nexus/repository/maven-releases/ \
"-Dartifact=com.acme:foo:[,)"
Unfortunately maven-dependency-plugin:get do NOT support version ranges e.g. [2.17.1,) or [,)
If you need download a specific maven artifact but using version range, as I do, look here:
Download Maven artifact with version range