mvn clean install 无法解析 class

mvn clean install not able to resolve class

我有以下maven结构

parent POM.XML
 - common/pom.xml
 - search/pom.xml

当我在 search 模块上执行 mvn clean install 时,搜索模块无法获取 common 模块 类 我得到 package de.test.common does not exists。我什至在父平台上 运行 mvn clean install 但没有成功。 common 模块正在构建中。

<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>de.test.search</groupId>
    <artifactId>search</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>de.test.platform</groupId>
        <artifactId>platform</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <properties>
        <app-name>search</app-name>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>de.test.common</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>searchdev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
        </profile>
        <profile>
            <id>searchprod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.heroku.sdk</groupId>
                        <artifactId>heroku-maven-plugin</artifactId>
                        <version>1.0.3</version>
                        <configuration>
                            <appName>${app-name}</appName>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
        </profile>
    </profiles>
</project>

普通pom

<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>de.test.common</groupId>
    <artifactId>common</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>de.test.platform</groupId>
        <artifactId>platform</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <properties>
        <app-name>common</app-name>
    </properties>
    <profiles>
        <profile>
            <id>commondev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
        </profile>
        <profile>
            <id>commonprod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.heroku.sdk</groupId>
                        <artifactId>heroku-maven-plugin</artifactId>
                        <version>1.0.3</version>
                        <configuration>
                            <appName>${app-name}</appName>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
        </profile>
    </profiles>
</project>

我想我遇到了这里提到的同样问题

maven compilation failure

找到问题但未找到原因

我把下面的依赖去掉就一切OK了

          <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

删除插件后,jar 以不同的结构构建。当 spring 启动插件在那里时,整个内容都在 BOOT-INF 文件夹中,我认为这是原因,但不确定...在这里需要专家意见。

解决这个问题的最简单方法是通过所谓的反应器项目,您可以在其中使用父 pom.xml 构建所有依赖模块。为此,将以下代码添加到您的父 POM 中:

<modules>
  <module>common</module>
  <module>search</module>
</modules>

现在,构建父 pPOM,您的整个构建应该可以正常工作。 另外,不要在子项目中使用显式版本,只从父 POM 继承版本(我认为你在那里很好)。如果您引用来自同一项目反应器的依赖项,请使用版本 ${project.version}.

找到解决方案。可能有人会发现它有用。

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>