BUCK2 import Maven dependencies

Meta's BUCK2 doesn't yet have Java and Android support (see github issue 394), however, it's useful to have a script to autogenerate remote_file and prebuilt_jar rules from Maven coordinates, if the code did work. If you're trying to get BUCK2 to compile Java, save yourself the trouble just yet and use Bazel - it should work for you. 

That said, here's a quick attempt at a script to import maven jars for BUCK. If it's useful to you, feel free to use.


#!/usr/bin/env bash
#
# Import a Maven dependency based on the coordinates.
#
#

# Print debug log
# set -x

# Exit on error
set -e

if [[ $# != 1 ]]; then
  echo Usage: $0 com.pinterest.optimus:library:version
  echo
  echo Imports the given Maven target into a BUCK file in third_party/
  exit 1
fi

# Change to third-party directory
cd `dirname $0`

MVN_COORDS=$1
GROUP_ID=$(echo $MVN_COORDS | cut -f 1 -d:)
ARTIFACT_ID=$(echo $MVN_COORDS | cut -f 2 -d:)
VERSION=$(echo $MVN_COORDS | cut -f 3 -d:)
MAVEN_CENTRAL_URL_BASE=https://repo1.maven.org/maven2

if [[ $VERSION == "" ]]; then
  VERSION=$(curl -s ${MAVEN_CENTRAL_URL_BASE}/$(echo $GROUP_ID | tr . /)/${ARTIFACT_ID}/maven-metadata.xml | grep '.*' | xargs echo | tr -d latest\<\>/)
  echo Latest Version: $VERSION
fi

echo Importing $MVN_COORDS
echo $GROUP_ID $ARTIFACT_ID $VERSION


JAR_SHA1=$(curl -s ${MAVEN_CENTRAL_URL_BASE}/$(echo $GROUP_ID | tr . /)/${ARTIFACT_ID}/$VERSION/${ARTIFACT_ID}-${VERSION}.jar.sha1)
SRC_JAR_SHA1=$(curl -s ${MAVEN_CENTRAL_URL_BASE}/$(echo $GROUP_ID | tr . /)/${ARTIFACT_ID}/$VERSION/${ARTIFACT_ID}-${VERSION}-sources.jar.sha1)
JAVADOC_JAR_SHA1=$(curl -s ${MAVEN_CENTRAL_URL_BASE}/$(echo $GROUP_ID | tr . /)/${ARTIFACT_ID}/$VERSION/${ARTIFACT_ID}-${VERSION}-javadoc.jar.sha1)
NAME=$(echo ${GROUP_ID} | tr . _)_$(echo ${ARTIFACT_ID} | tr .- _)

echo JAR_SHA1=${JAR_SHA1} SRC_JAR_SHA1=${SRC_JAR_SHA1} NAME=${NAME}

echo "
remote_file(
  name = '${NAME}_sources',
  out = '${ARTIFACT_ID}-${VERSION}-sources.jar',
  url = 'mvn:$MAVEN_CENTRAL_URL_BASE:$GROUP_ID:$ARTIFACT_ID:src:$VERSION',
  sha1 = '${SRC_JAR_SHA1}'
)

remote_file(
  name = '${NAME}_jar',
  out = '${ARTIFACT_ID}-${VERSION}.jar',
  url = 'mvn:$MAVEN_CENTRAL_URL_BASE:$GROUP_ID:$ARTIFACT_ID:jar:$VERSION',
  sha1 = '${JAR_SHA1}'
)

remote_file(
  name = '${NAME}_javadoc',
  out = '${ARTIFACT_ID}-${VERSION}-javadoc.jar',
  url = 'mvn:$MAVEN_CENTRAL_URL_BASE:$GROUP_ID:$ARTIFACT_ID:javadoc:$VERSION',
  sha1 = '${JAVADOC_JAR_SHA1}'
)

prebuilt_jar(
  name = '${NAME}',
  binary_jar = ':${NAME}_jar',
  source_jar = ':${NAME}_sources',
  javadoc_url = ':${NAME}_javadoc'
)
"

Comments

Popular posts from this blog

Coke Studio: Madari English Meaning and Lyrics

AJAX और हिंदी

Sadi Gali - Punjabi Lyrics and Meaning (in English) - Tanu Weds Manu

Tune Meri Jaana Kabhi Nahin Jaana - Lonely (Emptiness) - IIT Guwahati - Rohan Rathore

Solved? LaTeX Error: pdf file is damaged - attempting to reconstruct xref table