Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaModule.assembly produces invalid or corrupt jar file (was: publishLocal as altenative to jars : which are corrupt often and at random) #528

Closed
siddhartha-gadgil opened this issue Jan 18, 2019 · 20 comments · Fixed by #3140
Labels
bug The issue represents an bug workaround-available
Milestone

Comments

@siddhartha-gadgil
Copy link

I am getting a lot of corrupt jars, even though I have cleared/checked everything in sight several times. This happens to fat jars in sbt too, but there we have the alternative (for use in Jupyter, for example) of publishLocal. Can mill provide such an option?

@lihaoyi
Copy link
Member

lihaoyi commented Jan 18, 2019

Mill already supports .publishLocal

@lihaoyi lihaoyi closed this as completed Jan 18, 2019
@lefou
Copy link
Member

lefou commented Jan 19, 2019

@siddhartha-gadgil So, what exactly is your issue? What is corrupt? And how did this happen?

@siddhartha-gadgil
Copy link
Author

siddhartha-gadgil commented Jan 20, 2019 via email

@lefou
Copy link
Member

lefou commented Jan 20, 2019

To be honest, I have no clue what you wanna tell us. It would be helpful to be more concrete. E.g. the exact mill cmdline you used when mill crashed. The exact error message.If possible, the build.sc...

Looks like you should better ask on https://gitter.im/lihaoyi/mill.

@siddhartha-gadgil
Copy link
Author

I did not mean that mill crashes, but that the executable jar generated by mill myproject.assembly crashes, and in a random and hard to diagnose (at least for me) way. The reason is almost certainly some cached corrupt jar, and probably a source/documentation jar.

  • My main request was to publishLocal, as an alternative, which @lihaoyi pointed out is already part of mill.
  • A feature that would be nice is a minimal fat-jar, i.e. excluding source and documentation dependencies, so reducing the chance of corrupt jars fouling this up.
  • Even better would be better diagnostics while building jars, though this may not be a mill issue.

@lihaoyi
Copy link
Member

lihaoyi commented Jan 20, 2019

@siddhartha-gadgil do you happen to be using Mill concurrently? Mill doesn't have proper concurrency control, so while concurrent usually works, if tasks happen to overlap in what they are doing things blow up in odd ways.

If you want diagnostics while building jars, feel free to build the jars yourself by copy-pasting the Mill code into your build.sc and add whatever diagnostics you'd like.

@siddhartha-gadgil
Copy link
Author

Quite possibly that is happening. But the main problem is probably a giant dependency on the Stanford Parser (coupled with not great internet) - random bits get corrupted in the cache, and any piece corrupted seems to make the jar unusable.

I'll try manually building by copy-pasting, with checks thrown in for corrupt jars.

@lihaoyi
Copy link
Member

lihaoyi commented Jan 20, 2019

@siddhartha-gadgil for internet-related issues with upstream dependencies, those issues should be persistent until you clean your coursier cache in ~/.coursier. If you are seeing things behave nondeterministically without clearing that cache, it is unlikely to be internet related.

Also, if you think things are being corrupted while building jars, use mill inspect and mill show to trawl the dependency graph of your task that created the corrupted jar and look at the input jars/folders to see if they contain what you expect. This might help you narrow down the corrupted jar to the actual culprit doing the corruption

@siddhartha-gadgil
Copy link
Author

It is not non-deterministic - I have a natural experiment because of two work systems, and I meant built on one and not on the other. I also meant changes when some dependencies change. I have tried trawling and resetting, but it is not easy manually at least on large scale.

For example, today I used publishLocal, got a crash in ammonite, deleting the corresponding coursier file and re-published to fix the error. But without the pointer from running (or some other script-based way) it would not be practical to find which dependency is corrupt.

@siddhartha-gadgil
Copy link
Author

siddhartha-gadgil commented Jan 20, 2019 via email

@siddhartha-gadgil
Copy link
Author

siddhartha-gadgil commented Jan 20, 2019 via email

@lefou lefou added the invalid This issue is invalid or lacks required information label Apr 18, 2019
@lefou
Copy link
Member

lefou commented Jan 28, 2021

FYI, it looks like the assembly target has an issue with very large assemblies and an non-empty prependShellScript. Here is a workaround:

override def prependShellScript: T[String] = ""

@lefou lefou reopened this Jan 28, 2021
@lefou lefou changed the title publishLocal as altenative to jars : which are corrupt often and at random JavaModule.assembly produces invalid or corrupt jar file (was: publishLocal as altenative to jars : which are corrupt often and at random) Jan 28, 2021
@Ammonite-Bot
Copy link
Collaborator

Ammonite-Bot commented Jan 28, 2021 via email

@lefou
Copy link
Member

lefou commented Jan 28, 2021

So, I think we should create a test case that reproduced this issue and then fix it. After a first glace at the code I think it could be, a proper fix will need to go to os-lib.

@lefou lefou added bug The issue represents an bug and removed invalid This issue is invalid or lacks required information labels Jan 29, 2021
@lefou
Copy link
Member

lefou commented May 21, 2021

I recently fixed some issues with left open file handles in assembly processing (which constantly failed windows tests, #1327). There is a minimal chance this issue just vanishes after that fix, too. It would be nice, If someone could report if this issue is still present with mill >= 0.9.7-9-848292.

@lefou
Copy link
Member

lefou commented Oct 1, 2021

This is probably fixed?

@lefou
Copy link
Member

lefou commented Oct 1, 2021

Please reopen or comment if you find this issue is still valid!

@lefou
Copy link
Member

lefou commented Jul 5, 2023

This issue is still present. See #2650 for a reproduction.

lefou added a commit that referenced this issue Jul 5, 2023
@lefou lefou linked a pull request Jul 5, 2023 that will close this issue
lefou added a commit that referenced this issue May 3, 2024
lefou added a commit that referenced this issue May 6, 2024
…ng (#3140)

This is an attempt to fix the issue of invalid assembly files which
occurs when the following two conditions are met:
* The JAR file has more than `65535` ZIP entries
* The JAR has a prepended shell script

The issue was reported and analyzed in the following tickets:
* #528
* #2650

This issue also hits other build tools, but it seems Mill is the only
tools which automatically enables shell script prepending by default.

Since there is no real fix available, we simply try to detect the issue
after the fact and fail the assemble task with a actionable error
message.

To make the fix binary compatible, I had to deprecated the
`upstreamAssembly` target in favor to the new `upstreamAssembly2`
target, which returns also the added ZIP entry count. Since this can be
a behavioral change when users have overridden the `upstreamAssembly`
target, I also added some warning messages with will detect this at
runtime and provide actionable help.

Pull request: #3140
@lefou lefou added this to the 0.11.8 milestone May 6, 2024
@lefou lefou closed this as completed May 16, 2024
@abbadmus
Copy link

abbadmus commented May 31, 2024

why do i keep getting this error

./out/app/assembly.dest/out.jar
Error: Could not find or load main class MyApp
Caused by: java.lang.ClassNotFoundException: MyApp

@lefou
Copy link
Member

lefou commented May 31, 2024

why do i keep getting this error

You probably have a too large assembly and hit an issue with the JVM/JDK. Latest Mill snapshots and the upcoming version 0.11.8 will detect this and recommend a fix.

In the meantime, just use the workaround from #528 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue represents an bug workaround-available
Projects
None yet
5 participants