Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Maven(错误地)将我的快照部署到发行版和快照存储库中?_Maven_Maven Deploy Plugin - Fatal编程技术网

为什么Maven(错误地)将我的快照部署到发行版和快照存储库中?

为什么Maven(错误地)将我的快照部署到发行版和快照存储库中?,maven,maven-deploy-plugin,Maven,Maven Deploy Plugin,我当前在尝试设置要部署到内部nexus存储库的项目时遇到问题。一般来说,我对Maven还比较陌生,所以我希望在如何建立分销管理方面,有些东西我还不太了解 基本问题是,当我执行“mvn deploy”时,工件被成功地部署到快照存储库中,但Maven也试图将其部署到发布存储库中,这是失败的。。。应该如此。我对当前配置的理解是,它不应该也将其部署到发布存储库中 我已经在下面介绍了各种配置元素,但我想知道我是否真的应该使用概要文件来管理该部分,以便只定义快照构建,而只定义发布构建 如果您对此有任何帮助/

我当前在尝试设置要部署到内部nexus存储库的项目时遇到问题。一般来说,我对Maven还比较陌生,所以我希望在如何建立分销管理方面,有些东西我还不太了解

基本问题是,当我执行“mvn deploy”时,工件被成功地部署到快照存储库中,但Maven也试图将其部署到发布存储库中,这是失败的。。。应该如此。我对当前配置的理解是,它不应该也将其部署到发布存储库中

我已经在下面介绍了各种配置元素,但我想知道我是否真的应该使用概要文件来管理该部分,以便只定义快照构建,而只定义发布构建

如果您对此有任何帮助/澄清,我们将不胜感激

我的POM中有以下内容用于分销管理:

<distributionManagement>
<repository>
  <id>internal-releases</id>
  <name>Internal Releases</name>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
  <id>internal-snapshots</id>
  <name>Internal Snapshots</name>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Nexus的日志包含以下内容(如我所料):


可能是因为工件版本没有
-SNAPSHOT
后缀吗?

所以最好的线索实际上就在日志中我眼前。我认为唯一的工件是由我使用的POM生成的.war,但是您会在日志中注意到Maven试图部署到发行版的工件实际上是一个.jar

这是一个足够的指针(Maven用户邮件列表中有人提供了这个指针),可以查找并最终发现有人在部署阶段包含了以下额外的配置

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
  <phase>deploy</phase>
    <goals>
      <goal>deploy-file</goal>
    </goals>
    <configuration>
      <packaging>jar</packaging>
      <generatePom>true</generatePom>
      <url>${project.distributionManagement.repository.url}</url>
      <artifactId>${project.artifactId}</artifactId>
      <groupId>${project.groupId}</groupId>
      <version>${project.version}</version>
      <file>${project.build.directory}/${project.build.finalName}.jar</file>
    </configuration>
  </execution>
</executions>
</plugin>

org.apache.maven.plugins
maven部署插件
部署
部署文件
罐子
真的
${project.distributionManagement.repository.url}
${project.artifactId}
${project.groupId}
${project.version}
${project.build.directory}/${project.build.finalName}.jar
请注意,这实际上是直接引用
${project.distributionManagement.repository.url}
。此外,这种配置有些误导,应该通过war插件的
attachClasses
属性来实现

  • 在pom中定义以下属性

    <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
    
    ${project.distributionManagement.snapshotRepository.url}
    
  • 将maven部署插件的配置更改如下:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <skip>true</skip>
        </configuration>
        <executions>
            <execution>
                <phase>deploy</phase>
                <configuration>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                    <url>${deployFileUrl}</url>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                </configuration>
                <goals>
                    <goal>deploy-file</goal>
                </goals>
            </execution>
         </executions>
     </plugin>
    
    
    org.apache.maven.plugins
    maven部署插件
    2.5
    真的
    部署
    罐子
    真的
    ${deployFileUrl}
    ${project.artifactId}
    ${project.groupId}
    ${project.version}
    ${project.build.directory}/${project.build.finalName}.jar
    部署文件
    
  • 添加以下配置文件以使用存储库url设置deployFileUrl属性

    <profiles>
        <profile>
            <id>release-mode</id>
            <properties>
                <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
            </properties>
        </profile>
    </profiles>
    
    
    释放模式
    ${project.distributionManagement.repository.url}
    
  • 最后在maven发布插件中调用此配置文件

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.0-beta-9</version>
        <configuration>
            <releaseProfiles>release-mode</releaseProfiles>
        </configuration>
     </plugin>
    
    
    org.apache.maven.plugins
    maven发布插件
    2.0-beta-9
    释放模式
    

  • 工件版本是1.0.0-SNAPSHOT,所以不是。我认为这个答案应该是一个注释
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <skip>true</skip>
        </configuration>
        <executions>
            <execution>
                <phase>deploy</phase>
                <configuration>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                    <url>${deployFileUrl}</url>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                </configuration>
                <goals>
                    <goal>deploy-file</goal>
                </goals>
            </execution>
         </executions>
     </plugin>
    
    <profiles>
        <profile>
            <id>release-mode</id>
            <properties>
                <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
            </properties>
        </profile>
    </profiles>
    
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.0-beta-9</version>
        <configuration>
            <releaseProfiles>release-mode</releaseProfiles>
        </configuration>
     </plugin>