DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Private Remote Maven Repository With Artipie
  • How to Publish Artifacts to Maven Central
  • Two Engines, One Query: DuckDB Inside Neo4j
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption

Trending

  • How Kestra Unifies Enterprise Workflow Orchestration and Agentic AI
  • Why Your AI Agent Works in the Demo and Fails in Production
  • Delta Lake UniForm to Snowflake: Cross-Platform Table Access Without a Second Copy
  • MQTT, Kafka, NATS, or Zenoh? Choosing Edge-to-Cloud Messaging by Traffic Pattern

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. Maven Artifact Checksums

Maven Artifact Checksums

Want to learn more about working with Apache Maven and some of the problems you might face? Check out this post where we look at using Maven and artifact checksums.

By 
Karl Heinz Marbaise
·
Oct. 16, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
19.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

If you are using Apache Maven, you might have faced issues like this:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project cores-batch: Error creating shaded jar: invalid LOC header (bad signature) -> [Help 1]
...
.... (remove many lines for brevity).
...
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
    at java.util.zip.ZipFile.read(Native Method)
    at java.util.zip.ZipFile.access$1400(ZipFile.java:56)
    at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:679)
    at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:415)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
...


How could that happen? Most of the time, these are downloading or network issues that are causing this. In extreme cases, it might also be a hardware error. But, usually, I have my doubts about that. This means that the downloaded artifacts are not correctly downloaded or downloaded from repositories that do not exist anymore. Or, this could be any other strange thing that you could imagine. If you have artifacts that contain HTML snippets, this is an indicator that you are trying to download artifacts from repositories that no longer exist. Therefore, you will have to check your configuration for used repositories, which is obviously wrong.

So, now the question is: what can you do to prevent that in the future?

If you take a look on Stackoverflow, more or less, all answers will tell you to delete your local cache $HOME/.m2/repositoy and rebuild.

This is, unfortunately, only going to fix the symptoms and not the real cause. So, work can begin by deleting the local cache as a first step.

And now, we will look at the most important part — you have to configure Maven to check the checksums of the downloaded artifacts and fail your build if they are not correct. This is called the checksum policy, which I strongly recommend.

This means that you have to change the configuration in your settings.xml. You have to change the checksum policy in your settings.xml

A temporary solution would be to call Maven with --strict-checksums, which does this only for the appropriate call of Maven. So, it is better to configure this into your settings.xml, which will look like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>...</url>
        </repository>
      </repositories>
      <pluginRepositories>
        ...
      </pluginRepositories>
      ...
    </profile>
  </profiles>
  ...
</settings>


Furthermore, you have to configure this for all of your repositories in your settings.xml. If you are using a repository manager, either locally or within a corporate environment, you have to check your repository manager as well if it is correctly configured to check the checksums. You should, of course, not forget to check if you are downloading via https:// instead of http:// from all of your remote repositories.

Hope this helps!

Apache Maven Artifact (UML)

Opinions expressed by DZone contributors are their own.

Related

  • Private Remote Maven Repository With Artipie
  • How to Publish Artifacts to Maven Central
  • Two Engines, One Query: DuckDB Inside Neo4j
  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook