how to deploy artifacts (jar files) from POM.xml into jFrog repository? - maven

I am new to this repository world.
I have a maven project i.e MavenExample from GitHub. and I have installed a jFrog artifactory in my machine.
My Aim is to deploy all the jar files listed in my pom.xml into jFrog artifactory instead of .m2 repo (default). This deployment of jar file must ocucur after mvn deploy command.
I have tried adding distributionManagement inside Pom.xml and changing the settings.xml inside maven/conf.
Can someone help... much appreciated.

Edited:
You can try editing "localRepository" in your settings.xml":
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--
REST OF THE CODE
-->
</settings>
Go to your project directory and launch "mvn deploy".

The easiest way to obtain this information is from the "Set Me Up" section of Artifactory. Select the repository in the Artifacts tab, and in the top right corner, click "Set Me Up". Assuming you are using a local repository for deploying (remote will not work for deploying, only for resolving dependencies), it will show a section for deploying which will include the distribution management section. Place this in the pom.xml file of the parent project and this running the mvn deploy command from this directory will deploy to Artifactory.
A great way to see a working example of this is to view the "maven-example" section in JFrog's public Github page . You can see the parent project has 3 sub-modules (multi1, multi2, and multi3). Adding the distribution management section mentioned previously to the parent pom.xml file and then running mvn deploy from the parent project's root directory will deploy all the binaries to Artifactory.
If for some reason this is still not working, please provide your pom.xml for the parent, the name, package type, and if it is a local/remote/virtual of the repository. Additionally, please provide any output of the mvn deploy command (with the -X option) and anything you can find in the artifactory.log and request.log files ($ARTIFACTORY_HOME/logs/artifactory.log and request.log)

Related

How to accept Gradle Build Scan ToS automatically in a Maven project?

I add the Build Scan in my Maven project. How can I configure the Maven extension of the build scan to accept the Gradle Terms of Service automatically?
To add the Maven build scan to the project, include the following extensions.xml file inside a directory called .mvn at the root of the Maven project:
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<version>1.11.1</version>
</extension>
</extensions>
Also add a file gradle-enterprise.xml inside the .mvn directory as follows:
<gradleEnterprise>
<buildScan>
<publish>ALWAYS</publish>
<termsOfService>
<url>https://gradle.com/terms-of-service</url>
<accept>true</accept>
</termsOfService>
</buildScan>
</gradleEnterprise>
Then, you can run the build and the Gradle ToS will be accepted automatically.
See the Gradle Enterprise Maven Extension User Manual for more details and configuratio parameters.

How to fix The POM for XXX:jar:1.0 is missing, no dependency information available

