I have a parent platform BOM like this:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>platform-bom</artifactId>
<version>7.0.LTS.9</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<!-- Third Party Dependencies Managed Via third-party BOM -->
<dependency>
<groupId>com.company</groupId>
<artifactId>third-party</artifactId>
<version>7.0.LTS.9</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.company</groupId>
<artifactId>api</artifactId>
<version>7.0.LTS.9</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
I am importing it like this in my project:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.company</groupId>
<artifactId>platform-bom</artifactId>
<version>7.0.LTS.9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
When I am importing api dependency like below, it automatically pulls the version from the imported BOM.
<dependency>
<groupId>com.company</groupId>
<artifactId>api</artifactId>
</dependency>
However when I try to do the same for the third party bom, it is not able to pull the version from the imported BOM.
<dependency>
<groupId>com.company</groupId>
<artifactId>third-party</artifactId>
<type>pom</pom>
</dependency>
Error I get is: Unresolved dependency: 'com.company:third-party:pom:unknown'. Is there a way to pull the version from the BOM which is imported? If not, I think it defeats the purpose of having a BOM in the first place.
Related
I need to import a dependency in my project; The problem is that that dependency is specified by a pom in this way:
<dependency>
<groupId>it.xxxx.yyyyy.be.esb</groupId>
<artifactId>CR_XXXXX_BE_PRODO_YYYYYY_V1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
When I add this dependency in my project it compile well, and in my local repository (.m2) I find the folder at the path it.xxxx.yyyyy.be.esb;
But not find any jar inside the folder, so How I can use that dependency?
That dependency should be a client to make soap call to a server!
In other project the dependency was:
<dependency>
<groupId>it.xxxx.yyyyy.be.esb</groupId>
<artifactId>CR_XXXXX_BE_PRODO_YYYYYY_V1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
And when I compile, the jar file is downloaded and i'm able to find it in my local repository (.m2), also I can decompile and see all class inside the package, and I can import in my class;
So my question is, is there a way to use the first dependency (the one with pom as type: pom)?
thanks
In dependencyManagement you can import a "bill of materials" (BOM) that is provided in pom format. Here all the supplied components, their requirements and their versions are included so that you know that you are using all the versions that the BOM provider used.
For example, Spring boot (I know you can do it as a parent pom):
<dependencyManagement>
<dependencies>
<!-- Import dependency management from Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
.
.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</dependency>
</dependencies>
In their BOM, all the versions of the Spring Boot dependencies, including the versions of their plugins, are defined in one place.
Another good example is junit:
<!-- use dependency management to import pom -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.9.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
.
.
<dependencies>
<!-- Version is defined in the parent pom -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I have a spring boot application having starter-data-jpa dependency added to pom.xml. I can clearly find the javax.persistence package present in maven dependency section. But I am unable to use #Entity annotation. Upon manually entering import javax.persistence.Entity eclipse shows unresolved dependency.
Thanks in advance.
here is my pom.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springframework.boot</groupId>
<artifactId>currency-exchange-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>currency-exchange-serviceweb</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
You're specifying <scope>test</scope> for the JPA starter, which specifically tells Maven that you only want that dependency available for test classes. Remove the scope and it should work.
Try removing <scope> for dependency JPA starter from pom.xml, do mvn clean install -U. this should solve your issue.
You should remove <scope>test</scope> from the spring-boot-starter-data-jpa dependency first.
If it still doesn't work, verify that your project runs when using Maven directly, by using the following command within a terminal:
mvn spring-boot:run
If this command works, reimport your project within your IDE, and test again. Often, the IDE doesn't immediately update the classpath, and is at fault.
Can you help me understand what really the advantage of using a BOM pom is ?
more precisely what is the difference between using a BOM pom and
writing the content of BOM pom in the dependencyManagement section of
a parent pom ?
<dependencyManagement>
<dependencies>
<dependency>
<groupId>xxx.yyy</groupId>
<artifactId>com.so</artifactId>
<version>${my.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
vs
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
I am in the process of upgrading form Apache CXF 2.7.5 to 3.0.2 but I am having the problem below.
When I am including the dependency
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
<version>3.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
to my pom.xml I don't see any .jar files downloaded to my project. There are no errors on the project.
I am using Maven 3.2.3 with Eclipse Juno Release2 and m2e 1.3.1
Why the <type>pom</type> is not getting resolved to the respective jar files of the framework?
Isn't the <type>pom</type> dependencies suppose to give the respective libs automatically? And if not what is the benefit of using them?
UPDATE
This is how my pom.xml look like
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.sysman</groupId>
<artifactId>serviceWrapper</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>serviceWrapper Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
<version>3.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
</dependency>
</dependencies>
<build>
<finalName>serviceWrapper</finalName>
<pluginManagement>
<plugins></plugins>
</pluginManagement>
<plugins></plugins>
</build>
</project>
Thanks
Your dependency scope is import. This means it must be part of a dependency management declaration.
With dependency management you are not directly download dependencies. It is a way to ensure that specific versions of dependencies are required. So further down your pom in the dependencies part if you declare
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
without specifying the version, maven knows which artifacts to download. Also controls versions in transitive dependencies.
Your pom probably refers to a bill of materials (BOM)
For more details see http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management
Where do you include this statement?
<scope>import</scope> is only effective inside the <dependencyManagement> section, i.e.
<dependencyManagement>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
<version>3.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
Also, it does not download dependency per se, but instead expands referenced pom in place.
If you just need the pom, exclude <scope>import</scope>.
<project (...)>
<modelVersion>4.0.0</modelVersion>
<groupId>our.group.id</groupId>
<artifactId>parent.of.all</artifactId>
<version>3.2.2-SNAPSHOT</version>
<packaging>pom</packaging>
<url>http://maven.apache.org</url>
<modules>
<module>module-common</module>
<module>module-A</module>
<module>module-B</module>
<module>module-C</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-B</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>our.group.id</groupId>
<artifactId>module-C</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
This is the main pom of project, that holds within some modules module-common module-A module-B module-C.
The issue that I am facing is the fact, that most of them is bing compiled and tested multiple times, because of internal dependencies between modules:
<project (...)>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>our.group.id</groupId>
<artifactId>parent.of.all</artifactId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<artifactId>module-B</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
(... - some external dependecies...)
</dependency>
<dependency> <!-- internal dependency to other module -->
<groupId>our.group.id</groupId>
<artifactId>module-common</artifactId>
</dependency>
</dependencies>
</project>
The more dependencies there are, the longer it takes to build project. How can I prevent maven from doing full install on the same modules being done multiple times?