ima*_*boy 6 maven maven-deploy-plugin
我正在尝试设置项目以部署到内部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>
Run Code Online (Sandbox Code Playgroud)
在POM的其他地方,我有以下设置允许使用这些存储库来获取工件:
<repositories>
<repository>
<id>internal-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>internal-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- other repos, etc, etc -->
</repositories>
Run Code Online (Sandbox Code Playgroud)
我在settings.xml中有正确的设置,以提供能够发布到我的计算机上运行的此测试nexus实例的凭据,并且它实际上已成功部署快照.
问题是它还尝试将快照部署到发布存储库,该存储库配置为禁止快照.
"mvn deploy"的输出包括以下内容:
[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from internal-snapshots
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war
405K uploaded (service-1.0.0-20101104.170338-8.war)
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT'
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'artifact com.internal:service'
[INFO] Uploading project information for service 1.0.0-20101104.170338-8
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400
Run Code Online (Sandbox Code Playgroud)
来自Nexus的日志包含以下内容(正如我所期望的那样):
jvm 1 | 2010-11-04 13:03:39 INFO [p-759477796-118] - o.s.n.p.m.m.M2Repos~ - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1 | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~ - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
Run Code Online (Sandbox Code Playgroud)
小智 9
在pom中定义以下属性
<deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
Run Code Online (Sandbox Code Playgroud)更改maven-deploy-plugin的配置如下:
<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>
Run Code Online (Sandbox Code Playgroud)添加以下配置文件以使用存储库URL设置deployFileUrl属性
<profiles>
<profile>
<id>release-mode</id>
<properties>
<deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
</properties>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)最后在maven-release-plugin中调用此配置文件
<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>
Run Code Online (Sandbox Code Playgroud)所以最好的线索实际上在我的眼前是正确的.我曾经想过的唯一一个我正在使用的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>
Run Code Online (Sandbox Code Playgroud)
请注意,这实际上是直接引用${project.distributionManagement.repository.url}.此外,这种配置有点误导,应该通过attachClasseswar插件的属性实现.
| 归档时间: |
|
| 查看次数: |
15965 次 |
| 最近记录: |