1

我是 Maven 新手,我正在尝试将我的项目部署为战争和 jar。我很想拆分项目来做同样的事情,但是对于简单的我来说,它太大了,无法在合理的时间内完成。

我发现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)

我究竟做错了什么?

4

2 回答 2

1

我观察到的一件事是,您使用的版本 SNAPSHOT 没有任何前面的数字,例如:

1.0.0-SNAPSHOT

或者至少:

1-SNAPSHOT

您只是在使用 SNAPSHOT,这没有意义,因为在这种情况下您正在谈论哪个开发线。

另一件事是 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)
于 2012-06-25T21:00:24.940 回答
0

在相应的远程存储库中有一个http://build.example.biz:8081/artifactory/libs-snapshots-local/com/example/main-project/my-project/SNAPSHOT/maven-metadata.xml. 如果您查看它,您会看到最新的时间戳映射到您各自的SNAPSHOT. 这是 Maven 2 和 3 下的典型行为。我相信使用带时间戳的SNAPSHOT-s 是 Maven 3 下的默认行为。

当您尝试通过 Maven 下载工件时,我相信它会为您正确解决它,因此您不必担心。

于 2012-06-25T23:00:15.083 回答