在编译子项目时,使maven使用当前代码而不是已安装的版本

时间:2017-01-25 11:07:09

标签: java maven

我有一个maven项目P,它由几个子模块s1,s2组成......为了使这项工作,我有以下目录结构:

P
|_pom.xml
|_s1
  |_pom.xml
|_..
|_sN
  |_pom.xml

在父pom.xml中,我有一个正常的maven设置:

<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>P</artifactId>
  <version>0.1.0</version>
  <packaging>pom</packaging>
  <name>P</name>
  <modules>
    <module>s1</module>
    <module>s2</module>
    <!-- ... -->
    <module>sN</module>
  </modules>
  <!-- Repos and dependencies go here -->
</project>

并且,对于每个子项目,pom.xml与此类似:

<project xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.company</groupId>
    <artifactId>P</artifactId>
    <version>0.1.0</version>
  </parent>
  <groupId>com.company</groupId>
  <artifactId>s1</artifactId>
  <version>0.1.0</version>
  <packaging>jar</packaging>

  <dependencies>
    ...
  </dependencies>
</project>

此外,在项目中,我有一些模块间依赖关系,因此例如s4可能需要s1 s2和s5。为了使这项工作,我将子模块列为其他子模块的依赖性,例如,在s4的pom.xml中我会:

<dependencies>
  <dependency>
    <groupId>com.company</groupId>
    <artifactId>s1</artifactId>
    <version>0.1.0</version>
  </dependency>
  ...
</dependencies>

此设置的问题在于,每当我编译其中一个子模块项目时,除非先前已使用mvn install安装,否则不会看到其他子模块中的更改。这是有道理的,因为我列出了具有特定版本的模块间依赖关系,并且maven转到.m2文件夹中的本地存储库来查找它们。

有没有办法告诉maven我负责所有这些项目,并且只要有变化就应该递归地编译其他相关的子模块?

0 个答案:

没有答案