我正在使用程序集插件构建一个带有依赖项的jar,然后压缩项目。然后将zip文件上传到nexus。干净安装工作并按预期生成zip文件。 deploy命令失败:
[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而不是jar。第三,为什么部署不在其当前状态下工作?最后,您能告诉我如何使用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>
我花了太长时间在这上面并且尝试了太多。我会非常感谢任何帮助。
答案 0 :(得分:2)
基本上你不能使用maven-assembly插件部署zip。装配部件是包装的一部分,而部署则在以后进行。检查此链接是否有用
Deploying assembly package with maven-release-plugin
OR
您可以使用此插件部署zip或tar文件 maven-build-helper-plugin
答案 1 :(得分:0)
当Nexus返回400状态时,表示您正在上传不允许上传到特定存储库的工件,例如您正在尝试将快照上传到版本存储库。
我猜你试图用“mvn deploy”将其部署为快照。尝试“mvn release:prepare release:perform”,将其作为稳定版本发布到“版本”存储库中。你不应该再获得400状态响应了。
答案 2 :(得分: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>
答案 3 :(得分:0)
要将* .zip文件部署到Nexus,您需要具有正确的pom.xml
和assembly.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
的{{1}}版本开始,配置有所变化。
如果您未在maven-assembly-plugin
中更改packaging
的类型,则Maven还将为您创建一个pom.xml
加上一个*.zip
文件,因为此属性的默认值为*.jar
。
如果您的jar
的版本以pom
结尾,则您的zip文件将被上传到以-SNAPSHOT
结尾的存储库中,否则将使用snapshots
存储库
assembly.xml的示例:
releases
然后
<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>
命令将创建您的* .zip文件。
mvn clean package
命令会将您的zip上传到Nexus。
通常,您不允许两次将相同版本的工件上载到mvn clean deploy
存储库中。如果您尝试执行此操作,那么您将返回releases
:
status code 400
希望对您有帮助。