如何防止在 maven-assembly-plugin 中指定同级模块的版本?



我的项目的简化设置如下:

root |--parent |--service-1 |--service-2 |--service-aggregator

我需要在"服务聚合器"中组装"服务-1"和"服务-2"模块。我正在使用 maven-assembly-plugin 进行相同的工作,它工作正常,但是我预见到一个维护问题,每当服务-1 或服务-2 的版本发生变化时,我都需要更新服务聚合器pom.xml。

因此,我正在寻找一种方法来防止在服务聚合器 pom 中编写 service-1/-2 的版本.xml即我只需要服务聚合器简单地选择最新版本的服务-1/-2。

我已经浏览了 maven-assembly-plugin 文档中提供的示例,但这些示例包含程序集模块中提到的版本(在我的示例中为服务聚合器(。

如果缺少任何细节,请告诉我,我会添加它。

以下是服务聚合器pom.xml的关键内容:

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company.project</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.company.project.parent</groupId>
<artifactId>service-aggregator</artifactId>
<name>service-aggregator</name>
<dependencies>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-1</artifactId>
<version>0.0.1</version> <!-- this is the line troubling me -->
</dependency>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-2</artifactId>
<version>0.0.1</version> <!-- this is the line troubling me -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<skip.assembly>false</skip.assembly>
</properties>

最好的办法是使用这样的属性:

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company.project</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.company.project.parent</groupId>
<artifactId>service-aggregator</artifactId>
<name>service-aggregator</name>
<dependencies>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-1</artifactId>
<version>${project.version}</version> 
</dependency>
<dependency>
<groupId>com.company.project.parent</groupId>
<artifactId>service-2</artifactId>
<version>${project.version}</version> 
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

最新更新