Skip to content

Commit

Permalink
Migrate jar dependencies of tests from maven_jar to rules_jvm_external
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Nov 4, 2019
1 parent 0f89c21 commit 35e32d7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 58 deletions.
89 changes: 46 additions & 43 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,6 @@ specs2_junit_repositories()

load("//scala:scala_cross_version.bzl", "default_scala_major_version", "scala_mvn_artifact")

# test adding a scala jar:
maven_jar(
name = "com_twitter__scalding_date",
artifact = scala_mvn_artifact(
"com.twitter:scalding-date:0.17.0",
default_scala_major_version(),
),
sha1 = "420fb0c4f737a24b851c4316ee0362095710caa5",
)

# For testing that we don't include sources jars to the classpath
maven_jar(
name = "org_typelevel__cats_core",
artifact = scala_mvn_artifact(
"org.typelevel:cats-core:0.9.0",
default_scala_major_version(),
),
sha1 = "b2f8629c6ec834d8b6321288c9fe77823f1e1314",
)

# test of a plugin
maven_jar(
name = "org_psywerx_hairyfotr__linter",
artifact = scala_mvn_artifact(
"org.psywerx.hairyfotr:linter:0.1.13",
default_scala_major_version(),
),
sha1 = "e5b3e2753d0817b622c32aedcb888bcf39e275b4",
)

# test of strict deps (scalac plugin UT + E2E)
maven_jar(
name = "com_google_guava_guava_21_0_with_file",
artifact = "com.google.guava:guava:21.0",
sha1 = "3a3d111be1be1b745edfa7d91678a12d7ed38709",
)

# test of import external
# scala maven import external decodes maven artifacts to its parts
# (group id, artifact id, packaging, version and classifier). To make sure
Expand All @@ -84,12 +47,6 @@ scala_maven_import_external(
srcjar_sha256 = "5e586357a289f5fe896f7b48759e1c16d9fa419333156b496696887e613d7a19",
)

maven_jar(
name = "org_apache_commons_commons_lang_3_5",
artifact = "org.apache.commons:commons-lang3:3.5",
sha1 = "6c6c702c89bfff3cd9e80b04d668c5e190d588c6",
)

new_local_repository(
name = "test_new_local_repo",
build_file_content =
Expand Down Expand Up @@ -234,3 +191,49 @@ scala_maven_import_external(
"https://repo.maven.apache.org/maven2/",
],
)

RULES_JVM_EXTERNAL_TAG = "2.9"
RULES_JVM_EXTERNAL_SHA = "e5b97a31a3e8feed91636f42e19b11c49487b85e5de2f387c999ea14d77c7f45"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
name = "maven",
artifacts = [
# test of strict deps (scalac plugin UT + E2E)
"com.google.guava:guava:21.0",
# test adding a scala jar:
scala_mvn_artifact(
"com.twitter:scalding-date:0.17.0",
default_scala_major_version(),
),
"org.apache.commons:commons-lang3:3.5",
# test of a plugin
scala_mvn_artifact(
"org.psywerx.hairyfotr:linter:0.1.13",
default_scala_major_version(),
),
# For testing that we don't include sources jars to the classpath
scala_mvn_artifact(
"org.typelevel:cats-core:0.9.0",
default_scala_major_version(),
),
],
repositories = [
"https://jcenter.bintray.com",
"https://repo1.maven.org/maven2",
],
fetch_sources = True,
version_conflict_policy = "pinned",
generate_compat_repositories = True,
)

