Maven依赖插件不会重建依赖关系

时间:2020-03-15 13:07:35

标签: java maven

我有一个结构类似的多模块项目:

my-project
 - moduleA
 - moduleB
 - moduleC

针对moduleA的pom.xml配置如下:

<profiles>
    <profile>
        <id>withArtifacts</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>

                    <dependencies>
                        <dependency>
                            <groupId>com.ekiryuhin</groupId>
                            <artifactId>moduleB</artifactId>
                            <version>${project.version}</version>
                        </dependency>

                        <dependency>
                            <groupId>com.ekiryuhin</groupId>
                            <artifactId>moduleC</artifactId>
                            <version>${project.version}</version>
                        </dependency>
                    </dependencies>

                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <includeArtifactIds>
                                    moduleB,moduleC
                                </includeArtifactIds>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

然后:

  1. moduleBmoduleC内部的类中添加一些代码。
  2. cdmy-project/moduleA
  3. 运行mvn clean install -PwithArtifacts -DskipTests -am

最后,我在${project.build.directory}/lib中有jar文件,但是它们不包含我对(1)的编辑。

为什么Maven在复制之前可能不重建依赖关系?

UPD:

来自moduleB的pom.xml:

1 个答案:

答案 0 :(得分:1)

您需要为此构建 all 模块。转到主项目my-project,然后调用mvn clean install。您还需要确保moduleA依赖moduleB和moduleC,以便构建顺序正确。