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

How to prevent specifying the versions of sibling modules in maven-assembly-plugin?

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

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

我需要 assemble 'service-1' 和 'service-2' 模块 'service-aggregator'。我正在使用 maven-assembly-plugin 并且它工作正常,但是我预见到维护问题,其中每当 service-1 或 service-2 的版本发生变化时,我将需要更新服务聚合器 pom.xml还有。

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

我已经完成了 maven-assembly-plugin documentation 中提供的示例,但这些示例包含组装模块(在我的示例中为服务聚合器)中提到的版本。

如果有任何细节遗漏,请告诉我,我会添加。

这里是 service-aggregator 的关键内容 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>