【问题标题】:Installing and deploying a maven artifact with version constructed by custom properties使用由自定义属性构建的版本安装和部署 Maven 工件
【发布时间】:2023-03-15 07:15:01
【问题描述】:

我有一个 Maven 项目,它生成一个 WAR 文件并尝试从代码库中维护的 .properties 文件中的属性中获取工件版本。我还尝试使用自定义属性来形成 WAR 文件的最终名称。

片段:

<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>com.xyz.webapps</groupId>
  <artifactId>webapps</artifactId>
  <version>${info.version}-${application.env}</version>
  <packaging>war</packaging>
  <!-- Filling in the artifact version with properties read below -->

   ...

  <!-- Filling in the WAR name -->
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <maven.war.final.name>${pom.artifactId}-${pom.currentVersion}.war</maven.war.final.name>
     <maven.test.skip>true</maven.test.skip>
   </properties>

 ...

 <build>
   <plugins>

   ...

   <!-- I read those properties files here -->
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>${project.basedir}/webapps-main/src/main/resources/MessageResources.properties</file>
            <file>${project.basedir}/build.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

  ...

 </plugins>

...
</project>

当我执行“mvn clean package”时,WAR 文件的名称会正确生成:

[INFO] Assembling webapp[webapps] in [/home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/jubuntu/workspace/ui/new/webapps/webapps-main/src/main/webapp]
[INFO] Webapp assembled in [4690 msecs]
[INFO] Building war: /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war

但是当我执行“mvn clean install”(或“mvn clean deploy”)时,由于某种原因属性没有扩展(包阶段仍然生成具有正确名称的WAR):

[INFO] Building war: /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war
[INFO] [install:install {execution: default-install}]
[INFO] Installing /home/jubuntu/workspace/ui/new/webapps/target/webapps-2.8-qa.war to /home/jubuntu/.m2/repository/com/xyz/webapps/webapps/${info.version}-${application.env}/webapps-${info.version}-${application.env}.war

我在这里做错了什么吗?我将如何使这项工作用于安装和部署我的工件?我使用 Maven 版本 2.2.1 进行构建。谢谢。

【问题讨论】:

    标签: maven-2 maven-deploy-plugin maven-install-plugin


    【解决方案1】:

    你不能这样做。 Maven 不支持它。这是基本的。

    【讨论】:

    • 感谢您的快速回复!我不知道这是 Maven 中无法覆盖的基本功能。看起来快照必须这样做。
    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2012-03-05
    • 2015-01-05
    • 1970-01-01
    相关资源
    最近更新 更多