3

我正在使用程序集插件来构建一个带有依赖项的 jar,然后压缩项目。然后应该将 zip 文件上传到 nexus。全新安装工作并按预期生成 zip 文件。部署命令失败:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Analytics Feed Auditor
[INFO]    task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] [assembly:single {execution: jar-with-dependencies}]
[INFO] Processing DependencySet (output=)
[INFO] Building jar: C:\code\imt workspaces\uat-trunk\AnalyticsAudit\target\AnalyticsAudit-1
.0-jar-with-dependencies.jar
[INFO] [assembly:single {execution: RELEASE}]
[INFO] Reading assembly descriptor: dist.xml
[INFO] Building zip: C:\code\imt workspaces\uat-trunk\AnalyticsAudit\target\AnalyticsAudit-1
.0-RELEASE.zip
[INFO] [install:install]
[INFO] Installing C:\code\imt workspaces\uat-trunk\AnalyticsAudit\target\AnalyticsAudit-1.0.
jar to C:\SVNRepository\com\dec\gbm\gb\gcf\amg\fo\AnalyticsAudit\1.0\AnalyticsAudit-1.0.jar
[INFO] Installing C:\code\imt workspaces\uat-trunk\AnalyticsAudit\target\AnalyticsAudit-1.0-
jar-with-dependencies.jar to C:\SVNRepository\com\dec\gbm\gb\gcf\amg\fo\AnalyticsAudit\1.0\Analytic
sAudit-1.0-jar-with-dependencies.jar
[INFO] Installing C:\code\imt workspaces\uat-trunk\AnalyticsAudit\target\AnalyticsAudit-1.0-
RELEASE.zip to C:\SVNRepository\com\dec\gbm\gb\gcf\amg\fo\AnalyticsAudit\1.0\AnalyticsAudit-1.0-REL
EASE.zip
[INFO] [deploy:deploy]
altDeploymentRepository = null
Uploading: https://dsnexus.uk.hibm.dec:8081/nexus/content/repositories/releases/com/dec/gbm/gb/gcf
/amg/fo/AnalyticsAudit/1.0/AnalyticsAudit-1.0.jar
6K uploaded
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: https://dsnexus.uk.hibm.dec:8081/nexus/co
ntent/repositories/releases/com/dec/gbm/gb/gcf/amg/fo/AnalyticsAudit/1.0/AnalyticsAudit-1.0.jar. Re
turn code is: 400

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Fri Aug 09 15:58:22 BST 2013
[INFO] Final Memory: 14M/35M
[INFO] ------------------------------------------------------------------------

我这里有几个问题。首先,我想要一个自定义的 ZIP 文件名,而不是默认的。其次,只有 ZIP 文件应该部署到 Nexus 而不是 jars。第三,为什么部署不在当前状态下工作?最后,您能告诉我如何使用 wget 从 nexus 自动下载最新版本吗?

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project ....>
<modelVersion>4.0.0</modelVersion>
<groupId>com.dec.gbm.gb.gcf.amg.fo</groupId>
<artifactId>AnalyticsAudit</artifactId>
<version>1.0</version>
<name>Analytics Feed Auditor</name>
<description>Analytics Feed Auditor</description>
<packaging>jar</packaging>

<distributionManagement>
    <repository>
        <id>releases</id>
        <name>Internal Releases</name>
        <url>...</url>
    </repository>

    <snapshotRepository>
        <id>snapshots</id>
        <name>Internal Snapshots</name>
        <url>...</url>
    </snapshotRepository>

</distributionManagement>
<repositories>
    <repository>
        <id>releases</id>
        <name>Nexus Repository</name>
        <url>...</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>releases</id>
        <name>Nexus Repository</name>
        <url>...</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
<properties>
    <project.build.sourceEncoding>Cp1252</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.vicar</groupId>
        <artifactId>vicar</artifactId>
        <version>3.6</version>
        <scope>system</scope>
        <systemPath>
            ${project.basedir}/lib/vicar-3.6.jar
        </systemPath>
    </dependency>
    <dependency>...
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>
                                jar-with-dependencies
                            </descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>
                                    lib/
                                </classpathPrefix>
                                <mainClass>
                                    com.dec.gbm.gb.gcf.amg.fo.AnalyticsAuditor
                                </mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
                <execution>
                    <id>RELEASE</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>dist.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

