Skip to content
Advertisement

Spring boot dependency error for some of the dependencies in maven

Below is my pom.xml

    <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.java.hackathon</groupId>
  <artifactId>com.java.hackathon</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>com.java.hackathon</name>
  <url>http://maven.apache.org</url>

  
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.6.0.1398</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.5.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- junit 5 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.0</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Error message i am getting is

 For artifact {org.springframework.boot:spring-boot-starter-data-jpa:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-
     plugin:2.6:testResources:default-testResources:process-test-resources) org.apache.maven.artifact.InvalidArtifactRTException: For artifact 
     {org.springframework.boot:spring-boot-starter-data-jpa:null:jar}: The version cannot be empty. at 

But in most of the cases what I observed most of them wont declare any version for spring-boot-starter-data-jpa and spring-boot-starter-web but i am getting these errors I am getting errors for all the dependencies where i had not declared version

So i want to know how to resolve these errors where version has not been declared or any plugins needed to be downloaded. I am executing the code in eclipse.

Advertisement

Answer

Normally you don’t declare dependency versions when you have defined a dependencyManagement section in your POM where you centralize all of the dependencies used by all of your modules.

Since your POM does not define a dependencyManagement, you will need to provide the version for each dependency. You can check this sample guide project from Spring Boot, where you will notice that they set a parent in the POM:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

This parent will cause the POM to inherit a dependencyManagement section containing all of the versions of the spring-boot-starter-xx dependencies.

More details: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-dependency-management

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement