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
Related
I have a relativey simple multi module maven buid with a parent pom. This includes the 2 child modules as follows:
<modules>
<module>WebApp</module>
<module>WebService</module>
</modules>
When I run mvn clean install on the top level pom it cleans & installs each child module as expected. However I am now trying to add a plugin (codehaus weblogic) goal to deploy the WebApp .war to Weblogic 10.3.4 e.g. mvn clean install weblogic:deploy. For some reason this does not run the clean and install phases but does the deploy. If I run the command from within the WebApp directory it does do the clean and install before doing the deploy.
Is there some gotcha I'm missing that will not run the child life cycle phases if running a goal at the top level. Here's the command line output:
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] SupportClient
[INFO] SupportClient-WebServices
[INFO] SupportClient-WebApp
[INFO] Searching repository for plugin with prefix: 'weblogic'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] ------------------------------------------------------------------------
[INFO] Building SupportClient
[INFO] task-segment: [clean, install, weblogic:deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] [site:attach-descriptor]
[INFO] [install:install]
[INFO] Installing C:\Development\Destin8SupportClient\pom.xml to C:\Users\finchaj.HPH\.m2 \repository\com\mcpplc\supportClient\supportClient\1.0\supportClient-1.0.pom
[INFO] [weblogic:deploy]
[INFO] Weblogic Deployment beginning with parameters DeployMojoBase[adminServerHostName = localhost, adminServerProtocol = t3, adminServerPort = 8001, userId = xx, password = ****, artifactPath = C:\Development\Destin8SupportClient/WebApp/target/WebApp.war, projectPackaging = war, name = support-client-webapp, targetNames = AdminServer, remote = false]
[INFO] Weblogic Deployment parameters [-adminurl, t3://localhost:8001, -username, xx, -password, xx, -name, support-client-webapp, -targets, AdminServer, -source, C:\Development\Destin8SupportClient/WebApp/target/WebApp.war, -deploy]
weblogic.Deployer invoked with options: -adminurl t3://localhost:8001 -username xx-name support-client-webapp -targets AdminServer -source C:\Development\Destin8SupportClient/WebApp/target/WebApp.war -deploy
The file, 'C:\Development\Destin8SupportClient/WebApp/target/WebApp.war', does not exist.
It is running the weblogic:deploy goal on the top-level (pom!) module. This goal can only be run on a war or ear module.
You need to bind that goal in the WebApp sub-module to run in the install phase.
It is currently running on the top-level (pom!) module.
e.g. try adding the following to your weblogic configuration in the Webapp sub-module.
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
See also Example C-1 in this documentation
If you wish to have this run at the end of your build, once all other modules have been built, you will need to either:
re-order your sub-modules, so WebApp is last, then do as above
or, add another sub-module that will execute last, which depends on your WebApp submodule. Then, tell the weblogic plugin to use that .war file by specifying the following property maven.weblogic.war . You may want to use the dependency:copy goal first, to get the into the target dir of that last sub-module.
If you want to run the install phase first for all projects and after that deploy your projects to your webserver, you have to split the maven calls.
mvn clean install
mvn weblogic:deploy
By default, maven execute all tasks per project and to separate maven tasks the only solution to run them separately.
maven runs all the specified goals first on the parent project and then on the chldren.
From the logs it is evident that maven ran the clean and install goals of the parent and then tried to run the weblogic:deploy goal. Now, weblogic:deploy evidently is not a goal which is relevant to the parent, since it is meant to deploy a child webapp. maven does not know that and thus the failure.
Perhaps you should reconsider npellow's solution since it should work for your requirement.
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.
Hi i'm checking via new created plugin (mpc) some parts of the pom (scm area)...but now i faced that during the mvn release:prepare of a different modules which uses the created plugin (mpc) I got the following messages:
[INFO] [INFO] Scanning the projects...
[INFO] [INFO] ...
[INFO] [INFO] not a working copy....
The output "not a working copy" ...is because I'm checking the svn info output...
The question is can I recogdnize this state during the mvn release:prepare somehow ? for example via roperties or checking an attribute of the current project ? Which means in other words that I know inside my maven plugin (mpc) that currently the release:prepare cycle is running?
I found a solution. I simply check if the current build is building an SNAPSHOT version or not (ArtifactUtil.isSnapshot() very helpfull).
I'm building a Maven project which has half a dozen modules.
I'm fine with importing it myself using either Maven or Ivy, but other teams would like to use those jars as well, but their practice is to commit the jars and source jars to version control.
I'd like to generate a zip/tar assembly of all modules and their sources which they can use however they like.
I've read Maven Assembly Plugin: Including Module Binaries but I'm shy of using it because:
The linked FAQ entry returns a 404;
I need to manually specify all modules.
Is there an alternative?
Update: I've tried using the built-in assembly descriptors
mvn assembly:assembly -DprojectModulesOnly=true
mvn assembly:assembly
and both failed with
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to create assembly: Error creating assembly archive bin: You must set at least one file.
right after all the module builds have run.
I think you're on the right lines, the moduleSets options of the assembly plugin handles what you're after.
If you're looking for some useful documentation, the Module Selection section of the Maven book covers it quite thoroughly, including how to configure includes and excludes, handle binaries and sources, and exclude external dependencies.
I had this problem, for me, the solution was NOT put / at the beginning of your <fileset><directory>
If you do that will work on Windows, not on Unix/Linux!
<fileSet>
<directory>src/main/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>VERSION</include>
</includes>
</fileSet>
works whereas
<fileSet>
<directory>/src/main/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>VERSION</include>
</includes>
</fileSet>
causes
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.3:single (execution-pluggin-assembly) on project test3: Failed to create assembly: Error creating assembly archive assembly: You must set at least one file. -> [Help 1]
Have a look at the How to use assembly:assembly using predefined descriptor ids. I think the bin and src pre-defined descriptor files are what you need.
Sounds like you need a build-server of some kind. I was at JavaZone 2009 this week and looked at Hudson CI http://hudson-ci.org/
The server will create the artifacts you or other teams can use/download.
In my project, there are a number of dependencies that are transitively included from other dependencies that do not have pom.xml files available in any of our corporate repositories. These are internal jar-only libraries supported by various teams which have been uploaded into repositories for convenience from non-Maven teams, however these repositories are unfortunately not mine to play with.
For these dependencies, Maven insists on trying to retrieve the poms from each of my repository list every time I run a build, or mvn dependency:list. This means maven tries to retrieve 8x pom files from 7 different repository locations, and given this is over the global corporate WAN; it's really slow.
e.g. for one particular dependency
C:\Working\dev\workspace\project>mvn dependency:list
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building project
[INFO] task-segment: [dependency:list]
[INFO] ------------------------------------------------------------------------
[WARNING] Unable to get resource 'aGroupId:anArtifactId:pom:4.0.14i' from repository inhouse (http://someRepo1/proximity/repository/inhouse): While configuring wagon for 'inhouse': Unable to apply wagon configuration.
Downloading: http://someRepo1/proximity/repository/extFree/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository extFree (http://someRepo1/proximity/repository/extFree)
Downloading: http://someRepo1/proximity/repository/externalNonFree/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository extNonFree (http://someRepo1/proximity/repository/externalNonFree)
Downloading: http://someRepo2/efs/dist/maven/maven2-repository/incr/common/lib/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository efsRepo (http://someRepo2/efs/dist/maven/maven2-repository/incr/common/lib)
Downloading: http://someRepo2/efs/dist/btijava/maven2-repository/incr/common/lib/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository efsBTI (http://someRepo2/efs/dist/btijava/maven2-repository/incr/common/lib)
Downloading: http://someRepo3/maven/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository internal.repo (http://someRepo3/maven)
Downloading: http://repo1.maven.org/maven2/aGroupId/anArtifactId/4.0.14i/anArtifactId-4.0.14i.pom
[INFO] Unable to find resource 'aGroupId:anArtifactId:pom:4.0.14i' in repository central (http://repo1.maven.org/maven2)`
...
etc
...
[INFO] [dependency:list {execution: default-cli}]
[INFO]
[INFO] The following files have been resolved:
... etc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20 seconds
[INFO] Finished at: Tue Jan 26 15:01:48 CST 2010
[INFO] Final Memory: 31M/74M
[INFO] ------------------------------------------------------------------------
On the other hand, for POMs which are just invalid (older modelVersion, or corrupt/invalid XML, for example) it just checks my local repo, complains it's invalid and then continues. Which is fine; at least that doesn't try again over the WAN.
Is there a way (setting, override, repository config change) I can prevent Maven's dependency plugin/artifact resolver from repeatedly trying to locate missing POMs, if it already has the jar file in the local repo?
Specs:
Maven 2.2.1 (default superPOM plugin definitions)
JDK 1.6.0_18
Pascal's answer is correct for two local build workarounds. However, your best option is to request the owners of these projects to create POMs for the artifacts. They don't need to be complex, the simple alternative that Maven is using internally will work:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>aGroupId</groupId>
<artifactId>aArtifactId</artifactId>
<version>4.0.14i</version>
</project>
Downloading a POM is really a central concept in Maven to support transitive dependencies (actually, a dependency isn't just a JAR, see 3.5.5. Maven's Dependency Management for nice details on that) so I don't know if you can prevent it.
Of course, the right thing to do would be to fix the root cause of the problem. But if you can't, maybe you can run your build in offline mode (using the -o option). Or maybe you could just "install" the artifacts in your local repository using install:install-file and instruct the plugin to generate a pom for them using the generatePom optional parameter (but this obviously doesn't "scale" really well).
Set up a Nexus Repository (or similar) and upload the artifacts there. Nexus will automatically create basic poms for artifacts you upload.
download to local repo
setup nexus and upload
work offline
maybe the best idea is to get rid of maven all the way, it is horror !