mvn versions:set fail after a build failure - java

My snapshot version looks like 2.7.644-SNAPSHOT
So pom.xml normally look like
<parent>
<groupId>com.orderManager</groupId>
<artifactId>parent-pom</artifactId>
<version>2.7.644-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
But after a failed release my pom.xml file looks like
<parent>
<groupId>com.orderManager</groupId>
<artifactId>parent-pom</artifactId>
<version>2.7.644.344</version>
<relativePath>..</relativePath>
</parent>
When I try to correct all versions by running mvn versions:set -DnewVersion=2.7.644-SNAPSHOT, I get an error
mvn is trying to find the failed build jars in a remote repo for some reason.
I'm just trying to change the version names in pom.xml, there's no reason to download jars. Is there a way to run mvn versions:set without downloading current version's jars?

Simply before any plugin will be executed on project, Maven need to load your project and resolve needed dependencies.
In case when corrupt your project for any reason, you have options:
restore previous/correct version of code from scm - if you have
fix manually problematic versions in poms

Related

Can I remove jar from local repository without pom.xml?

I install my jar to local repository by command:
mvn install:install-file -Dfile=aaa.jar -DgroupId=bbb -DartifactId=ccc -Dversion=1.0 -Dpackaging=jar
Now I want remove it from repository. I try command:
mvn dependency:purge-local-repository -DmanualInclude=bbb-ccc
But get error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:purge-local-repository (default-cli): Goal requires a project to execute but there is no POM in this directory (...). Please verify you invoked Maven from the correct directory. -> [Help 1]
Then I create pom.xml with data:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<groupId>bbb</groupId>
<artifactId>ccc</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<properties>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>${project.packaging}</packaging>
<file>aaa.jar</file>
</properties>
</project>
Now I can remove jar from repository. But can I remove by command line without creating pom.xml?
I'm using 3.2.5 (windows x64).
The dependency:purge-local-repository goal, up to the current version 2.10, needs to be executed on a Maven project:
Requires a Maven project to be executed.
One of the purpose of this goal is to remove from the local repository the dependencies of a Maven project, so it needs one to execute. This explains the error you have.
However, with this plugin, it is possible to specify a manualInclude parameter, which will remove any dependency specified as groupId:artifactId:version or all versions of groupId:artifactId or even everything under a groupId. Therefore, the plugin could be updated to not require a Maven project to be executed.
I went ahead, created the JIRA issue MDEP-537 to track this addition and will fix this for version 3.0.0.
As Tunaki mentioned in his answer, he requested MDEP-537 for the Dependency plugin to be able to purge without a Maven project. This has been implemented since version 3.0.0.
If you only run mvn dependency:purge-local-repository, you are likely to run an older version. E. g. my Maven 3.6.0 comes with Dependency plugin version 2.8.0.
So you should run a specific version of the plugin:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:purge-local-repository -DmanualInclude=...

Maven building working from command prompt, but not from Eclipse

