Search code examples
javamavenhomebrewbuck

How do I download Buck remote files in a Homebrew formula?


I am trying to write a formula for my Java project. I am using to build the project, which requires some jar files to be downloaded from Maven.

For example, my BUCK file has:

remote_file(
  name = 'guava-jar',
  out = 'guava-21.0.jar',
  url = 'mvn:com.google.guava:guava:jar:21.0',
  sha1 = '3a3d111be1be1b745edfa7d91678a12d7ed38709',
)

prebuilt_jar(
  name = 'guava',
  source_jar = ':guava-jar',
  binary_jar = ':guava-jar',
  javadoc_url = 'https://google.github.io/guava/releases/21.0/api/docs/',
)

In my formula I have a line for fetching these jars:

system 'buck fetch :my-project'

However, the download of the jars fails:

Unable to download: mvn:com.google.guava:guava:jar:21.0

Is Homebrew applying some restrictions to my commands (e.g. blocking web requests)?

How can I pull files from Maven in a Homebrew formula?


Solution

  • My mistake was that in my project folder I have a .buckconfig, but in the Homebrew area I did not. This meant that the Maven URL was not set correctly, causing the download to fail.

    The solution was to add an extra step to my Homebrew formula that generates a .buckconfig:

    buckconfig = File.new('.buckconfig', 'w')
    buckconfig.puts("[download]\n" + 
      "maven_repo = http://repo.maven.apache.org/maven2/\n" + 
      "in_build = true\n")
    buckconfig.close