Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a jar artifact to Nexus results in a content type mismatch

I am using Nexus Repository Manager v3.1.0-04. When I attempt to mvn deploy a jar artifact to my repository, I get the following problem.

[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy (injected-nexus-deploy) on project rest-service: Failed to deploy artifacts: Could not transfer artifact com.xyz:rest-service:jar:0.0.1-20180504.193415-6 from/to nexus (http://nexus.mydomain.io/repository/snapshots/): Failed to transfer file: http://nexus.mydomain.io/repository/snapshots/com/xyz/rest-service/0.0.1-SNAPSHOT/rest-service-0.0.1-20180504.193415-6.jar. Return code is: 400, ReasonPhrase: Detected content type [application/x-sh], but expected [application/java-archive]: com/xyz/rest-service/0.0.1-SNAPSHOT/rest-service-0.0.1-20180504.193415-6.jar. -> [Help 1]

I thought that maybe this was related to the version of nexus-staging-maven-plugin (link) but even if I set the version to 1.6.8 (latest), I get the same effect. This post suggest that to use the build-helper-maven-plugin, and so I modified my pom.xml as follows.

<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>

However, I see a different problem now.

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:attach-artifact (attach-artifacts) on project rest-service: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:attach-artifact failed: For artifact {com.xyz:rest-service:0.0.1-SNAPSHOT:jar}: An attached artifact must have a different ID than its corresponding main artifact. -> [Help 1]

Note that the Maven project is generated by Spring Initializer via IntelliJ and is a Spring Boot project. Without using the Builder Helper plugin, I can see that all files are successfully uploaded to Nexus until the jar is finished uploaded (it actually finishes uploaded, but because the content type mismatches, it fails).

Any ideas on how to resolve this issue? The post I mentioned says "some maven repositories check the file content," and so, how would I disable Nexus (which I have control over) in checking file content? But the real problem is, why is the content type application/x-sh instead of application/java-archive?

like image 687
Jane Wayne Avatar asked May 04 '18 20:05

Jane Wayne


1 Answers

In the settings of the repository in question (the URL in the the error message mentions the "Snapshots" repository), Storage section: disable the Strict content type validation setting. The description of that setting is: Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format.

To answer the second question, why: load the JAR file in an editor. You might see a shell script header (Bash). In that case the JAR file is a "executable JAR", and the shell script header is a startup script from Spring Boot. Because of this Nexus wrongly detects the file as being a shell script.

Example:

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

Here a screenshot of such a file opened in Sublime Text: enter image description here

like image 172
t0r0X Avatar answered Oct 05 '22 21:10

t0r0X