We tried to build our project(Spring Boot 2.0.3 with Maven 3.3.9 dependency management)Jenkins Tool(Linux environment).Its saying build failure showing the following message in console "The POM for org.actus:ACTUS-Core-1.0:jar:1.0 is missing, no dependency information available".ACTUS is our custom java library developed by us and its in the local repository also.
This is the first time we started using Jenkins Tool. There are some other modules which depends on this same ACTUS jar.Those are also failing.I have searched for solution on internet.Some people said,make changes to settings.xml file.But in our development machine ,we cant find any such type of settings.xml file(in .m2)
remaining all dependencies are normal spring boot dependencies only.This is the only one external or custom jar.Using mvn install, we kept in maven local repo.
<dependency>
<groupId>org.actus</groupId>
<artifactId>ACTUS-Core-1.0</artifactId>
<version>1.0</version>
</dependency>
I will try to explain as much I can to solve your problem. I hope you are looking for settings.xml to update your maven Nexus repository. If you don't know about nexus repository, it's kind of public repo where you will get all open source dependency.
In your case, from your organization, you should have a private nexus repository and upload ACTUS-Core jar to there.
Then update your settings.xml file to use your company nexus repository. (Please check comments, it will be available in M2_HOME location)
So while you execute mvn install automatically it will upload in your private repository.
Now, in your pom.xml mention the same nexus repository. (It's optional)
Then, in your Jenkins script, you have updated this nexus repo.
So, the key point is you should have your own repo to upload ACTUS-Core jar and need to access the same while you building in Jenkin tool.
OR ELSE
If you find all the above activities in pain / not possible then I can suggest a short cut solution.
Create a lib folder under your project name ( same hierarchy as src) then add your ACTUS-Core.jar and commit that file along with your source code.
Then, update your pom file like below. It will work.
<dependency>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>11.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/fileName.jar</systemPath>
</dependency>

How to move maven directory ".m2" from my home directory after installing IntelliJ

I've just installed IntelliJ 15 on Ubuntu and wanted to update maven repository indices, I am having disk space errors because my home folder is on a limited size partition.
I am totally lost trying to move ~/.m2 to somewhere else. I've tried IntelliJ settings and changed paths and maven settings but didn't work and most of the time they return to the home folder after restarting IntelliJ.
I wanted to add that I didn't install maven (using apt-get install maven). Would this help or give more control?
You can modify the location of the Maven local repository by modifying the Maven settings. From Configuring your Local Repository:
The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/.
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Note: The local repository must be an absolute path.
Since you are using the Maven installation that is shipped with IntelliJ and not your own Maven version, you can create a Maven user settings:
Create a file settings.xml under ${user.home}/.m2/
Have the following content in it:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/path/to/local/repo</localRepository>
</settings>
Maven will read this file and use the specified local repository.
Another alternative I found is also by eclipse itself.
Create the setting.xml file in my D:\TAAS\settings.xml directory as follows:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\TAAS\.m2\repository</localRepository>
</settings>
Then I configured it by the eclipse itself according to the following figure.
This is an option for maven embedded versions.

What is required to use maven for artifact deployment?

I am setting up a CI system with repository archive, based on apache Archiva. Among various techniques for deploying file there, the most promising one seems to be using maven (as opposed to REST api that would require too much curl calls and Web interface that is not for automation).
It seems that for deploying artifact, such as zip archives of build artifacts, in maven there is a following plugin: deploy:deploy-file. However an attempt to simply invoke that command gave me no results.
I did not work with maven before; currently our builds are done by invoking cmake on source directory, then make from shell script. What do i need to add and have to be able to use maven for deploying the resulting artefact?
Is it necessary to create a pom file? If so, what steps do i need to add?
You can use deploy:deploy-file to upload these artifacts, and by default it will generate a POM for you. What you will need is to:
install Maven
create a settings.xml file, with a <server> element that contains the credentials for deploying to Archiva over HTTP
There's a bit more information here: http://maven.apache.org/plugins/maven-deploy-plugin/usage.html. If you are generating the POM, then you will need to supply the groupId (distinct grouping of artifacts), artifactId (filename without version), version (artifact version), and packaging (typically extension, such as zip) parameters along with the required ones of repositoryId, url and file.
However, it's not required to use Maven, or the REST API - you can also just use a simple HTTP PUT call:
curl -T artifact.zip http://localhost:8080/archiva/repository/my-releases/group/artifact/version/artifact-version.zip
You may also use scp, ftp, etc. to place the file directly in the Archiva filesystem. Note that in that case, you'll have to wait for Archiva's scheduled scan to pick it up.
Maven needs a WebDAV like repository (see also Nexus, Artifactory) to deploy its artifacts (mostly jar, war, ear or assemblies.
Look here for a how to on setting up Maven with Archiva.
Yes, it is necessary to have pom.xml in maven and also it is obvious that you need maven to be installed on your machine. Bare minimum, you need to provide artifact ID(like name of jar), group id(like package to identify the location of artifact in repository) and version. By default package structure will be jar unless you mention it as war/ear/pom. If you want to use any dependencies you can mention them in dependencies section.
Following is the minimum pom that is required.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
</project>
Here is the quick tutorial to get acquainted with maven.

How can I deploy only the pom file to my snapshot repository in Maven?

I would like to be able to deploy only the POM artifact (file) without the main artifact (JAR, WAR, etc), when running mvn deploy and version is a SNAPSHOT version.
Why?
We several developers working on multiple Maven projects. We have a Hudson server with a job per Maven project and version (e.g. foo-1.2, foo-1.3). Each job builds the project and deploys it to a Nexus server (upon success). Maven projects under development are marked as such by using -SNAPSHOT postfix in the version. For example: 1.2-SNAPSHOT, 1.3-SNAPSHOT.
Here's a sample scenario how a developer work is damaged due to this architecture.
Assume two Maven projects: foo-core and foo-webapp, both at version 1.2-SNAPSHOT.
Developer A is working on foo-core, made several changes and compiled it.
Developer A continues to work, but on foo-webapp.
Developer B started working and changing foo-core. It commits his work and pushes it to the SCM.
Hudson is triggered by SCM; Builds foo-core and deploys it to the snapshot repository in Nexus.
Developer A is running mvn install on foo-webapp. Maven is checking with Nexus, and finds that there is a newer version of foo-core in Nexus. It downloads it (filled with developer B changes) and than it fails compilation, since the changes made by developer A are not in the jar located in the local repository. The download overrides the file installed there by developer A.
Existing Solutions
I looked into maven-deploy-plugin, but this plugin deploys all artifacts attached to the project. If they had a way to configure which artifacts to deploy, it would have been great.
Question: Is there any way to solve this without resorting to writing my own deploy plugin, based on maven-deploy-plugin?
Basically to the -Dfile parameter, instead of the artifact, pass the pom.xml. Run the command and yay! mvn deploy won't give you any issues now. Here's a sample deploy command :
$ mvn deploy:deploy-file -DpomFile=pom.xml -Dfile=./pom.xml -DgroupId=my.group.id -DartifactId=artifact-id -DrepositoryId=bigdata-upload-snapshots -Durl=http://maven.mymaven.com/content/repositories/snapshots/
A prerequisite for this is that the repository be added in your settings.xml
[Edit]: I have supplied the parameters -DgroupId and -DartifactId of the project in the sample deploy command but they're not required (refer to Zac's comment below)
I never heard of such a possibility and also would be very astonished if that would be possible. As the pom and the resulting artifact are some kind of unit it would make no scence (to me) to deploy only parts of them.
Nevertheless you should consider to make a separate pom project which specified dependencies and plugins you might want to use on your JAR/WAR projects like this:
<groupId>foo.bar</groupId>
<artifactId>my-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
and then inherit that pom project by your JAR/WAR projects like this:
<parent>
<groupId>foo.bar</groupId>
<artifactId>my-pom</artifactId>
<version>1.0.0</version>
</parent>
This is called project inheritance. You can change and deploy your pom project independent of the "child" artifacts.
EDIT after reading motivation:
As I understand you want to prevent maven to resolve SNAPSHOT artifacts from a repository (so that local version won't be overwritten). Have you ever tried to use the mvn -nsu option (see mvn -help)?
-nsu,--no-snapshot-updates Suppress SNAPSHOT updates
I never tried it but found this reported issue. Nevertheless I would give it a try (as the issue is not commented yet).
This works for me for deploying a pom file only (e.g next to an existing jar):
(Note: you need to specify packaging also, otherwise it will be uploaded as an .xml file which is not what you want.)
mvn deploy:deploy-file \
-Dfile=pom.xml \
-Dpackaging=pom \
-DgroupId=com.mycompany.package \
-DartifactId=my-artifact \
-Dversion=2.0.1 \
-DrepositoryId=serverIdFromSettingsXMLForCredentials \
-Durl=http://repositoryserver/myrepo/
Not exactly the answer these folks were asking for. My situation was I wanted to deploy only the parent pom. I'm using the spring-boot-thin-layout in a child module. This requires the parent module be deployed into artifactory. I added the following into my project. It enables skipping of install and/or deploy phase.
In my parent pom:
<properties>
<disable.install>true</disable.install>
<disable.deploy>true</disable.deploy>
<enable.deployAtEnd>true</enable.deployAtEnd>
</properties>
<profiles>
<profile>
<id>deploy-parent</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<disable.install>true</disable.install>
<disable.deploy>true</disable.deploy>
<deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>
<build>
<finalName>${project.version}</finalName>
</build>
</profile>
</profiles>
And the in my child pom(s) or any module you don't want deployed with parent:
<properties>
<maven.install.skip>${disable.install}</maven.install.skip>
<maven.deploy.skip>${disable.deploy}</maven.deploy.skip>
<deployAtEnd>${enable.deployAtEnd}</deployAtEnd>
</properties>
So effectively when I run mvn deploy on the parent pom, it will compile all the modules, not run install on anything, and then at the end deploy any module not having `

Resources