【问题标题】:How to deploy only zip artifacts in maven如何在 Maven 中仅部署 zip 工件
【发布时间】:2014-08-22 07:21:43
【问题描述】:

我使用下面的描述符和 pom 文件在 maven 中做了一些 zip 打包。但在 Maven 中,默认情况下它在目标文件夹中创建了 jar 和 zip。现在我只想在我使用 deploy:deploy-file 插件的地方部署 zip 内容。但它没有部署,而是显示错误。不知道标签出了什么问题以及应该如何解决。

Pom 文件:

<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.wyndhamvo.prototype.dbscripts</groupId>
  <artifactId>DB_SCRIPTS</artifactId>
  <version>2.0.0.1</version>


<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptor>src/assembly/descriptor.xml</descriptor>
            </configuration>
            <executions> 
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <distributionManagement>
    <snapshotRepository>
        <id>wvoNexus</id>
        <file>${project.artifactId}-${project.version}.zip</file>
        <url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>

    <repository>
        <id>wvoNexus</id>
        <file>${project.artifactId}-${project.version}.zip</file>
        <url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
    </repository>
  </distributionManagement>

</project>

程序集插件描述符文件:

<assembly>
<formats>
    <format>zip</format>
</formats>

<fileSets>
    <fileSet>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*</include>
        </includes>
        <outputDirectory>DB_Files</outputDirectory>
    </fileSet>
</fileSets>
</assembly>

执行的命令:

mvn -X clean package deploy:deploy-file

错误:

[ERROR] Malformed POM C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml: Unrecognised tag: 'file' (position: START_TAG seen ...<id>wvoNexus</id>\r\n\t\t\t<file>... @37:10)  @ C:\Divakar\MavenPrototype\DB_Maven_Test\dev\pom.xml, line 37, column 10

【问题讨论】:

    标签: maven maven-plugin maven-deploy-plugin


    【解决方案1】:

    首先,您必须像这样修复分布管理区域中的错误:

      <distributionManagement>
        <snapshotRepository>
            <id>wvoNexus</id>
            <url>http://nexus.corproot.com/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    
        <repository>
            <id>wvoNexus</id>
            <url>http://nexus.corproot.com/nexus/content/repositories/releases/</url>
        </repository>
      </distributionManagement>
    

    如果您解决了这个问题,您可以通过以下方式简单地将文件部署到您的关系:

    mvn clean deploy
    

    如果您不喜欢同时部署 jar,则需要更改 pom 中的包装类型,如下所示:

    <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.wyndhamvo.prototype.dbscripts</groupId>
      <artifactId>DB_SCRIPTS</artifactId>
      <version>2.0.0.1</version>
      <packaging>pom</packaging>
    
    
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <descriptor>src/assembly/descriptor.xml</descriptor>
                    </configuration>
                    <executions> 
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    此外,我建议您像这样定义您使用的插件的版本:

        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <descriptor>src/assembly/descriptor.xml</descriptor>
                    </configuration>
                    <executions> 
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    【讨论】:

    • 谢谢@khmarbaise。有效。但没有部署在快照存储库中。 http://nexus.corproot.com/nexus/content/repositories/releases/com/wynd hamvo/prototype/dbscripts/DB_SCRIPTS/2.0.0.1/DB_SCRIPTS-2.0.0.1.zip (3 KB at 63. 8 KB/sec)
    • 当然不是因为您定义了发布版本而NOT SNAPSHOT 版本。
    • 对不起。无法得到你。我在 distributionManagement 标记中定义了发布和快照。我还需要在某个地方定义吗?或者我的 pom 文件有问题。
    • 您在 &lt;version&gt;2.0.0.1&lt;/version&gt; 中定义,这是从 Mavne 的角度来看的发布版本。如果您喜欢 SNAPSHOT,则需要定义 &lt;version&gt;2.0.0.1-SNAPSHOT&lt;/version&gt;
    【解决方案2】:

    你弄错了:&lt;file/&gt; 元素不是&lt;snapshotRepository/&gt; 的一部分,它是部署插件的配置项!您应该按如下方式部署您的 zip 文件:

    mvn -X clean package deploy:deploy-file -Dfile=/path/to/your-artifact-1.0.zip
    

    【讨论】:

      【解决方案3】:
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <version>3.3.0</version>
          <executions>
            <execution>
              <id>attach-artifacts</id>
              <phase>package</phase>
              <goals>
                <goal>attach-artifact</goal>
              </goals>
              <configuration>
                <artifacts>
                  <artifact>
                    <file>some file</file>
                    <type>extension of your file </type>
                    <classifier>optional</classifier>
                  </artifact>
                </artifacts>
              </configuration>
            </execution>
          </executions>
        </plugin>
      

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2010-12-24
      • 2020-12-30
      • 1970-01-01
      • 2011-12-26
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      相关资源
      最近更新 更多