Skip to content

Instantly share code, notes, and snippets.

@leolopez89
Last active July 13, 2022 14:54
Show Gist options
  • Save leolopez89/2ad326dfc8e292ce4d67f0dbfee0da3e to your computer and use it in GitHub Desktop.
Save leolopez89/2ad326dfc8e292ce4d67f0dbfee0da3e to your computer and use it in GitHub Desktop.
How to convert a gradle repository into a maven repository
#!/bin/bash
#
# Usage:
#
# bash gradle2maven.sh
# Will be used as default directories
# your default gradle reprository: $HOME/.gradle/caches/modules-2/files-2.1/
# in your current path, a new maven directory: $PWD/maven-XXXXX`/repository
#
# bash gradle2maven.sh <gradle-files2.1-path>
# It will use your prefered gradle files2.1 path and your current path
#
# bash gradle2maven.sh <gradle-files2.1-path> <your-prefered-output-path>
# It will use your prefered gradle files2.1 and output paths
#
current=$PWD
path=$1
[ "${path}" == "" ] && path=$HOME/.gradle/caches/modules-2/files-2.1/
output=$2
[ "${output}" == "" ] && output=`mktemp -d $current/maven-XXXXX`/repository
mkdir -vp $output
cd ${path}
for file in `find . -regex '.*\(pom\|jar\|aar\|exe\)'`; do
echo "Processing $file"
folderCreate=`echo $file | awk -v file=$file -v output=$output -F/ '{
cad = $2;
gsub(/\./, "/", cad);
print "mkdir -p " output "/" cad "/" $3 "/" $4 "/ "
}'`
fileCopy=`echo $file | awk -v file=$file -v output=$output -F/ '{
cad = $2;
gsub(/\./, "/", cad);
print "cp " file " " output "/" cad "/" $3 "/" $4 "/" $6
}'`
$folderCreate
$fileCopy
done
cd $current
@eliastg
Copy link

eliastg commented Jul 13, 2022

Very useful tool.
I have personally used it to fix some problems in React Native projects.
I am very happy that you have finally published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment