11"""Loads ANTLR dependencies."""
22
33load ("@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" , "http_jar" )
4+ load ("@bazel_tools//tools/build_defs/repo:utils.bzl" , "maybe" )
45load (":lang.bzl" , "C" , "CPP" , "GO" , "JAVA" , "OBJC" , "PYTHON" , "PYTHON2" , "PYTHON3" , supported_languages = "supported" )
56
7+ _MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2"
8+
69v4 = [4 , "4.7.1" , "4.7.2" , "4.8" , "4.9.1" , "4.9.2" ]
710v4_opt = [4 , "4.7.1" , "4.7.2" , "4.7.3" , "4.7.4" ]
811v3 = [3 , "3.5.2" ]
@@ -605,9 +608,10 @@ def _dependencies(dependencies):
605608 )
606609
607610def _download (name , path , sha256 ):
608- http_jar (
611+ maybe (
612+ http_jar ,
609613 name = name ,
610- url = path if path .startswith ("https" ) else "https://repo1.maven.org/maven2 /" + path ,
614+ url = path if path .startswith ("https" ) else _MAVEN_CENTRAL + " /" + path ,
611615 sha256 = sha256 ,
612616 )
613617
@@ -630,3 +634,67 @@ def _validate_versions(versions):
630634
631635def _to_string (x ):
632636 return str (x )
637+
638+ def rules_antlr_test_dependencies (repository = _MAVEN_CENTRAL ):
639+ """Loads test and development dependencies for rules_antlr.
640+
641+ These dependencies are only needed when developing/testing rules_antlr itself,
642+ not when using rules_antlr in your own projects. This macro:
643+
644+ - Uses maybe() to prevent duplicate loading
645+ - Automatically constructs Maven Central URLs
646+ - Centralizes version management for easier updates
647+ - Separates test deps from runtime deps for cleaner dependency graphs
648+
649+ Should be called in WORKSPACE after rules_antlr_dependencies().
650+
651+ Args:
652+ repository: Maven repository URL (defaults to Maven Central)
653+
654+ Example:
655+ load("//antlr:repositories.bzl", "rules_antlr_dependencies", "rules_antlr_test_dependencies")
656+ rules_antlr_dependencies("4.9.2")
657+ rules_antlr_test_dependencies()
658+ """
659+ _maven_jars ({
660+ "junit" : {
661+ "group" : "junit" ,
662+ "artifact" : "junit" ,
663+ "version" : "4.12" ,
664+ "sha256" : "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a" ,
665+ },
666+ "jimfs" : {
667+ "group" : "com.google.jimfs" ,
668+ "artifact" : "jimfs" ,
669+ "version" : "1.1" ,
670+ "sha256" : "c4828e28d7c0a930af9387510b3bada7daa5c04d7c25a75c7b8b081f1c257ddd" ,
671+ },
672+ "guava" : {
673+ "group" : "com.google.guava" ,
674+ "artifact" : "guava" ,
675+ "version" : "27.1-jre" ,
676+ "sha256" : "4a5aa70cc968a4d137e599ad37553e5cfeed2265e8c193476d7119036c536fe7" ,
677+ },
678+ }, repository )
679+
680+ def _maven_jars (dependencies , repository = _MAVEN_CENTRAL ):
681+ """Load Maven JAR dependencies using maybe() to avoid conflicts.
682+
683+ Args:
684+ dependencies: Dict of name -> dict with keys: group, artifact, version, sha256
685+ repository: Maven repository URL
686+ """
687+ for name , info in dependencies .items ():
688+ maybe (
689+ http_jar ,
690+ name = name ,
691+ url = "{}/{}/{}/{}/{}-{}.jar" .format (
692+ repository ,
693+ info ["group" ].replace ("." , "/" ),
694+ info ["artifact" ],
695+ info ["version" ],
696+ info ["artifact" ],
697+ info ["version" ],
698+ ),
699+ sha256 = info ["sha256" ],
700+ )
0 commit comments