我是Maven的新手,我尝试将我的项目部署为战争和罐子。我很乐意将项目分开来做同样的事情,但是对于我来说,在合理的时间里我做的事情太大了。
我找到maven deploy additional jar file,建议我添加一些插件。
安装插件效果很好
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<file>
${project.build.directory}/${project.artifactId}-SNAPSHOT.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
这是输出:
[INFO] [install:install-file {execution: default}]
[INFO] Installing C:\Server\example\code\server\my-project\target\my-project-SNAPSHOT.jar to C:\Users\Kyle\.m2\repository\com\example\main-project\my-project\SNAPSHOT\my-project-SNAPSHOT.jar
问题在于maven-deploy-plugin。它似乎忽略了我强迫它使用的SNAPSHOT版本:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>SNAPSHOT</version>
<!--${project.version}!="SNAPSHOT" for some reason-->
<file>${project.build.directory}/${project.artifactId}-SNAPSHOT.jar</file>
</configuration>
</execution>
</executions>
</plugin>
似乎使用其他版本号(YYYYMMDD.HHmmSS - #)
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
我做错了什么?
答案 0 :(得分:1)
我观察到的一件事是您使用的版本SNAPSHOT没有任何前面的数字,如:
1.0.0-SNAPSHOT
或至少:
1-SNAPSHOT
您正在使用SNAPSHOT这个does not make sense,原因,在这种情况下您正在讨论哪条开发线。
另一件事是,Maven中的SNAPSHOT(假设您以正确的方式使用它)是一个工件,其中将放置时间戳而不是SNAPSHOT。这样就可以让多个SNAPSHOT被释放,但可以区分它们。
所以你在输出中展示的东西正是Maven从SNAPSHOT中得到的东西:
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
Uploading: http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/my-project-20120625.161551-2.jar
42993K uploaded (my-project-20120625.161551-2.jar)
答案 1 :(得分:0)
在相应的远程存储库中有一个http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/maven-metadata.xml
。如果您查看它,您会看到最新的时间戳映射到您的相应SNAPSHOT
。这是Maven 2和3下的典型行为。我认为这是Maven 3下使用带时间戳的SNAPSHOT
- s的默认行为。
当您尝试通过Maven下载工件时,我相信它会为您正确解决它,所以您不应该感到惊慌。