I want to know what exactly Maven do in the -U phase.
The argument ordering forced check for updates on remote repositories and if needed, updating the local maven repository with the updated dependencies used in our project.
As described:
-U --update-snapshots Forces a check for updated releases and snapshots on remote repositories
But, how exactly is this done? Is maven first of all downloading all the remote repositories and locally decides that they need to get updated, or, deciding without downloading them first? Is there some corner cases that should be known?
My Maven version is:
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T16:51:42+03:00)
Maven home: /usr/local/Cellar/maven/3.2.2/libexec
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"
It is done only for the artifacts or dependencies referenced by your project.
The last check timestamp is stored within local artifact metadata (in your local Maven repository), so Maven can apply different strategies how often to check for updates based on that. The default update interval for snapshots is "daily".
Also see updatePolicy for remote repositories in Maven's settings.xml.
Related
I was testing the move from a Jenkins docker image to another using Thinbacvkup and restore the backup and restore went well and of course it didn't bring maven with it (No problem there) I went online and got the latest apache maven bin file (apache-maven-3.8.4-bin), extracted and set up the global tool configuration, export M2_HOME ...ETC. BUT for some reason, it didn't work giving me the same message
#tmp/durable-e665ee46/script.sh: 1: mvn: not found
searched and searched nothing worked, so I went to the original docker and got the same maven from there (apache-maven-3.5.3-bin)edited the configs and all, and it worked but now I wanted to know why did this work and that won't is there something with my project, build or what?
Not using a Docker image, but had no problem on a clean install, no plugins,
Global Tool Configuration ( /configureTools/ ), add maven configuration:
Create job with Invoke top-level maven step, choose same maven version:
If a pipeline job, then the reference would be tools:
tools {
maven 'maven-3.8.4'
}
or withMaven:
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'maven-3.8.4',
Works fine. I did not set M2_HOME or add to PATH; Tool configuration takes care of that.
Started by user admin
Running as SYSTEM
Building in workspace C:\Users\jenkins\.jenkins.2.322.new\workspace\M-Foo
Unpacking https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip to C:\Users\jenkins\.jenkins.2.322.new\tools\hudson.tasks.Maven_MavenInstallation\maven-3.8.4 on Jenkins
[M-Foo] $ cmd.exe /C "C:\Users\jenkins\.jenkins.2.322.new\tools\hudson.tasks.Maven_MavenInstallation\maven-3.8.4\bin\mvn.cmd -version && exit %%ERRORLEVEL%%"
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: C:\Users\jenkins\.jenkins.2.322.new\tools\hudson.tasks.Maven_MavenInstallation\maven-3.8.4
Java version: 1.8.0_312, vendor: Temurin, runtime: C:\Tools\Java\jdk8\jre
Default locale: en_CA, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Finished: SUCCESS
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: C:\Users\jenkins.jenkins.2.322.new\tools\hudson.tasks.Maven_MavenInstallation\maven-3.8.4
Note: you must have proxy set up properly for the "Install from Apache" to populate for "Install automatically".
If you un-tick "Install automatically", then you must input the MAVEN_HOME (which should really be labelled M2_HOME) and then choose that.
Started by user admin
Running as SYSTEM
Building in workspace C:\Users\jenkins\.jenkins.2.322.new\workspace\M-Foo
[M-Foo] $ cmd.exe /C "C:\Tools\apache-maven\apache-maven-3.8.1\bin\mvn.cmd -version && exit %%ERRORLEVEL%%"
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: C:\Tools\apache-maven\apache-maven-3.8.1\bin\..
Java version: 1.8.0_312, vendor: Temurin, runtime: C:\Tools\Java\jdk8\jre
Default locale: en_CA, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Finished: SUCCESS
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: C:\Tools\apache-maven\apache-maven-3.8.1\bin..
I can download a maven artifact using mvn dependency:get, but when the remote artifact is updated dependency:get does not download the updated artifact.
The updatePolicy from settings.xml is ignored.
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
The artifact I want to download is not a -SNAPSHOT but a release artifact. It's version does not change. For the updated artifact I can see changes in the checksum for both the artifact itself as well as the respective pom.xml in the nexus repository manager gui. Seems like everything is properly configured since dependency:get and deploy:deploy-file work.
Is there any way to ask maven to check for updates on the remote repository?
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 1.8.0_252, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-40-generic", arch: "amd64", family: "unix"
Maven assumes that release artifacts never change.
If they change, this is usually some kind of mistake. One should not use the same version number twice.
You can call dependency:purge-local-repository to redownload all dependencies.
SonarQube 5.1 running on Ubuntu 12.04.4 LTS
Jenkins ver. 1.616 running on Ubuntu 12.04.4 LTS
SonarQube Plugin 2.2.1
Artifactory Pro Power Pack 3.8.0 (rev. 30190) running on Ubuntu 12.04.5 LTS
sbt 0.13.8
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk1.8.0_45/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.5.0-23-generic", arch: "amd64", family: "unix"
Attempting to use the SonarQube Jenkins Plugin in a Jenkins Build, the plugin seems to try to rebuild the entire build and re-resolve all the dependencies out of Artifactory. Problem is, unlike the rest of the build, when the SonarQube plugin requests artifacts from Artifactory, it does so as a non-authenticated-user, and Artifactory refuses the request.
I've tried everything from copying the <servers/>, <profiles/>, and <activeProfiles/> from the jenkins user's settings.xml file into /etc/maven.settings.xml and explicitly telling the plugin to use the former as user settings and the latter as system settings - in short, anything and everything I could find documented to medieval brute force the plugin to use the jenkins user's credentials , but still it just keeps connecting as a non-authenticated user and having its requests refused.
Example from Jenkins Log (sensitive information obfuscated):
INFO: No credentials available for BASIC 'Artifactory Realm'#libs.<organization>;:443
[WARNING] Could not transfer metadata <GAV>/maven-metadata.xml from/to ArtifactorySnapshotsRepo (<Artifactory URL>/artifactory/libs-snapshot/): Not authorized.
[WARNING] The POM for org.codehaus.jackson:jackson-core-asl:jar:1.8 is missing, no dependency information available
[WARNING] The POM for org.codehaus.jackson:jackson-mapper-asl:jar:1.8 is missing, no dependency information available
[WARNING] Failure to transfer <GAV>/maven-metadata.xml from <Artifactory URL>/artifactory/libs-snapshot/ was cached in the local repository, resolution will not be reattempted until the update interval of ArtifactorySnapshotsRepo has elapsed or updates are forced. Original error: Could not transfer metadata <GAV>/maven-metadata.xml from/to ArtifactorySnapshotsRepo (<Artifactory URL>/artifactory/libs-snapshot/): Not authorized.
And in Artifactory's request.log we get (again with sensitive information obfuscated):
20150916190344|5181|REQUEST|<Jenkins IP>;|non_authenticated_user|GET|/libs-snapshot//<GAV>/maven-metadata.xml|HTTP/1.0|401|0
The maven command launched by the SonarQube Plugin was as follows (lines broken for clarity, sensitive information obfuscated):
mvn
-f /var/lib/jenkins/workspace/NE-BUILD-1/pom.xml
-s /var/lib/jenkins/.m2/settings.xml
-gs /etc/maven/settings.xml
-e
-B org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
-Dsonar.jdbc.url=jdbc:postgresql://<server>:<port>/sonar
******** ********
-Dsonar.host.url=http://<server>:<port>/
-Dsonar.branch=sbt-publish-deb ******** ********
How can I make this process authenticate to Artifactory properly?
New to maven. When I run this command i get access denied error? any help? I am trying to configure maven to run with eclipse. Let me know if you need more information.
mvn -Declipse.workspace=<c:\temp\eclipse\workspace>eclipse:add-mvn-repo
Path:
C:\apache-tomcat-7.0.55\bin;C:\apache-ant-1.9.4-bi
n\bin;C:\apache-maven-3.2.2\bin;C:\Program Files (x86)\Google\google_appengine\
C:\Temp\eclipse\workspace>mvn -v
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T09:51:4
2-04:00)
Maven home: C:\apache-maven-3.2.2\bin\..
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
C:\Temp\eclipse\workspace>cd\Temp\eclipse\workspace
**C:\Temp\eclipse\workspace>mvn -Declipse.workspace=<C:\Temp\eclipse\workspace> eclipse:add-maven-repo
Access is denied.
C:\Temp\eclipse\workspace>**
Configuring Maven to run within Eclipse.
Eclipse has an embedded version of Maven which you can use. Assuming that you want to use Maven within Eclipse and outside of it, download Maven from http://maven.apache.org/download.cgi, extract it and set the M2_HOME environment variable such that it points to your local Maven installation directory.
Set JAVA_HOME environment variable so that it points to the JDK which you want to use.
Append %JAVA_HOME%\bin and %M2_HOME%\bin to the Path so that the jdk and mvn executables can be executed from anywhere.
Now open an Eclipse Workspace and go to Window > Preferences > Maven > Installations. If you want to use your standalone installation instead of using the embedded one, you can change it here.
If you have a specific Maven settings file which you want to use, then dump that settings.xml file under the .m2 folder of your User home directory.
Once this is done, you can easily use Maven from within eclipse.(File > Import > Maven > Existing Maven Projects) or create a new one (File > New > Maven > Maven Project). Once you have a project in your workspace, you can run different Maven goals on it by right clicking on the Project and selecting what you want from the Run As option.
I use maven 3.0.3 and have tried to generate pom for third-party jar like this:
mvn install:install-file -Dfile=cobra.jar -DgroupId=com.cobra
-DartifactId=cobra -Dversion=0.98.4 -Dpackaging=jar -DgeneratePom=true
According to link below it should generate proper pom.xml and install artifact in the repo.
http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html
Meanwhile, it returns such a error:
[ERROR] The goal you specified requires a project to execute but there
is no POM in this directory (D:\cobra-0.98.4\lib). Please verify you
invoked Maven from the correct directory. -> [Help 1]
Why is it asking for pom.xml while it should generate pom.xml?
This is an old question, but was a serious PITA for me for a few minutes, so I thought I'd share:
I just ran into this problem, and I believe that the issue is probably platform-dependent. The real tip-off was that the solution from Cyril's answer wasn't working as expected: despite my specification of -DgroupId=com.xyz and -DartifactId=whatever on the command-line and the corresponding entry in the POM file, the jar was installed in the local repo under com/whatever.
This led me to experiment with quoting command-line arguments, and the eventual correct result from formatting the command-line like this (after deleting the POM file):
mvn install:install-file "-Dfile=cobra.jar" "-DgroupId=com.cobra" "-DartifactId=cobra" "-Dversion=0.98.4" "-Dpackaging=jar" "-DgeneratePom=true"
Some of the quoting is doubtless redundant, but better safe than sorry, right? I happen to be running Vista on this computer, and would not be surprised if this problem were specific to this OS version...by the way, this was with Maven v3.0.4.
Are you sure that you are executing the install-file goal? I checked your command and it works for me, but when I place a blank install :install-file (maybe you have this typo) the install goal would be used which needs a pom.xml.
Try to use the -X parameter to get more debug information:
-X,--debug Produce execution debug output
My system
Maven
c:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\progs\apache-maven-3.0.3
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: c:\Program Files (x86)\Java\jdk1.6.0_21\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Install Plugin
c:\>mvn -Dplugin=install help:describe
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
This plugin has 3 goals:
install:help
Description: Display help information on maven-install-plugin.
Call
mvn install:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
install:install
Description: Installs the project's main artifact in the local repository.
install:install-file
Description: Installs a file in the local repository.
For more information, run 'mvn help:describe [...] -Ddetail'
I found a bypass. You need to create a simple pom.xml like this :
<project 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.cobra</groupId>
<artifactId>cobra</artifactId>
<version>0.98.4</version>
</project>
It's not perfect but it's worked for me. If you find a better way to do that, I'm interested.
My config :
$mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/maven
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: /usr/local/jdk1.6.0_20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-25-generic-pae", arch: "i386", family: "unix"
$mvn -Dplugin=install help:describe
...
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
...
Try to run it on cmd.exe or execute cmd command before the mvn command.
Using maven version 3.6.3, this worked for me to generate pom file in my chosen directory:
C:<MyChosenDir> mvn archetype:generate "-DgroupId=com.mycompany.app" "-DartifactId=my-app" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DarchetypeVersion=1.4" "-DinteractiveMode=false"
just go under your project directory where you can find your pom.xml file then execute the same command ! it works for me ;)
If you are having trouble with the command line version of Maven, you might want to try the M2E plugin for eclipse. It is far more user friendly for people without very much experience with Maven.
It worked for me when I changed Powershell to Cygwin. Powershell is somehow parsing the command line argument incorrectly.
I had that error when I was using maven in Windows, what worked for me was opening the cmd and not the PowerShell.
Apparently certain errors appear when you don't do it with the cmd.
I hope it works.
If you are getting this error during jenkins pipeline setup , Then the error is we are placing git repository without .git in jenkins git url blank .Generally we put website url of git repo but we need to place clone url of git repo.Insert .git (cloned url) to website url , Simply insert git clone url.