【问题标题】:mvn clean install not able to resolve classmvn clean install 无法解析类
【发布时间】:2017-01-05 06:57:53
【问题描述】:

我有以下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>

普通绒球

<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

找到问题但没有找到原因

我删除了以下依赖,一切正常

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

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

【问题讨论】:

  • 您是否安装了“通用”模块(到本地存储库 - mvn clean install)
  • 是的,我在 \.m2\repository\de\test\common\common\0.0.1-SNAPSHOT 下有 jar
  • 粘贴“common”的pom...
  • 粘贴先生。请看一下。
  • 有点奇怪,我刚刚用上面相同的设置运行 mvn clean install 运行良好

标签: maven pom.xml parent-pom


【解决方案1】:

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

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

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

【讨论】:

  • 我已经在父 POM 中定义了 sn-p,更糟糕的是父 pom 构建正在破坏搜索模块,抱怨公共模块不存在....
  • 更新了 reactor 控制台......它总是在导入公共模块的项目中中断。
  • 查看更新。 spring boot 插件引起了问题。不知道为什么。
【解决方案2】:

找到了解决办法。可能有人会觉得它有用。

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

【讨论】:

  • 它的作用是在 Spring Boot Jar 的末尾附加指定的分类器,同时保持非 Boot Jar 不变。这样依赖的模块就可以得到它的依赖。 Spring Boot Jar 以依赖模块无法加载重新打包的 jar 类的方式重新打包。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-08
  • 2014-03-30
  • 2011-08-26
  • 2012-10-08
  • 2013-05-12
  • 2014-08-06
相关资源
最近更新 更多