dist.xml

<assembly>
<id>RELEASE</id>
<formats>
    <format>zip</format>
</formats>
<files>
    <file>
        <source>
            target/${project.artifactId}-${project.version}-jar-with-dependencies.jar
        </source>
        <outputDirectory>lib</outputDirectory>
    </file>
    <file>
        <source>${project.basedir}/bin/AnalyticsAudit.cmd</source>
        <outputDirectory />
    </file>
    <file>
        <source>
            ${project.basedir}/resources/analytics_audit.properties
        </source>
        <outputDirectory>resources</outputDirectory>
    </file>
    <file>
        <source>${project.basedir}/lib/vicar-3.6.jar</source>
        <outputDirectory>lib</outputDirectory>
    </file>
</files>

我在这方面花了太长时间,也尝试了太多。我将非常感谢任何帮助。

4

4 回答 4

2

基本上,您不能使用 maven-assembly 插件部署 zip。组装部分是包装的一部分,而部署发生在以后。检查此链接是否有用

使用 maven-release-plugin 部署程序集包

或者

您可以使用此插件部署 zip 或 tar 文件maven-build-helper-plugin

于 2013-09-30T10:56:14.217 回答
0
        <!--Make it a fat jar-->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!--this is used for inheritance merges-->
                    <phase>package</phase> <!--bind to the packaging phase-->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
于 2014-10-30T11:08:37.203 回答
0

当 Nexus 返回 400 状态时,这意味着您正在上传不允许上传到特定存储库的工件,例如您正在尝试将快照上传到发布存储库。

我猜您正在尝试使用“mvn deploy”将其部署为快照。尝试“mvn release:prepare release:perform”将其作为稳定版本发布到“releases”存储库中。你不应该再得到那个 400 状态响应了。

于 2014-04-29T14:28:55.083 回答
0

为了将 *.zip 文件部署到 Nexus,您需要拥有适当的文件pom.xmlassembly.xml文件。

这是您需要的 pom.xml:

<project>
    <groupId>a.b</groupId>
    <artifactId>deploy-to-nexus</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!-- 
         it needs to be 'pom', otherwise maven will
         generate an <artifactId>-<version>.jar file as well
    -->
    <packaging>pom</packaging>

    <!-- nexus repositories -->
    <distributionManagement>
        <repository>
            <id>deploy-to-nexus-releases</id>
            <url>http://...</url>
        </repository>
        <snapshotRepository>
            <id>deploy-to-nexus-snapshots</id>
            <url>http://...</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
             <!-- assembly plugin will be activated by 'mvn package' -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我的评论:

  • v3.1.1版本的配置发生了变化maven-assembly-plugin

  • 如果您不更改类型,packaging那么pom.xmlMaven 也会为您创建一个*.zip*.jar文件,因为此属性的默认值为jar.

  • 如果您的版本以pom结尾,-SNAPSHOT那么您的 zip 文件将上传到以 结尾的存储库snapshots,否则releases使用存储库。

assembly.xml 的示例:

<assembly>
    <id>bundle</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <!-- add some files -->
        <fileSet>
            <directory>...</directory>
            <outputDirectory>...</outputDirectory>
            <includes>
                <include>**</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

然后

  • mvn clean package命令将创建您的 *.zip 文件。

  • mvn clean deploy命令会将您的 zip 文件上传到 Nexus。

通常,不允许您将相同版本的工件releases两次上传到存储库中。如果您尝试这样做,那么您将返回status code 400

Failed to deploy artifacts: Could not transfer artifact a.b:deploy-to-nexus:pom:1.0 from/to ..... (http://.....-releases): Failed to transfer file http://..../deploy-to-nexus/1.0/deploy-to-nexus-1.0.pom with status code 400

希望对您有所帮助。

于 2019-09-11T13:26:27.877 回答