英文:
Maven dependency plugin does not rebuild dependencies
问题
我有一个多模块项目,结构如下:
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>
然后:
- 在
moduleB
和moduleC
内的类中添加一些代码。 - 使用
cd
命令切换到my-project/moduleA
目录。 - 运行
mvn clean install -PwithArtifacts -DskipTests -am
最终,我在 ${project.build.directory}/lib
目录中有一些 JAR 文件,但它们不包含我在步骤(1)中的编辑内容。
为什么 Maven 在复制之前可能不会重新构建依赖项?
更新:
moduleB 的 pom.xml 如下:
英文:
I have multi-module project with structure like:
my-project
- moduleA
- moduleB
- moduleC
pom.xml for moduleA configured like:
<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>
Then:
- Add some code in classes inside
moduleB
andmoduleC
. cd
tomy-project/moduleA
.- Run
mvn clean install -PwithArtifacts -DskipTests -am
And finally I have jar files in ${project.build.directory}/lib
but they do not contain my edits from (1).
Why maven may do not rebuild dependencies before copy?
UPD:
pom.xml from moduleB:
答案1
得分: 1
你需要为此构建 所有 模块。转到主项目 my-project
并调用 mvn clean install
。您还需要确保 moduleA 依赖于 moduleB 和 moduleC,以确保构建顺序正确。
英文:
You need build all the modules for that. Go the main project my-project
and call mvn clean install
. You also need to make sure that moduleA depends on moduleB and moduleC so that the build order will be correct.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论