I found this crazy issue in my eclipse. I'm able to run the Maven build with the command "maven clean package" in command prompt. But however when I try to build the same in eclipse by doing right click-> run as -> Maven build, In the configuration I've added as "clean package". It is throwing me the error of
The project com.svu.core:cUT:1.0.0-SNAPSHOT (E:\CU-SVN\pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: Failure to find com.zenmonics.core:epom:pom:1.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 11, column 10 -> [Help 2]
It has the same error in POM.xml, but how is it running from command prompt but not from eclipse IDE. Due to this I'm not able to get Maven dependencies in my Build path.
<project xmlns="http://maven.apache.org/POM/4.0.0" x mlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- <groupId>com.svu.core</groupId>-->
<artifactId>cUT</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>pom :: cUT</name>
<packaging>pom</packaging>
<parent> <---------- Here it throws error
<groupId>com.svu.core</groupId>
<artifactId>epom</artifactId>
<version>1.0.0</version>
</parent>
You might be using embedded maven inside eclipse.
You can try using the same maven set up that you are using on your system.
go to -->
Window >> preferences >> maven >> installations
Here in - add a new installation and give the path till bin folder of maven libraries.
Try using this approach - it should work , if your maven commands are working fine from command prompt.
Please check your workspace whether maven repository exist or not exist..!
Please try to put your pom.xml. Your error says that the problem is in pom.xml # line 11, column 10. The problem is the parent pom is not detected in your current pom. Try the following
<project>
<parent>
<groupId>com.svu.core</groupId>
<artifactId>epom</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.svu.core</groupId> <--- Same group id as your parent
<artifactId>cUT</artifactId>
Reference: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html
Note: I dont have enough reputation to comment in your question.
When following is working
cd cUT
mvn compile
but the same module cannot be compile in Eclipse. Probably you have changed the Maven config and the Eclipse view of it is not up-to-date anymore. This can happen for exmaple if you change a pom.xml file outside Eclipse or at a place which is not considered as to be in the project path (see your other question).
Select in the Project Explorer in Eclipse the module cUT. Press ALT-F5 (executes maven -> update project). Select all modules of your project, check that update project configuration from pom.xml is enabled and click on òk` to process.
I had the same exact problem, everything was working on eclipse Mars, but I switched to Eclipse Oxygen and all my variables were fine, I checked everywhere.
And suddenly I got into the preferences in eclipse for Maven Installations (where you point to the Maven directory) and just got rid of the forward slash at the end of the path and it worked!
Basically:
Change C:\Program Files\apache-maven_3.5.3\
to
C:\Program Files\apache-maven_3.5.3
And it worked!
The difference between building from command line and eclipse is the variables. Like:
the java path in case you have more than one jdk. The command line will pick from java home where as in eclipse you can configure which jdk to use.
settings.xml can also be different. I think this is the problem in your case. Command line picks the settings.xml from the source code directory (if present). This file contains the maven repo url to download all the dependencies. In eclipse you can configure the path for settings.xml. I suspect the path is different in eclipse compared to command line. Please change that in eclipse and it should work. I have faced this issue and this was the root cause. you can see in your logs "Failure to find com.zenmonics.core:epo, which suggests the some problem in the repo url.
I have installed latest maven and in the windows -> maven -> installation I have added my latest maven. It started working for me.

Maven install not respecting command line arguments

I have a project which I am attempting to install with maven. The pom.xml has a few properties in it which are modified when the maven install command is run depending on whatever version of a library we are attempting to build with:
<properties>
<some-version>0</some-version>
</properties>
The zero here is a placeholder, as we'll always specify a legitimate version during our build process. The version is then referenced later in the pom.xml to specify a few dependencies:
<dependencies>
<dependency>
<groupId>com.mycompany.myproduct</groupId>
<artifactId>someOtherProject</artifactId>
<version>${some-version}</version>
</dependency>
</dependencies
Building is done via make with the following commandline:
mvn -Dsome-version=1.6.2
Maven is able to correctly resolve the version and build as expected. However, the version being installed in my local maven repository (/home/user/.m2) doesn't have the correct version. The pom.xml that is installed does not have the updated version I set in the command line:
user#ubuntu:~/$ cat /home/user/.m2/repository/com/mycompany/myproduct/myproject/1.0.0/myproject-1.0.0.pom | grep some-version -C 1
<properties>
<some-version>0</some-version>
</properties>
--
<artifactId>someOtherProject</artifactId>
<version>${some-version}</version>
</dependency>
user#ubuntu:~/$
This is preventing any other project which depends on myproject from being able to build, as maven will complain that it can't find version 0 of someOtherProject:
[ERROR] Failed to execute goal on project myproject:
Could not resolve dependencies for project mycompany.myproduct:myproject:jar:1.0.0:
The following artifacts could not be resolved: com.mycompany.myproduct:someOtherProject:jar:0,
Could not find artifact com.mycompany.myproduct:someOtherProject:jar:0 in central (https://mycompany.com/artifactory/repo/) -> [Help 1]
What do I need to do for maven to install with the updated version in the pom? Obviously a terrible hackish solution would be to use sed and modify the pom file directly, but it seems that Maven should be able to actually leverage the command line settings when installing the pom. Otherwise the ability to set arguments on the command line seems remarkably limited in effectiveness.
Better you may set your property in pom.xml in <properties> tag like this -
<properties>
<property>
<name>some-version</name>
<value>1.6.2</value>
</property>
</properties>
If you use this then you don't have to provide the property each time you issue a mvn command from terminal.
mvn -Dsome-version=1.6.2 works as a substitution value for the scope of building than replacing the original POM with the new values. Hence is the behavior you see. I am not aware of any maven support to do so.
Under #JoopEggen's advice, I looked deeper into the maven versions plugin. It offered an update-property target which will actually update the pom.xml value on disk, rather than just passing in an overwrite during the build phase. I was able to solve my issue by calling
mvn versions:update-property -Dproperty=some-version -DnewVersion=1.6.2 -DsearchReactor=false -DallowSnapshots=true
in the makefile before calling mvn install. Disabling the reactor was necessary to prevent the plugin from rejecting values it couldn't find in the remote repo (see here), and allowSnapshots allows me to use version numbers such as 1.6.2-SNAPSHOT, useful when testing.

Maven dependency not getting corresponding POM file downloaded

I've got a maven project that has a dependency that it gets from a remote Nexus repository. I believe that the dependency was not built with maven, and just uploaded with a barebones POM file. The layout on the server looks fine though, so it was probably deployed with maven.
When maven downloads the dependency to my local repository, it downloads the jar file, but doesn't get the POM. At build time, there's a warning that the POM couldn't be found, and no dependency information available. I'm not actually using any of its code directly (it's actually a transitive dependency), so build completes successfully.
The real problem arises when I try to perform site generation for my project. The part that tries to generate the dependency graph report fails, because it can't find the POM for this dependency to work with.
I can't figure out why I'm not getting the POM downloaded, when the jar file for it gets downloaded just fine.
The POM file for that particular dependency looks like this (you can see why I don't think it's built with maven :))
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.component</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0.1</version>
</project>
You'll notice that the root <project> element doesn't contain any namespace or schema information. Could this be related? Could it be Nexus not recognizing it as a POM? Apart from the possibility of some small syntactical character missing or mistaken, this is my current train of thought...please don't let it influence any ideas you may have! :)
Also, while troubleshooting, I've pasted the contents of the remote POM file into the correct file location in my local .m2 repo. Everything works fine when I do that. This isn't an acceptable fix though, because we will need the build to be done on our CI build servers.
Any help/suggestions greatly appreciated!
Edit:
I've managed to temporarily solve my actual problem, but the strangeness here still exists. I solved the problem by explicitly excluding the thing that depends on this from the dependency that's in my pom (the trouble dep is two steps away at least, and I'm not using anything that uses the thing that pulls it in):
<dependency>
<groupId>com.company.utility</groupId>
<artifactId>shared-utility</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>com.company.common.component</groupId>
<artifactId>thing-that-puls-in-bad-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
I've created a dummy project to prove it, with the following POM:
<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.company.project</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.company.component</groupId>
<artifactId>bad-artifact</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</project>
Now in ~/.m2/repository/com/company/compnent/bad-artifact/1.0.1/, I've got:
_remote.repositories
bad-artifact-1.0.1.jar
bad-artifact-1.0.1.jar.sha1
bad-artifact-1.0.1.pom.lastUpdated
With no actual POM file.
If you look inside of _remote.repositories, then this file probably contains information which says "downloading the POM failed last time, don't try it again."
That's one of the things where Maven's policy "don't try to download releases again" gets in your way. Try to delete the folder ~/.m2/repository/com/company/compnent/bad-artifact/1.0.1/ and run Maven again to see the error.
It's quite possible that Maven refuses to use such a broken POM since the root element doesn't have the correct XML namespace. But it's hard to tell without seeing the actual error message.
A way to fix this is to download the JAR and to use mvn install:install-file from the command line to install the dependency locally. Even better, you can use mvn deploy:deploy-file to deploy it to your own Nexus server so all other developers now get a "good" version of the POM.
You should also get in contact with the people running the remote Nexus server so they can fix the issue.
Not related to your actual problem, but with maven (at least, recent version), generated jar contains their pom.xml in the META-INF/maven folder of that jar.
You should try to run maven with -e -X, and move your local repository to force Maven to download all, again.
mv "~/.m2/repository" "~/.m2/repository.old"
mvn -X -e dependency:tree
[edit] it was initially a comment, but it will be too long:
As far as I understand your problem, I think it is an error on Nexus, and not on your machine. Any valid solution would require you to mess with that your company Nexus. If you don't have permissions to do anything with your Company Nexus, you can test it with a local Nexus.
You can also enforce use of that Nexus in your ~/.m2/settings.xml like this:
<mirrors>
<mirror>
<id>nexus-local-central</id>
<mirrorOf>central</mirrorOf>
<url>http://localhost:8081/nexus/content/repositories/central</url>
</mirror>
<mirror>
<id>nexus-local-any</id>
<mirrorOf>external:*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
You should not lose too much time as to why it fails, but focus on making it working.
For that, I think you should write a valid pom.xml for that artifact, and redeploy it on the server using the pomFile option:
mvn deploy:deploy-file -DpomFile=valid-pom.xml -Dfile=foobar.jar -Durl=http://nexus:8081 -DrepositoryId=company-nexus-deploy
Or if you are too lazy (or if this command fail), do it from the Nexus GUI!
PS: the Nexus default admin login/password are admin/admin123, and I think there was also deploy/deploy123 for deployment. Most Nexus that I've seen were not configured to use another login/password.

Maven finds artifact but cannot compile

When I run a mvn compile I get a list of errors from the compilation that all say a package is missing that I have as a dependency in my pom.xml.
Pom.xml
`<dependency>
<groupId>com.fortysevendeg.android</groupId>
<artifactId>swipelistview</artifactId>
<version>1.0-SNAPSHOT</version>
<type>apklib</type>
</dependency>`
Error
error: package com.fortysevendeg.swipelistview does not exist
I would really appreciate some help on this one. I have been banging my head against this for a while now.
Looks like MVN is not able to pull your package ( com.fortysevendeg.swipelistview ) from your repository. To figure out, I would check-out the package from code repository ( i.e SVN, GitHub ) to your work space. Recheck the pom.xml for exact name & do MVN install.
link: Read
Downloading from a Remote Repository
Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer).
By default, Maven will download from the central repository.
During MVN compile it look first in your local workspace & if doesn't find then it will pull it from repository configured to.

Categories

Resources