Maven:避免在标准构建生命周期中部署项目包隐含工件 [英] Maven: avoid deploying project package-implied artifact during standard build lifecycle

查看:136
本文介绍了Maven:避免在标准构建生命周期中部署项目包隐含工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以避免在'deploy:deploy'处理期间部署根据项目打包构建的工件?

Is it possible to avoid deploying the artifact that is built according to the project packaging during 'deploy:deploy' processing?

I表示以下内容:


  • 假设我们有一个用于Web应用程序的'pom.xml'并将包装类型定义为'war';

  • 我们要组装'*。war'工件或'*。zip'包含我们的应用程序以及servlet容器;

  • 我们希望在'部署期间仅部署'*。zip'工件:部署'处理;

  • suppose we have a 'pom.xml' for web application and define packaging type as 'war';
  • we want to assemble either '*.war' artifact or '*.zip' that contains our application as well as a servlet container;
  • we want to deploy only that '*.zip' artifact during 'deploy:deploy' processing;

即我希望能够运行'mvn deploy'并得到以下结果:

I.e. I want to be able to run 'mvn deploy' and has the following results:


  1. ' myapp.war'已构建;

  2. 'myapp-standalone.zip'已构建;

  3. 'myapp-standalone.zip'部署到目标远程存储库(请注意,如果'myapp.war'安装到本地存储库,我不会烦恼) ;

  1. 'myapp.war' is constructed;
  2. 'myapp-standalone.zip' is constructed;
  3. 'myapp-standalone.zip' is deployed to the target remote repository (note that I don't bother if 'myapp.war' is installed to the local repository here);

我检查了'war:war documentation'并找到'primaryArtifact'参数。但是,它只提到了本地存储库。

I checked 'war:war documentation' and found 'primaryArtifact' parameter. However, it mentions only local repository.

我尝试了以下POM但它仍然部署了'* .war'' * .zip'到远程存储库:

I tried the following POM but it still deploys either '*.war' or '*.zip' to remote repository:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mygroup</groupId>
    <artifactId>myapp</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>myapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <!-- dependencies go here -->
    </dependencies>

    <build>
        <plugins>
            <! -- plugins like 'compiler' etc -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <primaryArtifact>false</primaryArtifact>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>myapp-standalone</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/standalone.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <repository>
            <-- target repository information -->
        </repository>
        <snapshotRepository>
            <-- target repository information -->
        </snapshotRepository>
    </distributionManagement>
</project>

似乎我可以通过将项目包装声明为'pom'来获得所需的行为并手动配置'war'打包所暗示的所有mojos('resources:resources''compiler:compile' 'resources:testResources''compiler:testCompile''surefire:test''war:war''install:install''deploy:deploy')。然而,这会让POM变得相当冗长,我想避免这种情况。

It seems that I can get desired behavior via declaring project packaging as 'pom' and manually configuring all mojos implied by 'war' packaging ('resources:resources', 'compiler:compile', 'resources:testResources', 'compiler:testCompile', 'surefire:test', 'war:war', 'install:install', 'deploy:deploy'). However, that would make the POM rather verbose and I'd like to avoid that.

据我所知,Maven的方式是总是有项目隐含的工件包装类型作为项目工件之一。但是,如果他或她想要获得与任何默认打包类型不匹配的工件(例如单个'*。zip'存档),则不清楚Maven用户应该做什么。

As far as I understand, Maven way is to always have an artifact implied by project packaging type as a one of project artifacts. But it's not clear what Maven user is expected to do if he or she wants to get an artifact that is not matched to any default packing types (e.g. single '*.zip' archive).

有什么想法?

问候,Denis

推荐答案

根据 Maven Deploy Plugin 文档:


deploy:deploy 用于自动安装工件,其pom以及特定项目生成的附加工件。 [...]

deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project. [...]

所以我认为不可能阻止你的战争按原样部署。

So I don't think it's possible to prevent your war from being deployed "as is".

但是,为了获得所需的效果,您可以在构建中添加一个特定的模块来负责生成程序集(程序集将取决于war模块)和将war模块中的deploy插件配置为跳过部署如下:

However, to obtain the desired effect, you could add a specific module to your build that would be in charge of producing the assembly (the assembly would depend on the war module) and configure the deploy plugin in the war module to skip deployment as follows:

         <plugin>
           <artifactId>maven-deploy-plugin</artifactId>
           <version>X.Y</version>
           <configuration>
             <skip>true</skip>
           </configuration>
         </plugin>

这篇关于Maven:避免在标准构建生命周期中部署项目包隐含工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