java - 马文 : avoid deploying project package-implied artifact during standard build lifecycle

标签 java maven-2

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

我的意思是:

  • 假设我们有一个用于 Web 应用程序的 'pom.xml' 并将打包类型定义为 'war'
  • 我们想要组装包含我们的应用程序和 servlet 容器的'*.war' 工件或'*.zip'
  • 我们只想在'deploy:deploy' 处理过程中部署那个'*.zip' 工件;

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

  1. 'myapp.war' 构建完成;
  2. 'myapp-standalone.zip' 构建完成;
  3. 'myapp-standalone.zip' 部署到目标远程存储库(请注意,如果 'myapp.war' 安装到本地,我不会打扰存储库在这里);

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

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

<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 变得相当冗长,我想避免这种情况。

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

有什么想法吗?

问候,丹尼斯

最佳答案

根据 Maven Deploy Plugin 文档:

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

所以我认为不可能阻止您的 war “按原样”部署。

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

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

关于java - 马文 : avoid deploying project package-implied artifact during standard build lifecycle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1559388/

相关文章:

java - 使用 Maven 构建项目时缺少 JUNIT Jar 异常

Maven + Surefire/Failsafe - forkMode ="perthread"不起作用...解决方法?

java - 如何转换 Map 中的键/值

java - 使用 do-while 循环,尝试 3 次后将终止

java - Spring Testing Mock MVC 不应用自定义 RequestMappingHandlerMapping

clojure - lein pom-:classifier clause does not get generated in pom. xml

netbeans - Maven codehaus.mojo无法解析

java - 我在 SelectionSort 中得到错误的输出

java - Mingliu 字体不能在 linux 上工作

java - 如何在Eclipse中查看maven项目的web内容