Our warfile contains not the expected SNAPSHOT-Version of a jarfile, it contains an older release version via another dependency.
Simplified dependency:tree
war-x.x.x-SNAPSHOT
\- jar1-x.x.x-SNAPSHOT
+- jar2-x.x.x
| +- problemjar-x.x.x
+- jar3-x.x.x-SNAPSHOT
jar3-x.x.x-SNAPSHOT has a dependency "problemjar-x.x.y-SNAPSHOT" (newer version), but the war project build (and the dependency:tree) contains "problemjar-x.x.x" from "jar2-x.x.x".
For now, we "exclude" "problemjar-x.x.x" for "jar2-x.x.x".
But it would be nice to know the reason for this behaviour, IMHO the exclusion is just a workaround.
Notes:
The dependency "problemjar-x.x.y-SNAPSHOT" in "jar3-x.x.x-SNAPSHOT" is not "provided".
The Maven version is 3.2.5
The levels in the simplified dependency:tree above are correct, so the path to the older version is not shorter than the path to the newer SNAPSHOT version
edit: project structure
war and jar1 are children of one parent pom, the simplified dependency:tree is from the war project which has the jar1 project as a dependency. The others are normal/external dependencies, which applies to jar1 too as seen from the war project.
Maven does not take the newest version from the dependency tree.
It takes the nearest version, and in your case this is the first it encounters.
If you want to force Maven to take a specific version, it is better to use <dependencyManagement> instead of exclusions.
Make sure of the following:
1) Each child module should take it's version from it's parent, i.e. do not have a <version> tag only a <parent> tag that contains a version.
2) When you call the dependency from the same project always do it as follows:
<version>${project.version}</version>
Related
I introduced org.elasticsearch:elasticsearch:7.14.0 in pom.xml, but I ended up using the version number 7.12.1 provided in springboot, why?
I need the 7.14.0 version
End-use version
spring-boot-dependencies[pom.xml]
easy-es-parent[pom.xml] |
easy-es-common[pom.xml]
This is my complete pom.xml file
https://gist.github.com/2720851545/b75a50bd0119590f928d1e70a99ea03f
In Maven, any transitive dependency-version might be used, you could try to explicitly state in the POM which version for that given dependency you want to have.
With maven dependency-plugin, it should be transparent which dependency-version will be effective:
mvn dependency:tree
As in question the pom.xml from started does not provide the version information
Using dependency tree we can see versions of all dependencies in the maven project.
mvn dependency:tree -Dverbose
Expand the maven dependencies folder in the project explorer of the IDE.
The version number is present at the end of the file name, like
spring-boot-starter-data-jpa-2.5.5.jar
Here 2.5.5 is the version number of the corresponding file.
There are couple of ways you can find the version.
One option is to verify the version downloaded from you IDE or from you .m2 folder
If you want to know where the version is specified you need to travel through the <parent> tag mentioned in the pom.xml. In the case of Spring Boot Data JPA Starter pom.xml the version is specified in spring-boot-build pom.xml within the properties tag. You can check the below link for the pom.xml definition :
spring-boot-build pom.xml
I am including another pom file as parent in my current maven project.
There is a dependency for hibernate 3.3.2 defined in parent pom file.
I want to use the latest version of hibernate 4.3.5 in my current project. my question is how to exclude the older version so that antlr and other dependencies gets properly generated in my war file.
I also want my war file not to have duplicate jar files
Please help
Just put the version you want in your own POM file.
When there are multiple versions of same artifact resolved transitively (through parent, or through transitive dependencies), Maven is going to resolve find the version to use. Normally it use the "nearest" one. If you are declaring the dependency in the POM of the project itself, it will always be the "nearest" and hence will be used.
In your case, just put hibernate:4.3.5 in your POM, and hence this version will be taken instead of hibernate:3.3.2 (which is declared in parent), no related transitive dependencies of hibernate:3.3.2 will be included in project.
Just one thing to be careful: such kind of version resolution is done only for same artifact, which means, artifact with same Group ID and Artifact ID. If the old version in parent is org.hibernate:hibernate:3.3.2 while the newer version is org.hibernate:hibernate-core:4.3.5, it will not work. In such case, you need some trick to explicitly exclude the dependency from parent, for which you can look into https://stackoverflow.com/a/7898553/395202 for one method.
I have a parent project(has its own pom.xml) in which I import the child project as a jar with its own pom.xml.
In the parent pom.xml I have specified my child jar as a dependency - this gets resolved, but i want maven to resolve the dependencies required by my child jar.
My Use case to replicate :
When I include spring-web-mvc.jar the transitive dependencies are resolved automatically.
I have a similar requirement where I include my child.jar into a main framework project and expect the transitive dependencies to get resolved (Notw: the child.jar is not hosted it is packaged as jar and present on the local file system)
Current Structure:
Child Project:
|----/src/main/java
|----/src/main/resources
|----child-pom.xml
>This child project will be a jar as dependency in the parent project
Parent Project
|----/src/main/java
|----/src/main/resources
|----/src/main/webapp/WEB-INF/lib/child.jar
|---- parent-pom.xml
The problem:
When i create a war from parent project i want all the dependecy including transitive ones to show in WEB-INF lib.
Currently this is not happening.
First when talking of parent/ child Maven projects normaly you have your"childs" specified as modules in a common parent project which itself is beeing packed with the packaging type pom rather than make them a dependency of the parent project.
When it comes to the dependencies of your "childs" or generally "dependencies of your dependencies" those are called transitive dependencies and are pretty well explained in the official documentation found here: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
The resolving of those transitive dependencies is one of Mavens core strenghts and guaranteed by default unless they lead to conflicts that make the build fail.
Two things to help here are having a closer look into the enforcer plugin (http://maven.apache.org/enforcer/maven-enforcer-plugin/) and the shader plugin (http://maven.apache.org/plugins/maven-shade-plugin/) .... well and the official documentation of corse (reading the whole thing takes less than a day - then supports you further for specific topics whereas we gladly further support you too if you already have pom.xml files and you are stuck somewhere.
While the enforcer-plugin covers certain conflicts regarding different versions of the same artefacts the shader plugin will just pack everything you specified to a single jar for reverseengineering (its not the normal use case but i sometimes use it that way if i am not absolutly sure what ends in my final archives).
Also worth a look at is the dependency-plugin already available in the maven distributions - mvn dependency:tree -Dverbose will give you pretty detailed information on the resolved dependencies (and probably version conflicts).
I'm creating new project for Servicemix 4.4.0. My project will consist of several modules and one parent pom.xml, here is an example:
+- Module1
+- Module2
+- pom.xml (parent)
Each module contains element referring to the parent pom.
I was thinking about declaring all Servicemix dependencies in parent pom. This way, I would get rid of versions in child modules.
So my question is, how to include all Servicemix dependencies in my parent pom.xml without typing them directly one by one? Perhaps there is a way to import some Servicemix parent pom or something similar?
Servicemix4 is just an OSGi container with a bunch of features/bundles already installed, you don't want to import all the Servicemix dependencies into your project. Instead, build your project (using the maven-bundle-plugin) using only the dependencies necessary for your project and then deploy it into Servicemix4.
see these pages for more information...
http://servicemix.apache.org/SMX4/creating-a-bundle-using-maven.html
http://www.consulting-notes.com/2010/08/servicemix-developer-machine-setup.html
If you are just looking for the latest versions of artifacts, then you can get them here...
http://svn.apache.org/repos/asf/servicemix/smx4/features/trunk/pom.xml