如何始终在 maven 3.x 中获取特定依赖项的最新版本?

How to always get the latest version of an specific dependency in maven 3.x?

我有一个带有大型 pom 文件的 Maven 项目,我希望我的依赖项之一始终是部署到我们本地反工厂服务器的最新版本。

这个依赖项的名称是“WebInfra”,我使用 maven 3.x 所以“LATEST”关键字对我不起作用。

我会把 pom 文件放在这里,我很乐意找到这个问题的解决方案。我需要其他依赖项保持其固定版本,并且每次调用 mvn clean deploy 时只有这个依赖项应该升级到最新版本。 我看到 "Versions Maven Plugin" 并设置了它的包含和排除但对我不起作用: 我有 webinfra-1.jar 然后我将 webinfra-2.0-SNAPSHOT 部署到 artifactory 服务器但是当我 运行 mvn versions:use-latest-versions 没有任何反应。我希望我的 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/maven-v4_0_0.xsd">

  <!-- POM file generated with GWT webAppCreator -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.dpdouran.web</groupId>
  <artifactId>WebERP</artifactId>
  <packaging>war</packaging>
  <version>1.3-SNAPSHOT</version>
  <name>WebERP</name>

  <distributionManagement>
    <repository>
      <id>Douranrepository</id>
      <name>Douranrepository</name>
      <url>http://192.168.100.243:8082/artifactory/Douranrepository/</url>
    </repository>
  </distributionManagement>

  <repositories>
    <repository>
      <id>Douranrepository</id>
      <name>Douranrepository</name>
      <url>http://192.168.100.243:8082/artifactory/Douranrepository/</url>
    </repository>
  </repositories>

  <properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.5.1</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <!-- Defaults -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwtVersion}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwtVersion}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
      <classifier>sources</classifier>
      <scope>test</scope>
    </dependency>
    <!-- thirdparties -->
    <dependency>
      <groupId>org.thirdparty.grouped</groupId>
      <artifactId>Thridparty</artifactId>
      <version>1</version>
    </dependency>
    <!-- Douran artifacts -->
    <dependency>
      <groupId>org.dpdouran.accounting</groupId>
      <artifactId>accounting</artifactId>
      <version>1</version>
    </dependency>


    <dependency>
      <groupId>org.dpdouran.bi</groupId>
      <artifactId>WebAnalytic</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.bi</groupId>
      <artifactId>WebDashboard</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.bi</groupId>
      <artifactId>ireport</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.bi</groupId>
      <artifactId>reporting</artifactId>
      <version>1</version>
    </dependency>


    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>WebCommon</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>baseinfo</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>coding</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>common</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>custom-editor</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>filemanager</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>formula</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>image</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>oa</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>webfilemanager</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.common</groupId>
      <artifactId>weboa</artifactId>
      <version>1</version>
    </dependency>


    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>BFonts</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>DecisionTable</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>ITIL</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>configfiles</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>db</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>dynamicreports</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.custom</groupId>
      <artifactId>encrypt</artifactId>
      <version>1</version>
    </dependency>



    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Attendanc</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Command</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Common</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Evaluation</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Knowledge</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_PayRoll</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Personnel</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Pishnehadat</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Recruitment</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Refahi</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>HR_Training</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>WebHumanResource</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.humanresource</groupId>
      <artifactId>organizationchart</artifactId>
      <version>1</version>
    </dependency>



    <dependency>
      <groupId>org.dpdouran.infrastructure</groupId>
      <artifactId>Infra</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.infrastructure</groupId>
      <artifactId>WebInfra</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.infrastructure</groupId>
      <artifactId>WebInfraService</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.infrastructure</groupId>
      <artifactId>webskin</artifactId>
      <version>1</version>
    </dependency>



    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>WebSupport</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>production</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>projectmanagement</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>realestate</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>risk_management</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.logistics</groupId>
      <artifactId>support</artifactId>
      <version>1</version>
    </dependency>



    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>Manager</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>NetworkCommon</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>NetworkGraph</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>NetworkMonitoringUI</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>NetworkUtil</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>NetworkWebService</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>WebNetworkDiscovery</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>WebNetworkMonitoring</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>WebStockChart</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.network</groupId>
      <artifactId>websocket-api</artifactId>
      <version>1</version>
    </dependency>



    <dependency>
      <groupId>org.dpdouran.workflow</groupId>
      <artifactId>WebCartable</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.workflow</groupId>
      <artifactId>cartable</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.workflow</groupId>
      <artifactId>workflow</artifactId>
      <version>1</version>
    </dependency>
    <dependency>
      <groupId>org.dpdouran.workflow</groupId>
      <artifactId>webworkflow</artifactId>
      <version>1</version>
    </dependency>

  </dependencies>

  <build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

    <plugins>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
          <includes>
            <include>org.dpdouran.infrastructure:*</include>
          </includes>
          <excludes>
            <exclude>org.codehaus.plexus:plexus-utils</exclude>
            <exclude>com.google.gwt:*</exclude>
            <exclude>javax.validation:*</exclude>
            <exclude>org.codehaus.mojo:*</exclude>
            <exclude>org.apache.maven.plugins:*</exclude>
          </excludes>
        </configuration>
      </plugin>



      <!-- GWT Maven Plugin -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>2.5.1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <!-- <goal>test</goal>
              <goal>i18n</goal>
              <goal>generateAsync</goal> -->
            </goals>
          </execution>
        </executions>
        <!-- Plugin configuration. There are many available options, see 
          gwt-maven-plugin documentation at codehaus.org -->
        <configuration>
          <extraJvmArgs>-Xmx8192M -Xss2048M </extraJvmArgs>
          <!-- -Dfoo=bar -->
          <runTarget>WebERP.html</runTarget>
          <hostedWebapp>${webappDirectory}</hostedWebapp>
          <!-- <i18nMessagesBundle>org.dpdouran.web.client.Messages</i18nMessagesBundle> -->
        </configuration>
      </plugin>

      <!-- Copy static web files before executing gwt:run -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>exploded</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <webappDirectory>${webappDirectory}</webappDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

您需要分别运行两次 Maven:

  1. 在命令行上使用 versions maven 插件更新版本。
  2. 运行 类似于 mvn clean verify 来构建项目。

您不能在构建项目时更改版本。

顺便说一句:你配置了 Java 5. 你真的确定要这个吗?