如何使用Maven install-plugin以最小的配置安装pom

时间:2015-07-13 20:08:15

标签: maven maven-install-plugin

我正在使用Maven(2.2.1)install-plugin(2.5.2)来安装存储库中不可用的第三方依赖项。

当依赖项同时包含jar和pom时,install-plugin会读取pom文件并设置包装,groupId,artifactId和版本,因此我不需要指定它们:

<execution>
    <id>1</id>
    <phase>validate</phase>
    <goals>
        <goal>install-file</goal>
    </goals>
    <configuration>
        <file>si/odm/jrules-engine/8.5.1/jrules-engine-8.5.1.jar</file>
        <pomFile>si/odm/jrules-engine/8.5.1/jrules-engine-8.5.1.pom</pomFile>
    </configuration>
</execution>

但是,当依赖项只有一个pom文件时,它会强制我手动指定包装,groupId等:

<execution>
    <id>2</id>
    <phase>validate</phase>
    <goals>
        <goal>install-file</goal>
    </goals>
    <configuration>
        <packaging>pom</packaging>
        <groupId>odm</groupId>
        <artifactId>jrules-otherthing</artifactId>
        <version>8.5.1</version>
        <file>si/odm/jrules-otherthing/8.5.1/jrules-otherthing-8.5.1.pom</file>
    </configuration>
</execution>

当它是唯一安装的文件时,是否可以配置install-plugin来读取pom文件?

能够做到这一点会使配置更短,更易读。

我尝试在没有<pomFile>元素的<file>元素中指定pom文件,但install-plugin坚持认为我必须拥有<file>。我认为现在还不行,但我想在这里问我以防万一。

1 个答案:

答案 0 :(得分:0)

根据其他人的评论,以下是我使用 maven-install-plugin 使用 Maven 3.6.1 仅将 pom 安装到我的存储库中的方法:

    <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>3.0.0-M1</version>
                <configuration>
                    <groupId>com.microservice</groupId>
                    <artifactId>parent</artifactId>
                    <version>${revision}</version>
                    <packaging>pom</packaging>
                    <file>pom.xml</file>
                </configuration>
                <executions>
                    <execution>
                        <id>install-pom</id>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <phase>install</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>