19

I started getting the following error when updating my casks recently:

Error: Cask 'java' definition is invalid: Token '{:v1=>"java"}' in header line does not match the file name.

I'm on MacOS 10.14.4, and my Homebrew version:

→ brew --version
Homebrew 2.1.2
Homebrew/homebrew-core (git revision 6811d1; last commit 2019-05-11)
Homebrew/homebrew-cask (git revision ba4e3; last commit 2019-05-11)

Here's the output of brew cask upgrade --verbose --debug:

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
angular-cli          atlassian-cli        libpqxx              terraforming
app-engine-python    elasticsearch        osm2pgrouting
asciidoctorj         jenkins-lts          postgresql

==> Casks with `auto_updates` or `version :latest` will not be upgraded
==> Upgrading 1 outdated package:
Error: Cask 'java' definition is invalid: Token '{:v1=>"java"}' in header line does not match the file name.
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:73:in `cask'
/usr/local/Caskroom/java/.metadata/1.8.0_51-b16/20150725210402.758/Casks/java.rb:1:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:62:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:62:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:178:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/upgrade.rb:39:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/upgrade.rb:37:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/upgrade.rb:37:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd/abstract_command.rb:36:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:92:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:158:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:123:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:9:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:102:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:162:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:162:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:146:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:123:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:9:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:102:in `<main>'

and the output of brew tap:

beeftornado/rmtree
heroku/brew
homebrew/cask
homebrew/core
homebrew/services

Here's the output of brew doctor if it helps:

→ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
  /Users/myUser/anaconda3/bin/icu-config
  /Users/myUser/anaconda3/bin/krb5-config
  /Users/myUser/anaconda3/bin/freetype-config
  /Users/myUser/anaconda3/bin/xslt-config
  /Users/myUser/anaconda3/bin/libpng16-config
  /Users/myUser/anaconda3/bin/python3.6m-config
  /Users/myUser/anaconda3/bin/libpng-config
  /Users/myUser/anaconda3/bin/xml2-config
  /Users/myUser/anaconda3/bin/python3-config
  /Users/myUser/anaconda3/bin/curl-config
  /Users/myUser/anaconda3/bin/ncursesw6-config
  /Users/myUser/anaconda3/bin/pcre-config
  /Users/myUser/anaconda3/bin/python3.6-config
  /Applications/Postgres.app/Contents/Versions/9.4/bin/gdal-config

Warning: Some installed formulae are not readable:
  dotwrp: Unsupported special dependency :fortran
(base)

I've searched but cannot seem to find a way to fix this. Any suggestions?

DaniG2k
  • 4,772
  • 36
  • 77

2 Answers2

58

Solved by doing the following:

  1. Edited the java cask:
vim /usr/local/Caskroom/java/.metadata/1.8.0_51-b16/20150725210402.758/Casks/java.rb
  1. Changed the first line from:

cask :v1 => 'java' do

to

cask 'java' do

  1. Removed the undent comments at the end of the cask, which were giving me problems.

  2. Ran brew uninstall --cask java

Problem solved

tplaner
  • 8,363
  • 3
  • 31
  • 47
DaniG2k
  • 4,772
  • 36
  • 77
  • 2
    If I could upvote this answer fifty times, I would! I have been fighting with a broken java installation, literally, for years. I did one more step, which was to do a "brew cask uninstall --force java". – A. Rick Feb 12 '20 at 23:22
  • Any idea what causes this problem to begin with? – Louis Thibault Aug 05 '20 at 10:30
  • Step 3 was the step that fixed the issue for me. – sbkrogers Aug 08 '20 at 13:39
  • This was really helpful. What does everyone do *after* uninstalling java? Do you install via homebrew again, or go through the native OSX install? According to my notes, I installed Java via brew cask after upgrading to Yosemite, 5 years ago. But I don't recall why I installed it. – antun Nov 10 '20 at 21:24
  • 1
    Thank you! For future searchers: I also had to comment out a line reading `license :gratis` to get it to work. I did _not_ have to change the `undent` comment at the end of the cask. – Dave Land Nov 13 '20 at 23:24
  • applied the same instructions to remove an old version of flash and it worked! thanks! – Edoardo Nov 17 '20 at 14:12
  • 2
    I also had to delete two blocks containing `if MacOS.release <= :mavericks` due to `Error: Cask 'java' is unreadable: undefined method `release' for OS::Mac:Module` – Nick Nov 26 '20 at 12:53
  • 2
    Step 4 is now: `brew uninstall --cask java` – techpeace Mar 19 '21 at 20:51
  • I used this solution for a similar error but for virtualbox: Error: Cask 'virtualbox' definition is invalid: Token '{:v1=>"virtualbox"}' in header line does not match the file name. Thanks a million! – jaco Jul 26 '21 at 15:17
7

You can clean up old-style cask formulas thus:

grep "cask :v1 =>" --files-with-match /usr/local/Caskroom/*/.metadata/*/*/Casks/*.rb \
  | xargs gdirname | xargs gdirname | xargs rm -r

Assuming you've installed coreutils with a g prefix, so gdirname runs the GNU flavor of dirname

George V. Reilly
  • 15,885
  • 7
  • 43
  • 38
  • Thanks, this saved me from `Cask 'virtualbox' definition is invalid: Token '{:v1=>"virtualbox"}' in header line does not match the file name.` – kross Jan 30 '21 at 01:59