我们可以使用versions-maven-plugin获取在<dependencymanagement>导入范围中指定的POM的最新版本吗?

时间:2019-05-16 06:30:25

标签: maven import dependency-management versions-maven-plugin

我准备了一个commonimport POM,它具有我所有项目依赖的版本。现在,我想在项目POM中始终使用最新版本的commonimport POM。我正在尝试使用versions-maven-plugin实现它,但它没有选择commonimport POM的最新版本。 我们如何通过版本-maven-plugin实现这一目标? 我们可以通过其他任何方式实现这一目标吗?

通用POM版本#1.0:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>commonimport</groupId>
        <artifactId>commonimport-artifact</artifactId>
        <version>1.0</version>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>group-a</groupId>
                    <artifactId>artifact-a</artifactId>
                    <version>1.0</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>

通用POM版本#2.0:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>commonimport</groupId>
        <artifactId>commonimport-artifact</artifactId>
        <version>2.0</version>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>group-a</groupId>
                    <artifactId>artifact-a</artifactId>
                    <version>2.0</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>

项目-一个POM:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>project-a</groupId>
        <artifactId>project-a-artifact</artifactId>
        <version>1.0</version>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.7</version>
                    <configuration>
                        <includes>
                            <include>commonimport:commonimport-artifact</include>
                        </includes>
                        <excludes>
                            <exclude>org.apache.commons:commons-collections4</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.dstovall</groupId>
                    <artifactId>onejar-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>one-jar</goal>
                            </goals>
                            <configuration>
                                <onejarVersion>2.0.6</onejarVersion>
                                <mainClass>com.projecta.ProjectA</mainClass>
                                <urlFactory>com.simontuffs.onejar.JarClassLoader$OneJarURLFactory</urlFactory>
                                <filename>${project.artifactId}-one-jar-${project.version}.jar</filename>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </build>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>commonimport</groupId>
                    <artifactId>commonimport-artifact</artifactId>
                    <version>1.0</version>
                    <scope>import</scope>
                    <type>pom</type>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
               <groupId>group-a</groupId>
               <artifactId>artifact-a</artifactId>
            </dependency>
        </dependencies>
    </project>

当我在project-a的命令下运行时,我希望它可以获取commonimport POM的最新版本,即版本#2。

MVN版本:use-latest-releases全新安装

0 个答案:

没有答案