I have more than 1 settings.xml file and I want to specify the 1 I want to use when I run > mvn from the command line, because running mvn help:effective-settings is showing 1 file but it seems that is using the other one
Use:
mvn --settings settingsYouWant.xml clean install
If you add the argument -X to your maven command (debug) you can see which one is picking.
Related
I have corporate Jenkins where I don't have access to Manage Jenkins option. I want to make a build of my java app using maven.
When I try to run mvn clean install:
dir("test/test2/project") {
sh "mvn clean install -Dmaven.test.skip=true"
}
I get the following error:
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/var/jenkins/workspace/test/test2/project). Please verify you invoked Maven from the correct directory.
I was trying to add mvn -f /var/jenkins/workspace/test/test2/project/pom.xml (I have pom file in the folder) but it did not work.
I also tried
withEnv(["PATH+MAVEN=${tool 'maven-3.5.0'}/bin:${env.JAVA_HOME}/bin"]) {
sh "mvn --batch-mode -V -U -e clean install -Dmaven.test.skip=true"
which also did not work.
I would like to point to maven and java which are installed on the agent but can't seem to sucseed.
Any idea?
Can you try something like below?
dir("test/test2/project") {
sh "mvn clean install"
}
I've been searching the web and StackOverflow for a solution. Problem is that Jenkins will not invoke mvn from the the build step. In my build step, I'm using Invoke top-level Maven targets. From the command line mvn clean install runs just fine from the directory where the POM file is located. So I believe Maven is installed correctly.
From the console I see:
[XXXX] $ cmd.exe /C "mvn -f C:\Users\XXX\XXX\XXX\pom.xml clean install && exit %%ERRORLEVEL%%"
Error message is:
'mvn' is not recognized as an internal or external command, operable program or batch file.
What I have tried:
change the settings file option to point too the settings.xml in the Maven install folder
change the global setting file option to point too the settings.xml in the Maven install folder
I've set the MAVEN_HOME environment variable in Jenkins Configure System
What I expect to happen:
Maven to build my project from the build step.
I just removed pom.xml file from the path.. it's worked ..
So try the below option
I am using maven verison 3.3.9 on linux-version: "4.4.0-43-generic". For somehow i can run the maven command using this way on console:
mvn -pl '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed' -P compileWithGradle,nightly,flex-debug clear
double quotes inside the single quote i dont know the reason but it is working this way on console. I have a jenkins pipline in which i want to use this command but it is not working eiter i use:
sh ''' mvn -pl '"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed"' -P compileWithGradle,nightly,flex-debug clear '''
OR use :
sh """ mvn -pl '"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed"' -P compileWithGradle,nightly,flex-debug clear """
result will be given in a "!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" OR '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed'
Can someone tell me a proper way to use in jenkins script or inside a maven goal.
You can use
sh 'mvn -pl "!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" -P compileWithGradle,nightly,flex-debug clear'
It should work.
If bash shell is used you have to escape !. with a backslash \. This works.
mvn -pl \!com.mycom.hp.comp:zonegtools
Ah , but this is not working in Jenkins groovy code.(2 backslashes)
sh "mvn -pl \\!com.mycom.hp.comp:zonegtools"
This does not work in jenkins+ groovy + maven
MVN error: Could not find the selected project in the reactor: !com.mycom.hp.comp:zonegtools
I can run mvn command in the groovy file like this. Could you try this?
run('mvn install:install-file -Dhttps.protocols=TLSv1.2 -DgroupId=com.sample-DartifactId=sample -Dversion=2.1.0 -Dpackaging=jar -Dfile=src/main/lib/sample-2.1.0.jar -DgeneratePom=true -Dmaven.test.skip=true')
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.
I have a Maven build job in Jenkins and in the "Build" section, I have given Maven Version and Root POM and in the "Goals and Options" filed, I am executing the pom with customized goals. I need to write the output of the execution to a file, I tried below
clean install -Dmaven.test.skip=true -nsu -l output.log
clean install -Dmaven.test.skip=true -nsu -DoutputFile=output.log
clean install -Dmaven.test.skip=true -nsu -Doutput=output.log
Nothing works for me. Could anyone please help in either the above way or any other option available to direct the output log to a file?
According to mvn -help, the following works for me:
clean install -l output.log
The file is stored to the job workspace, if you want to publish it as an artifact, you need to add a Publish artifact or Publish document post-step (or Publish document post-build option in Maven project).