load("@maven//:compat.bzl", "compat_repositories")
compat_repositories()
4 changes: 2 additions & 2 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ scala_binary(
scala_library(
name = "HelloLib",
srcs = ["HelloLib.scala"],
plugins = ["@org_psywerx_hairyfotr__linter//jar"],
plugins = ["@maven//:org_psywerx_hairyfotr_linter_2_11"],
deps = [
"Exported",
"MacroTest",
Expand Down Expand Up @@ -278,7 +278,7 @@ scala_repl(

scala_library(
name = "jar_export",
exports = ["@com_twitter__scalding_date//jar"],
exports = ["@maven//:com_twitter_scalding_date_2_11"],
)

#Mix java scala
Expand Down
10 changes: 5 additions & 5 deletions test/src/main/scala/scalarules/test/scala_import/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ load("//scala:scala_import.bzl", "scala_import")
scala_import(
name = "guava_and_commons_lang",
jars = [
"@com_google_guava_guava_21_0_with_file//jar:file",
"@org_apache_commons_commons_lang_3_5//jar:file",
"@maven//:v1/https/jcenter.bintray.com/com/google/guava/guava/21.0/guava-21.0.jar",
"@maven//:v1/https/jcenter.bintray.com/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar",
],
)

Expand Down Expand Up @@ -44,7 +44,7 @@ scala_specs2_junit_test(
#filter source jars
scala_import(
name = "cats",
jars = ["@org_typelevel__cats_core//jar:file"],
jars = ["@maven//:v1/https/jcenter.bintray.com/org/typelevel/cats-core_2.11/0.9.0/cats-core_2.11-0.9.0.jar"],
)

scala_library(
Expand Down Expand Up @@ -80,8 +80,8 @@ scala_specs2_junit_test(
java_import(
name = "guava_and_commons_lang_java_import",
jars = [
"@com_google_guava_guava_21_0_with_file//jar:file",
"@org_apache_commons_commons_lang_3_5//jar:file",
"@maven//:v1/https/jcenter.bintray.com/com/google/guava/guava/21.0/guava-21.0.jar",
"@maven//:v1/https/jcenter.bintray.com/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ scala_library(
name = "source_jar_not_oncp",
srcs = ["ReferCatsImplicits.scala"],
deps = [
"@org_typelevel__cats_core//jar",
"@maven//:org_typelevel_cats_core_2_11",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ scala_library(
srcs = [
"B.scala",
],
deps = ["@com_google_guava_guava_21_0_with_file//jar"],
deps = ["@maven//:com_google_guava_guava"],
)
8 changes: 4 additions & 4 deletions test_expect_failure/scala_import/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ load("//scala:scala_import.bzl", "scala_import")

scala_import(
name = "dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage",
jars = ["@org_psywerx_hairyfotr__linter//jar:file"],
jars = ["@maven//:v1/https/jcenter.bintray.com/org/psywerx/hairyfotr/linter_2.11/0.1.13/linter_2.11-0.1.13.jar"],
)

scala_import(
name = "guava",
jars = ["@com_google_guava_guava_21_0_with_file//jar:file"],
jars = ["@maven//:v1/https/jcenter.bintray.com/com/google/guava/guava/21.0/guava-21.0.jar"],
deps = [":dummy_dependency_to_trigger_create_provider_transitive_compile_jar_usage"],
)

scala_import(
name = "cats",
jars = ["@org_typelevel__cats_core//jar:file"],
jars = ["@maven//:v1/https/jcenter.bintray.com/org/typelevel/cats-core_2.11/0.9.0/cats-core_2.11-0.9.0.jar"],
)

scala_import(
Expand All @@ -28,7 +28,7 @@ scala_import(

scala_import(
name = "commons_lang_as_imported_jar_cats_and_guava_as_compile_deps",
jars = ["@org_apache_commons_commons_lang_3_5//jar:file"],
jars = ["@maven//:v1/https/jcenter.bintray.com/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
deps = [
":guava",
":indirection_for_transitive_compile_deps",
Expand Down
4 changes: 2 additions & 2 deletions third_party/dependency_analyzer/src/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ scala_junit_test(
jvm_flags = [
"-Dplugin.jar.location=$(location //third_party/dependency_analyzer/src/main:dependency_analyzer)",
"-Dscala.library.location=$(location //external:io_bazel_rules_scala/dependency/scala/scala_library)",
"-Dguava.jar.location=$(location @com_google_guava_guava_21_0_with_file//jar)",
"-Dguava.jar.location=$(location @maven//:com_google_guava_guava)",
"-Dapache.commons.jar.location=$(location @org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file)",
],
suffixes = ["Test"],
Expand All @@ -22,7 +22,7 @@ scala_junit_test(
"//external:io_bazel_rules_scala/dependency/scala/scala_reflect",
"//third_party/dependency_analyzer/src/main:dependency_analyzer",
"//third_party/utils/src/test:test_util",
"@com_google_guava_guava_21_0_with_file//jar",
"@maven//:com_google_guava_guava",
"@org_apache_commons_commons_lang_3_5_without_file//:linkable_org_apache_commons_commons_lang_3_5_without_file",
],
)

0 comments on commit 35e32d7

Please sign in to comment.