将jar工件部署到Nexus会导致内容类型不匹配

Jan*_*yne 6 java spring nexus maven spring-boot

我正在使用Nexus Repository Manager v3.1.0-04.当我尝试将mvn deployjar工件存储到我的存储库时,我遇到了以下问题.

[错误]无法执行目标org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:部署(inject-nexus-deploy)项目rest-service:无法部署工件:无法传输工件com. xyz:rest-service:jar:0.0.1-20180504.193415-6 from/to nexus(http://nexus.mydomain.io/repository/snapshots/):无法传输文件: http://nexus.mydomain.io /repository/snapshots/com/xyz/rest-service/0.0.1-SNAPSHOT/rest-service-0.0.1-20180504.193415-6.jar.返回码为:400,ReasonPhrase:检测到的内容类型[application/x-sh],但是预期[application/java-archive]:com/xyz/rest-service/0.0.1-SNAPSHOT/rest-service-0.0.1 -20180504.193415-6.jar. - > [帮助1]

我想也许这与nexus-staging-maven-plugin(链接)的版本有关,但即使我将版本设置为1.6.8(最新),我也会得到相同的效果.这篇帖子建议使用build-helper-maven-plugin,所以我修改了我pom.xml的如下.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
            <goal>attach-artifact</goal>
        </goals>
        <configuration>
            <artifacts>
            <artifact>
                <file>target/${artifactId}-${version}.jar</file>
                <type>jar</type>
            </artifact>
            </artifacts>
        </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但是,我现在看到了一个不同的问题.

[错误]无法在项目rest-service上执行目标org.codehaus.mojo:build-helper-maven-plugin:3.0.0:attach-artifact(attach-artifacts):目标org.codehaus.mojo的执行附件工件:build-helper-maven-plugin:3.0.0:attach-artifact failed:对于artifact {com.xyz:rest-service:0.0.1-SNAPSHOT:jar}:附加的工件必须具有与其对应的main不同的ID神器. - > [帮助1]

请注意,Maven项目由Spring Initializer通过IntelliJ生成,是一个Spring Boot项目.在不使用Builder Helper插件的情况下,我可以看到所有文件都成功上传到Nexus,直到jar上传完成(它实际上已完成上传,但由于内容类型不匹配,因此失败).

有关如何解决此问题的任何想法?我提到的帖子说"一些maven存储库检查文件内容",那么,在检查文件内容时如何禁用Nexus(我已经控制)?但真正的问题是,为什么内容类型application/x-sh而不是application/java-archive

t0r*_*r0X 6

在相关存储库的设置中(错误消息中的 URL 提到了“快照”存储库),存储部分:禁用严格的内容类型验证设置。该设置的描述是:Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format

要回答第二个问题,为什么:在编辑器中加载 JAR 文件。您可能会看到一个 shell 脚本标头 (Bash)。在这种情况下,JAR 文件是“可执行 JAR”,而 shell 脚本头是来自 Spring Boot 的启动脚本。因此 Nexus 错误地将该文件检测为 shell 脚本。

例子:

#!/bin/bash
#
#    .   ____          _            __ _ _
#   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
#  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
#   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
#    '  |____| .__|_| |_|_| |_\__, | / / / /
#   =========|_|==============|___/=/_/_/_/
#   :: Spring Boot Startup Script ::
#
# ... etc
Run Code Online (Sandbox Code Playgroud)

这是在 Sublime Text 中打开的此类文件的屏幕截图: 在此处输入图片说明