I using maven to build my project and I am trying to input the parent version # run time.
<project>
<modelVersion>4.0.0 </modelVersion>
<name>Payroll Common</name>
<parent>
<groupId>com.adp</groupId>
<artifactId>PayRoll</artifactId>
<version>19.0-${build.version}</version>
</parent>
..
</project>
mvn -Dbuild.version=101 install. It is throwing an error.
Reason: Cannot find parent: com.adp:PayRoll for project: null:payroll-common:jar:null for project null:payroll-common:jar:null
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Cannot find parent: com.adp:PayRoll for project: null:payroll-common:jar:null for project null:payroll-common:jar:null
Can you please help me, with wat I am doing wrong.
thanks
Nash
No, you can't do that. Version numbers in the project or the parent must be fully-specified in the POM.
you can either leave out the parent version or the project version. If maven sees only one of them, maven assumes they are the same.
b.t.w.: ${build.version} is not a valid replacement. You can use ${project.version} to get the version of your current project.
Related
I try to run tycho in ubuntu, but I face this error.
Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.14.1:build-qualifier (default-build-qualifier) on project tychodemo.bundle: Execution default-build-qualifier of goal org.eclipse.tycho:tycho-packaging-plugin:0.14.1:build-qualifier failed: Unable to load the mojo 'build-qualifier' in the plugin 'org.eclipse.tycho:tycho-packaging-plugin:0.14.1'. A required class is missing: org.eclipse.tycho.core.TychoProject
I guess it's related to my framework, because I do the same in another computer and tycho run succesfully.Can you detect my problem?
thanks in advance!
Class loader errors for Tycho classes are typically caused by mixing multiple Tycho versions in the same reactor. Being a build build extension, there must only be one version of Tycho active at a time.
To do this, check that your reactor uses the same version for the Tycho build extension and the Tycho plug-ins, e.g. by using the variable ${tycho-version} as version and defining that version in your parent POM:
<properties>
<tycho-version>0.14.1</tycho-version>
</properties>
Also make sure that all your modules reference the same parent POM, and not an older version of the POM.
I'm trying to go through the examples in Maven: The Definitive Guide. In chapter '4.3. Creating the Simple Weather Project' it has me run the following command.
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch04 -DartifactId=simple-weather -DpackageName=org.sonatype.mavenbook -Dversion=1.0
I think these errors are a problem.
[WARNING] POM for 'asm:asm-commons:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-commons at Artifact [asm:asm-commons:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-util:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-util at Artifact [asm:asm-util:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-analysis:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-analysis at Artifact [asm:asm-analysis:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-tree:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-tree at Artifact [asm:asm-tree:pom:3.2:runtime]
because later I on get the message this
[INFO] Failed to resolve artifact.
Missing
--------
org.apache.maven.archetype:archetype-catalog:jar:1.0
org.apache.maven.archetype:archetype-common:jar:1.0
org.apache.maven.archetype:archetype-registry:jar:1.0
org.apache.maven.archetype:archetype-descriptor:jar:1.0
I ran the command again with debug on and I've included the output in a pastebin link
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch04 -DartifactId=simple-weather -DpackageName=org.sonatype.mavenbook -Dversion=1.0 --debug > mvnoutput.txt
http://pastebin.me/e50a3e5fa84cd8e8ff9336b3c3062d7f
I really have no idea why this is failing. I tried to navigate to the POMs manually using the
http://search.maven.org/remotecontent?filepath=asm/asm-commons/3.2/asm-commons-3.2.pom along with the other POMs and they look fine to me (but I'm trying to learn Maven.)
Here is my mvn effective settings. I left out the schema stuff at the very beginning. I am behind a proxy, but everything else seems to download fine. Any help would be much appreciated. I'll answer questions or post more information if you leave them as comments.
<localRepository>C:\Documents and Settings\~removed~\.m2\repository</localRepository>
<proxies>
<proxy>
<active>true</active>
<username>~removed~</username>
<password>~removed~</password>
<host>~removed~</host>
<nonProxyHosts>~removed~</nonProxyHosts>
<id>optional</id>
</proxy>
The most important thing is to start with Maven 3.0.4 instead of Maven 2.0.8. Furthermore you need to use:
mvn archetype:generate
instead of
mvn archetype:create
Take a look into the docs of the archetype plugin.
And one thing i recognized is that you are using an old book: Take a look into "Maven by Example" book and "Maven: The Complete Reference".
I'm doing some scripting and I need to get a list of all the parent poms for any given pom. The dependency plugin seems to be only interested in the dependencies that are listed in the dependency section of the pom, but there doesn't seem to be a way to show the parent poms, which are also required dependencies for Maven to work.
Am I missing something basic?
There is no simple Maven command that will show you the chain of parent POMs for a pom.xml. The reason for this is that it is not a common question one would typically ask (more on that below). For your script, you'll just have to parse the pom.xml file, get the parent artifact coordinates, get a hold of the artifact's pom.xml file and then parse it's pom.xml file (and repeat). Sorry, but there is no short cut I know of, but other folks have solved similar problems.
You are right that technically the parent pom is a dependency of your project, but it is not a literal Maven Dependency and is handled completely differently. The chain of parent poms, along with active profiles, your settings.xml file, and the Maven super pom from the installation directory are all combined together to create your project's effective pom. The effective POM is what Maven really uses to do its work. So basically, the parent pom inheritance chain is already resolved and combined before the dependency plugin (or any other plugin) is even activated.
The questions most people typically ask is 'what does my REAL pom.xml really look like when Maven is done combining everything?' or 'What is the result my inheritance chain of parent poms?' or 'How are my pom.xml properties affected by an active profile?' The effective pom will tell you all of this.
I know you didn't ask, but for others reading this, if you want to see your parent pom.xml, simply open up the pom.xml in the M2Eclipse POM editor and click on the parent artifact link on the overview tab. In this way you can quickly move up the chain of pom.xml files with just a single click per pom. It would be a strange project that had more than 3 or 4 parent poms of inheritance.
If you want to see your effective pom, you can run the command mvn help:effective-pom. Alternatively, you can click on the Effective POM tab in M2Eclipse's POM editor.
Basic solution
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1:display-ancestors
If your project defines version 3.1 or later you can use:
mvn dependency:display-ancestors
The output looks similar to:
[INFO] Ancestor POMs: org.springframework.boot:spring-boot-starter-parent:1.4.0.RELEASE <- org.springframework.boot:spring-boot-dependencies:1.4.0.RELEASE
Improved solution
The hierarchy-maven-plugin (that I wrote) can display additional information about imported poms like this :
[INFO] Displaying hierarchy. Set level=full to display dependencies in dependencyManagement
[INFO] PARENT org.springframework.boot:spring-boot-samples:1.4.1.BUILD-SNAPSHOT
[INFO] PARENT org.springframework.boot:spring-boot-starter-parent:1.4.1.BUILD-SNAPSHOT
[INFO] PARENT org.springframework.boot:spring-boot-dependencies:1.4.1.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework:spring-framework-bom:4.3.3.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework.data:spring-data-releasetrain:Hopper-BUILD-SNAPSHOT
[INFO] PARENT org.springframework.data.build:spring-data-build:1.8.4.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework.integration:spring-integration-bom:4.3.1.RELEASE
[INFO] IMPORT org.springframework.security:spring-security-bom:4.1.3.RELEASE
Details are here : https://github.com/ExampleDriven/hierarchy-maven-plugin
I have a library which I "mavenized" recently and put into a local git repository.
In order to lock some plugin versions I created a simple parent pom which defines the plugin versions via pluginManagement (the parent pom file is not checked into any SCM repository). I specify the parent pom in my libraries pom file:
<parent>
<groupId>org.my.company</groupId>
<artifactId>superpom</artifactId>
<version>1</version>
</parent>
I use default directory structure.
When I try to perform a release using the release plugin I run into a problem.
mvn release:prepare runs fine however when I run mvn release:perform maven checks out the corresponding tag from my local git repository into the target/checkout folder and tries to run the deploy goal.
However the build fails with the error message that it can't find the parent pom file defined in my library pom file.
I assume that's related to the fact that maven tries to find the parent pom file in the target folder and it is not available there.
Is there an easy way how to solve this problem?
Update:
I have multiple unrelated GWT libraries which should share the common company parent pom file in order to specify plugin versions.
The parent pom is just used for defining some default versions and won't contain any module definitions because all GWT libraries are unrelated.
The GWT library are really simple and have no real dependencies to any other libraries apart from the default ones (gwt, junit)
Update2:
I solved the problem by installing the superpom into my local repository by running mvn install in the folder of my superpom.
The first fail you did is not to versionise the parent pom where you defined the pluginManagement area. This is the first step you must do put the pom.xml which you like to use a parent. Secondly you have to put the information about the VCS into the scm area of that pom. After you cleaned up everything you must do a mvn release:prepare release:perform of the parent pom. After that you are able to use it as a parent in your other projects. Furthermore you should define the distributionManagement area in your parent pom.
Maven 2.2.1 claims to support version ranges (see e.g. http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-project-dependencies.html#pom-relationships-sect-version-ranges)
I tried from a brandnew maven installation the following pom:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>rangetest</artifactId>
<groupId>my.group</groupId>
<version>1.0</version>
<packaging>jar</packaging>
<description>test project containing one dependency, only</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The dependency should resolve to junit 4.8.2, right?
But instead, the version 4.8 is resolved:
C:\Users>mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - my.group:rangetest:jar:1.0
[INFO] task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] my.group:rangetest:jar:1.0
[INFO] \- junit:junit:jar:4.8:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Oct 07 14:30:40 CEST 2010
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------
You might think it's an issue with Junit, as 4.8 is an existing version, but it's not. In my projects, I have versions deployed from 1.0.0 to 1.0.15 (no version 1.0!), but mvn dependency:tree complains about missing artifact of version 1.0.
That only works if you actually specify a version range or if you have more than one POM. You use 4.8 which is a single version number, so Maven tries to resolve it directly. A version range must start with [ or ( (inclusive and exclusive, respectively).
In your case, try: [4.8,4.9)
That should give you the highest version with the same API (i.e. all bug fixes but no breaking changes).
This document shows how Maven interprets versions: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html
The first line seems to support your position (4.8 means "at least 4.8") but there is a catch: Maven will only select a higher version if anyone specifically asks for it. So unless you have more POMs in your build and one of those asks for 4.8.2, 4.8 is "good enough" for Maven.
Think of it as a hint for conflict resolution. If POM A asks for 4.8 and B asks for 4.8.2 and B depends on A, then Maven has to make a decision. Should it fail? Should it use 4.8? Or 4.8.2?
The rules resolve this conflict by picking 4.8.2 without giving a warning or an error.
If A asks for [4.8], you'd get an error instead since Maven can't silently "upgrade" the dependency to 4.8.2 and it certainly can't downgrade 4.8.2 to 4.8.
If you want to use version ranges, specify a version range as others pointed out. Currently, you're not.
But my real advice would be to not use version ranges at all, version ranges are a bad idea for build reproducibility and the last thing you want is a build that suddenly starts to fail because of an unknown reason. Just don't, they are a bad practice (which is probably why version ranges aren't documented anymore).
There doesn't seem to be a range qualifier in your version tag. Maybe you meant to use the following to require version 4.8 or later:
<version>[4.8,)</version>
In my case, everything was working but out of the sudden I got this error
No versions are present in the repository for the artifact with a range [x,y)
I went to the library location inside .m2/repository folder and deleted the whole folder,
if you removed folder of a specific version of the lib it won't work, should remove folders of all versions of that lib
one more thing, if the lib is transitive you might need to remove all libraries in the dependency path
hope this helps you