首页 文章

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

提问于
浏览
2

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

[错误]无法执行目标org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:在项目休息服务上部署(inject-nexus-deploy):无法部署工件:无法传输工件com .xyz:rest-service:jar:0.0.1-20180504.193415-6 from / to nexus(http://nexus.mydomain.io/repository/snapshots/):无法传输文件:http://nexus.mydomain . IO /库/快照/ COM / XYZ / REST的服务/ 0.0.1-SNAPSHOT / REST的服务,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-pluginlink)的版本有关,但即使我将版本设置为 1.6.8 (最新),我也会得到同样的效果 . 这个post建议使用 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>

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

[错误]无法执行目标org.codehaus.mojo:build-helper-maven-plugin:3.0.0:attach-artifact(attach-artifacts)on project rest-service:目标org.codehaus的执行附件工件 . mojo:build-helper-maven-plugin:3.0.0:attach-artifact failed:对于artifact :附加的工件必须具有与其对应的不同的ID主要神器 . - > [帮助1]

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

有关如何解决此问题的任何想法?我提到的帖子是"some maven repositories check the file content,"所以,在检查文件内容时如何禁用Nexus(我已经控制)?但真正的问题是,为什么内容类型 application/x-sh 而不是 application/java-archive

1 回答

  • 4

    在相关存储库的设置中(错误消息中的URL提到"Snapshots"存储库), Storage section:禁用 Strict content type validation 设置 . 该设置的描述是: Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format .

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

    例:

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

    这里是Sublime Text中打开的此类文件的屏幕截图:
    enter image description here

相关问题