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

时间:2017-08-17 16:11:51

标签: java maven maven-assembly-plugin

我项目的简化设置如下:

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

我需要组装'service-1'和& 'service-aggregator'中的'service-2'模块。我正在使用maven-assembly-plugin并且它工作正常,但是我预见到维护问题,其中每当service-1或service-2的版本都将改变时,我将需要更新service-aggregator pom。 xml也。

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

我已经浏览了maven-assembly-plugin documentation中提供的示例,但这些示例包含了程序集模块中提到的版本(我的示例中为service-aggregator)。

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

以下是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>

1 个答案:

答案 0 :(得分:1)

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

<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>