使用maven-deploy-plugin将Ant生成的jar部署到Nexus

时间:2019-01-29 10:10:04

标签: maven maven-deploy-plugin

我有一个带有war和ear模块的多模块项目。在战争的pom中,我正在使用maven-antrun-plugin生成jar。现在,我正在尝试使用maven-deploy-plugin将jar部署到Nexus。

这是我的战争的pom.xml:

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>test-war</artifactId>
<packaging>war</packaging>

<properties>
    ...
</properties>

<dependencies>
    ...
</dependencies>

<!-- <distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <url><nexus_releases_repo_url></url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <url><nexus_snapshots_repo_url></url>
    </snapshotRepository>
</distributionManagement> -->

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>ant-build</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <ant antfile="<path_to_build_xml>" target="run" />
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
            <executions>
                <execution>
                    <id>deploy-file</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <repositoryId>nexus-snapshots</repositoryId>
                        <file>fileToDeploy.jar</file>
                        <url>http://<path_to_my_repo></url>
                        <groupId>${project.parent.groupId}</groupId>
                        <artifactId>${project.parent.artifactId}-tmp</artifactId>
                        <version>${project.parent.version}</version>
                        <packaging>jar</packaging>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在父pom上运行clean deploy时,出现以下错误:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project test: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

好吧,所以我在war的pom中添加了distributionManagement部分,但我遇到了同样的错误。如果我在war模块上运行相同的命令,则没有错误,但是在jar文件旁边的Nexus上也部署了war文件。

有没有一种方法可以使用deploy命令部署jar文件?

0 个答案:

没有答案