简体   繁体   中英

Can't compile multi module Spring project with Maven

I took an older Java 11, Spring based multi module project that I didn't work on since about two years and tried to make it compile and run on my new laptop. It worked on my old laptop, but I can't make it run on the new laptop. When running mvn clean install the module called "util" compiles fine. But the "shared" module, which requires the "util" module, does not find the util module: "cannot find symbol". What happens is that all the fxml and image files are copied to the target directory but there is not a single class file. Because the information about the issue was very limited in STS (Spring development tool) I installed Maven 3.8.2. and tried to fix it from the command line. Based on the information and what I found in the inte.net I added org.codehaus.mojoversions-maven-plugin and org.apache.maven.plugins:maven-enforcer-plugin plus I tried with and without explicit version tags, since I got warnings as the versions are already defined in spring-boot-dependencies-2.5.4.pom.pom. So, when I run mvn versions:display-plugin-updates I find the outcome very confusing, since in the very end it states "BUILD SUCCESS" but if I scroll up, there is an Error message saying: "Project does not define required minimum version of Maven. Update the pom.xml to contain maven-enforcer-plugin to force the maven version which is needed to build this project". But this is what I did?. Please see below the current parent pom. Please let me know should you need more information. Thank you in advance for your help. Please have in mind that my expertise in Maven is rather limited, I understand the basics, when it gets to all these plugins. I get lost, Therefore. I would be grateful for "dummies" style answers.

 <?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.5.4</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>com.agiletunes</groupId>
<artifactId>agiletunes-parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>agiletunes-parent</name>
<description>Maven parent for all agileTunes modules</description>

<modules>
    <module>../agiletunes-productmanager</module>
    <module>../agiletunes-testmanager</module>
    <module>../agiletunes-shared</module>
    <module>../agiletunes-authserver</module>
    <module>../agiletunes-util</module>
</modules>

<properties>
    <java.version>11</java.version>
    <maven.compiler.release>11</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <!-- for testing Spring Boot applications with JUnit -->
    <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-mail</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-envers</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <scope>test</scope>
    </dependency>   

    <!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
    </dependency>
    
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>11</version>
    </dependency>
    
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <generateBackupPoms>false</generateBackupPoms>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
             <version>3.0.0</version>
            <executions>
                <execution>
                    <id>enforce-maven</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <requireMavenVersion>
                                <version>3.0</version>
                            </requireMavenVersion>
                        </rules>    
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

This is happening because what you defined in the configurations of the maven-enforcer-plugin actually maven-enforcer-plugin runs in the validation life cycle and when you run the mvn versions:display-plugin-updates with the below configurations what happen is,

<requireMavenVersion>
 <version>3.0.0</version>
</requireMavenVersion>

it will check the project maven version and then check the plugin versions, and you will get an error if the project minimum version is not compatible with the plugin versions.

[INFO] Project inherits minimum Maven version as: 3.0.0
[INFO] Plugins require minimum Maven version of: 3.1.1
[INFO] Note: the super-pom from Maven 3.6.3 defines some of the plugin
[INFO]       versions and may be influencing the plugins required minimum Maven
[INFO]       version.
[INFO]
[ERROR] Project requires an incorrect minimum version of Maven.
[ERROR] Update the pom.xml to contain maven-enforcer-plugin to
[ERROR] force the Maven version which is needed to build this project.
[ERROR] See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html
[ERROR] Using the minimum version of Maven: 3.0.0

so what you can do is change the version in the maven-enforcer-plugin to the project version.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>enforce-maven</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <requireMavenVersion>
                        <version>3.1.1</version>
                    </requireMavenVersion>
                </rules>
            </configuration>
        </execution>
     </executions>
  </plugin>

and after that, the error will be gone,

[INFO] Project inherits minimum Maven version as: 3.1.1
[INFO] Plugins require minimum Maven version of: 3.1.1
[INFO] Note: the super-pom from Maven 3.6.3 defines some of the plugin
[INFO]       versions and may be influencing the plugins required minimum Maven
[INFO]       version.
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

but actually you don't need maven-enforcer-plugin to define, I'm not sure if there is a list of plugins that don't need to be explicitly added, but I assume it's the most common ones like maven-surefire-plugin and maven-clean-plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM