Skip to content

Instantly share code, notes, and snippets.

@wdziemia
Created March 1, 2021 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdziemia/fd430dc11b2497684cb96ab9797d74c8 to your computer and use it in GitHub Desktop.
Save wdziemia/fd430dc11b2497684cb96ab9797d74c8 to your computer and use it in GitHub Desktop.
This is a script used to check
import os
import subprocess
import shlex
import argparse
import re
from pathlib import Path
bintray_repo = 'bintray.com/'
lib_gradle_kotlin_dsl = 'gradle-kotlin-dsl-plugins'
cached_marker = 'Cached resource'
build_environment = 'buildEnvironment'
CLI=argparse.ArgumentParser()
CLI.add_argument(
"--task",
nargs="?",
type=str,
default=build_environment,
)
CLI.add_argument(
"--repos",
nargs="*",
type=str,
default=[bintray_repo],
)
def run_check(command, repos):
print("\n"+command+"\n")
reposToUrls = dict()
for repoUrl in repos:
reposToUrls.setdefault(repoUrl, set())
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while(True):
retcode = process.poll()
line = process.stdout.readline().decode('utf-8').rstrip("\n")
if line.startswith(cached_marker):
for repo in repos:
if repo in line:
url = re.search(r'(https?://\S+)', line).group()
reposToUrls[repo].add(url.rsplit('/', 1)[0])
if retcode is not None:
if retcode == 1:
print ("\nError while executing gradle command. Please check that your arguement are correct\n")
break
return reposToUrls
if __name__ == "__main__":
args = CLI.parse_args()
print("\nChecking {0} for repos: {1}".format(args.task, args.repos) +"...")
command = "./gradlew %r --info --refresh-dependencies" % args.task
offendingLibs = run_check(command, args.repos)
hasKotlinDsl = False
for repo, libs in offendingLibs.items():
print("Found " + str(len(libs)) + " repos(s) used by " + repo)
for lib in libs:
if (not hasKotlinDsl and lib_gradle_kotlin_dsl in lib):
hasKotlinDsl = True
print(" - " + lib)
print("\n")
if (hasKotlinDsl):
print("Please replace jcenter() with mavenCentral() buildSrc/build.gradle.kts file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment