2010-11-04 15 views
6

我在尝试设置项目以部署到内部联系存储库时目前遇到问题。由于我对整个Maven都比较陌生,因此我认为在如何建立分销管理方面我并没有真正理解的东西。为什么Maven(错误地?)将我的SNAPSHOT部署到版本库和快照库?

基本问题是,当我执行“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> 

其他地方我有以下设置为允许使用这些存储库中获得文物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> 

我在我的settings.xml中有正确的设置来提供证书,以便能够发布到我的计算机上运行的此测试nexus实例,并且实际上它正在成功部署快照。

的问题是,它也试图部署快照释放存储库,它被配置为禁止快照。

从“MVN部署”输出包括以下内容:

[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 

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 

回答

5

所以最好的线索其实原来是正确的日志在我的眼前。我曾经想过的唯一的工件是由我正在使用的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> 

请注意,这实际上是直接引用${project.distributionManagement.repository.url}。另外,这种配置有些误导,应该通过war插件的attachClasses属性来完成。

2

难道是因为神器版本没有-SNAPSHOT后缀?

+0

的神器版本是1.0.0,快照,因此没有。 – imaginaryboy 2010-11-06 02:52:56

+1

这个答案应该是一个评论,我想 – 2016-03-11 16:11:17

9
  1. 定义下列财产在你的POM Maven的部署,插件

    <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl> 
    
  2. 更改配置如下:

    <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> 
    
  3. 添加以下配置文件设定与存储库中的deployFileUrl财产网址

    <profiles> 
        <profile> 
         <id>release-mode</id> 
         <properties> 
          <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl> 
         </properties> 
        </profile> 
    </profiles> 
    
  4. 最后调用此配置文件中的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> 
    
相关问题