Error: POM not present while using mvn deploy command - maven

I am using below mentioned command to send jar from my local workspace to Artifcatory in maven repo. I am not using pom.xml to do so. I have configured setting.xml with credentials for Artifactory.
mvn deploy:deploy-file -Durl=https://myartifactory.fkc.com/maven-prereleases
-DrepositoryId= arti-mavenpre -Dfile=trial.zip -DgroupId=com/org/mydir
-DartifactId=test -Dversion=1.0 -Dpackaging=zip
I get following error while executing above command:
[ERROR] The goal you specified requires a project to execute but there is no
POM in this directory (C:\Users\raji\script). Please verify you invoked Maven
from the correct directory. -> [Help 1]
What am I doing wrong? I don't want to use pom.xml file. How to make it work without pom?
Thank you.

So this was the error. I am using powershell to execute maven command and it requires double quotes for execution. After using double quotes, its working fine.
C:\apache-maven-3.3.9\bin\mvn -s "C:\Users\my-user.m2\settings.xml" -Dversion="$(Build.BuildNumber)" -Durl="https://my-artifactory.ayz.com/maven-prereleases" -DgroupId="com.mycomp.mydir" -Dfile="C:\agent_work\1\a_PublishedWebsites\test_$(Build.BuildNumber).zip" -Dpackaging="zip" -DrepositoryId="my-artifac
tory" -DgeneratePom=true -DartifactId="test" -B deploy:deploy-file

The problem of your script is the empty space -DrepositoryId= arti-mavenpre between the repositoryId and the value. I had a similar problem and that fixed it.

Related

Maven Local file installation

I am trying to install a local jar file to be used as a dependency using the following command
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=<path-to-file>
Getting the following result
The goal you specified requires a project to execute but there is no POM in this directory
To install the file in the local maven repository, you have to provide also the group ID, artifact ID, and the version for that file. Without them, Maven does not know in what directory to store the file.
See also: https://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html.
Maven need the so called GAV coordinates: groupId, artifactId, version and packaging to store the artefact.
You can name them wiht the install command
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file
-Dfile=<path-to-file>
-Dpackaging=jar
-DgeneratePom=true
-DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version>

Maven - jenkins pipeline not using pom

