2

I encountered a problem with running my spring-boot application using the terminal. In IDE (IntelliJ) app starts perfectly, but when I try to run it by mvn clean spring-boot:run an error occurs.

shell
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.020 s
[INFO] Finished at: 2023-01-17T09:35:14+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.1:run (default-cli) on project tobebought: Unable to parse configuration of mojo org.springframework.boot:spring-boot-maven-plugin:3.0.1:run for parameter version: Cannot find 'version' in class org.springframework.boot.maven.Exclude -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigurationException

I tried changing the version of spring-boot as well as adding the <version\> tag to the parent dependency. Also, I tried deleting the .m2 folder and downloading all dependencies again. Maven is up to date because I tried to reinstall it also.

Here is my pom.xml

<?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 https://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>3.0.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.pedrycz</groupId>
    <artifactId>tobebought</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>tobebought</name>
    <description>Service allowing users to store their shopping lists</description>
    <properties>
        <java.version>19.0.1</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.passay/passay -->
        <dependency>
            <groupId>org.passay</groupId>
            <artifactId>passay</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</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.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <version>6.0.1</version>
            <scope>test</scope>
        </dependency>
<!--         https://mvnrepository.com/artifact/com.auth0/java-jwt-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>1.4.2.Final</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok-mapstruct-binding -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>0.2.0</version>
<!--            <scope>provided</scope>-->
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.24</version>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.24</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.4.2.Final</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>0.2.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
wazzupek01
  • 29
  • 7
  • Start with removing all `version` tags from the `org.springframework.boot` dependencies and `spring-security-test` (those are managed by the parent) as well as for the `spring-boot-maven-plugin`. DItch `jakarta.validation-api`. Remove the `source`/`target` from the `maven-compiler-plugin` andyou want to upgrade the `mapstruct` version to 1.5.3. Also as the scope is `provided` for lombok you don't need the exclude. – M. Deinum Jan 17 '23 at 09:22
  • @M.Deinum Unfortunately problem still exists – wazzupek01 Jan 17 '23 at 09:33
  • You removed the exclude as well? You are trying to outsmart things that are already done by Spring Boot as a parent and the starters. The problem is the exclude as it doesn't allow a version but you shouldn't need the exclude as a provided dependency isn't included anyway. – M. Deinum Jan 17 '23 at 09:42
  • @M.Deinum removing exclude worked, I thought that it was necessary since I was trying to run mapstruct with lombok. Thank you very much – wazzupek01 Jan 17 '23 at 09:47
  • The plugin configuration for maven-compiler-plugin to use source/target with Java 8 is simply wrong. Spring Boot 3.X requires minimum JDK17... which is also in contradiction to the given `java.version` property... – khmarbaise Jan 17 '23 at 11:38

1 Answers1

2

The problem is the exclude, which you don't need, as an exclude only allows for a groupId and artifactId to be set, no version. But as stated you don't need the exclude.

Looking at your pom.xml you are also trying to outsmart other parts of the dependency management and configuration.

<?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 https://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>3.0.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.pedrycz</groupId>
    <artifactId>tobebought</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>tobebought</name>
    <description>Service allowing users to store their shopping lists</description>
    <properties>
        <java.version>19.0.1</java.version>
        <mapstruct.version>1.5.3.Final</mapstruct.version>        
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.passay</groupId>
            <artifactId>passay</artifactId>
            <version>1.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</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.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${mapstruct.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>0.2.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${mapstruct.version}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok-mapstruct-binding</artifactId>
                            <version>0.2.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
  • spring-boot-starter-validation already contains the needed dependencies, no need for jakarta.validation-api as a dependency
  • The spring-boot-starter-parent will already manage the dependencies for the starters and supported dependencies (like spring-security-test) no need to specify a version
  • No version for the maven-compiler-plugin and no source/target those are already set and managed by the spring-boot-starter-parent you want to extend the configuration
  • Upgrade to a newer Mapstruct version and use a version property
  • No version for the spring-boot-maven-plugin already managed by the spring-boot-starter-parent and the exclude doesn't support version as it will automatically exclude the dependency for that specific version (that is basically how excludes work).
M. Deinum
  • 115,695
  • 22
  • 220
  • 224
  • "the exclude isn't needed as well as the dependency is provided and thus not part of the archive" - that is wrong, unlike other maven plugins, the behaviour of `spring-boot-maven-plugin` is [counterintuitive](https://github.com/spring-projects/spring-boot/issues/413) – Andrey B. Panfilov Jan 17 '23 at 10:11
  • A **** you are right, I totally forgot about that... Updated the answer to reflect that. – M. Deinum Jan 17 '23 at 12:33