I have a problem running a maven deploy through Jenkins. When run locally, the correct URL is contacted, but via Jenkins(in the middle of a pipeline), it does not. It also states that it is using a different plugin to do so. How do I get Jenkins to contact MY_URL like my command line does?
(I've cleaned up the output a bit)
Running the following through the command line gives me:
mvn clean deploy -DaltDeploymentRepository=nexus::default::https://MY_URL/ -DskipTests -P nexus -X -s ./settings.xml
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MY_PROJECT: Failed to deploy artifacts: Could not transfer artifact from/to nexus (https://MY_URL): Failed to transfer file 20200217.092316-15.jar with status code 401 -> [Help 1]
This is what I want (I'm waiting on credentials - but it is hitting the correct URL)
Running via Jenkins gives me:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy (default-deploy) on project : Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
I have done a "diff" on the pom files in use by jenkins and locally and they are identical; likewise with the settings.xml I suspect this is a plugin problem but do not know where to go with it.
Items I have tried:
mvn clean beforehand
reinstalling mvn
echoing the settings.xml and pom.xml into the jenkins output
Specifying altDeploymentRepository in the settings.xml and/or
commandline
Specifying altDeploymentRepository using the -Dproperties= flag
Combinations of altDeploymentRepository, altDeploymentDirectory,
altSnapshotDeploymentRepository
Endless research
Hopeful reruns
Banging head on desk
Your Jenkins runs the org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy goal.
It is either specified in the POM or given on command line. So first of all, check whether the nexus-staging-maven-plugin is configured in your POM or in one of the parent POMs. If so, check if it run conditionally or is part of a profile.
Secondly, look at the command line call in Jenkins and see if it is exactly the same as the one you ran locally.
The third possibility is that you run a Jenkins plugin from Sonatype that implicitly tries to deploy artifacts. So watch out for Sonatype specific Jenkins plugins.
One of the three strategies should lead to the source of the problem.

maven: local installed jar not found

I'm getting this error message:
Could not resolve dependencies for project com.psgd.template:backend:war:1.0.0: Could not find artifact com.oracle:ojdbc7:jar:12.1.0.2
I've previously installed this library into local repository using:
mvn install:install-file \
-DgroupId=com.oracle \
-DartifactId=ojdbc7 \
-Dversion=12.1.0.2 \
-Dpackaging=jar \
-Dfile=ojdbc7-12.1.0.2.jar \
-DgeneratePom=true
I've look up into my repository:
$ ls -Rh ~/.m2/repository/com/oracle/
/home/jeusdi/.m2/repository/com/oracle/:
ojdbc7
/home/jeusdi/.m2/repository/com/oracle/ojdbc7:
12.1.0.2
/home/jeusdi/.m2/repository/com/oracle/ojdbc7/12.1.0.2:
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
So, it's present into local repository.
Any ideas?
Many things can go wrong here.
When you run mvn install:install-file you should see the log line in command line: something like : INFO Installing file ... to full <<PATH_COMES_HERE>>
So check that path.
If everything works as expected you should be able to see both pom.xml and the jar in the corresponding folder of your repository, not "lastUpdated" I believe.
I don't see it in the provided snippet...
You can also check permissions as one possible source of issues.
The last thing is checking the actual pom generated by install:install-file. Make sure, the pom is valid and contains the information you've entered.
You can also delete the whole folder from maven repo and re-run mvn install:install-file maybe the repo went corrupted for some reason who knows.
The files
ojdbc7-12.1.0.2.jar.lastUpdated ojdbc7-12.1.0.2.pom.lastUpdated
mean that the Maven looked for the pom and did not find it. It is a kind of cache for missing artifacts.
Please delete these two files and try again to install the jar. Then try again to build against it.

MAVEN: This project has been banned from the build due to previous failures

I am trying to add Oracle JDBC driver in Maven local repository using following command
mvn install:install-file -Dfile=C:\Users\Meharaj Fareedy\Downloads\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
But getting .
Remove space from your "Meharaj Fareedy" directory Or pass path in quotes
like -
without space
mvn install:install-file -Dfile=C:\Users\MeharajFareedy\Downloads\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
With quotes
mvn install:install-file -Dfile="C:\Users\MeharajFareedy\Downloads\ojdbc6.jar" -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
Then it would work
Use a quotes for the filename
mvn install:install-file -Dfile="C:\Users\Meharaj Fareedy\Downloads\ojdbc6.jar" -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
Please fix the previous failures means project is depends on the other module or other something which has errors.
You may get the idea by running command one by one don't mix two or more together to execute.
You will get your solution.
If you have used wrong formatted options in Options field in maven task of pipeline or passed optional arguments through Command Prompt for executing maven task. Then you will get above error. You need to check the correct syntax for the options you are passing to maven as per maven version.
NOTE: Different maven version have slightly different syntax. Please look below highlighted fields in screenshots.
ADO PIPELINE:
THROUGH CMD:

maven error: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT)

I am trying to create php project using maven by tying below command:
sudo mvn archetype:generate -DarchetypeGroupId=org.phpmaven
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0-SNAPSHOT
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
but it gives me error:
Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli)
on project standalone-pom: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT) -> [Help 1]
Apparently you're trying to follow these instructions. If you do, you should also do the preparation steps that have been listed.
Doing that you're relying on a snapshot archetype, and those do not exist in default repositories, so you have to configure php-maven snapshot repository.
After doing that,
Confirm your settings.xml location (in the comments you indicated you had that in the wrong folder)
try with
mvn archetype:generate -DarchetypeGroupId=org.phpmaven.sites
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0.0-beta-1
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
Since you can see from the repo that that archetype version should be in place. Note the different archetypeversion and different archetypegroupid!

Resources