Skip to content

Commit

Permalink
Generate a Maven BOM (#11560)
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c authored Feb 7, 2023
1 parent 99126df commit 4e02ef4
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ JAVA_RELEASE_TARGETS = %w[
//java/src/org/openqa/selenium/firefox:firefox.publish
//java/src/org/openqa/selenium/grid/sessionmap/jdbc:jdbc.publish
//java/src/org/openqa/selenium/grid/sessionmap/redis:redis.publish
//java/src/org/openqa/selenium/grid:bom-dependencies.publish
//java/src/org/openqa/selenium/grid:bom.publish
//java/src/org/openqa/selenium/grid:grid.publish
//java/src/org/openqa/selenium/ie:ie.publish
//java/src/org/openqa/selenium/json:json.publish
Expand Down
11 changes: 3 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,17 @@ rules_proto_dependencies()

rules_proto_toolchains()

RULES_JVM_EXTERNAL_TAG = "4.5"

RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"

http_archive(
name = "rules_jvm_external",
patch_args = [
"-p1",
],
patches = [
"//java:rules_jvm_external_javadoc.patch",
"//java:add_missing_dirs.patch",
],
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/refs/tags/%s.zip" % RULES_JVM_EXTERNAL_TAG,
sha256 = "b6a142dd4ac191d64c855463d4d3de30a7efd629cc65065a833865e34c261b74",
strip_prefix = "rules_jvm_external-cf8286d9b137ab36b89fc6654ce3e6fe48923778",
url = "https://github.com/bazelbuild/rules_jvm_external/archive/cf8286d9b137ab36b89fc6654ce3e6fe48923778.zip",
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
Expand Down
2 changes: 1 addition & 1 deletion java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@contrib_rules_jvm//java:defs.bzl", "spotbugs_config")
load(":defs.bzl", "artifact")

exports_files(
srcs = [
Expand Down
3 changes: 2 additions & 1 deletion java/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load(
_java_binary = "java_binary",
_java_import = "java_import",
)
load("@rules_jvm_external//:defs.bzl", _artifact = "artifact", _javadoc = "javadoc")
load("@rules_jvm_external//:defs.bzl", _artifact = "artifact", _javadoc = "javadoc", _maven_bom = "maven_bom")
load("//java/private:dist_zip.bzl", _java_dist_zip = "java_dist_zip")
load("//java/private:library.bzl", _java_export = "java_export", _java_library = "java_library", _java_test = "java_test")
load("//java/private:merge_jars.bzl", _merge_jars = "merge_jars")
Expand All @@ -29,6 +29,7 @@ java_module = _java_module
java_selenium_test_suite = _java_selenium_test_suite
java_test = _java_test
javadoc = _javadoc
maven_bom = _maven_bom
merge_jars = _merge_jars
selenium_test = _selenium_test
JUNIT5_DEPS = _JUNIT5_DEPS
16 changes: 16 additions & 0 deletions java/private/export.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load(
"javadoc",
"pom_file",
)
load("@rules_jvm_external//private/rules:maven_bom_fragment.bzl", "maven_bom_fragment")
load("@rules_jvm_external//private/rules:maven_project_jar.bzl", "maven_project_jar")
load("@rules_jvm_external//private/rules:maven_publish.bzl", "maven_publish")
load("//java/private:module.bzl", "java_module")
Expand All @@ -16,6 +17,7 @@ def java_export(
opens_to = [],
exports = [],
tags = [],
testonly = None,
visibility = None,
**kwargs):
tags = tags + ["maven_coordinates=%s" % maven_coordinates]
Expand Down Expand Up @@ -94,6 +96,20 @@ def java_export(
visibility = visibility,
)

# We may want to aggregate several `java_export` targets into a single Maven BOM POM
# https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms
maven_bom_fragment(
name = "%s.bom-fragment" % name,
maven_coordinates = maven_coordinates,
artifact = ":%s" % lib_name,
src_artifact = ":%s-maven-source" % name,
javadoc_artifact = None if "no-javadocs" in tags else ":%s-docs" % name,
pom = ":%s-pom" % name,
testonly = testonly,
tags = tags,
visibility = visibility,
)

# Finally, alias the primary output
native.alias(
name = name,
Expand Down
2 changes: 1 addition & 1 deletion java/private/module.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _java_module_impl(ctx):
)

return [
DefaultInfo(files = depset([module_jar, src_jar])),
DefaultInfo(files = depset([module_jar])),
JavaModuleInfo(
name = name,
module_path = depset(direct = [module_jar], transitive = [info.module_path for info in all_infos]),
Expand Down
41 changes: 40 additions & 1 deletion java/src/org/openqa/selenium/grid/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//common:defs.bzl", "copy_file")
load("//java:defs.bzl", "java_binary", "java_dist_zip", "java_export", "java_library", "javadoc", "merge_jars")
load(
"//java:defs.bzl",
"java_binary",
"java_dist_zip",
"java_export",
"java_library",
"javadoc",
"maven_bom",
"merge_jars",
)
load("//java:version.bzl", "SE_VERSION")
load("//java/src/org/openqa/selenium/devtools:versions.bzl", "CDP_DEPS")

Expand Down Expand Up @@ -82,6 +91,36 @@ java_library(
],
)

# Generated from: bazel query 'kind(maven_publish, set(//java/... //third_party/...))' | sort
# with the selenium rc, bom dependencies (naturally), and CDP implementations removed.
maven_bom(
name = "bom",
bom_pom_template = "bom-pom-template.xml",
dependencies_maven_coordinates = "org.seleniumhq.selenium:selenium-dependencies-bom:%s" % SE_VERSION,
dependencies_pom_template = "bom-pom-template.xml",
java_exports = [
"//java/src/org/openqa/selenium/chrome:chrome",
"//java/src/org/openqa/selenium/chromium:chromium",
"//java/src/org/openqa/selenium/edge:edge",
"//java/src/org/openqa/selenium/firefox:firefox",
"//java/src/org/openqa/selenium/grid/sessionmap/jdbc:jdbc",
"//java/src/org/openqa/selenium/grid/sessionmap/redis:redis",
"//java/src/org/openqa/selenium/grid:grid",
"//java/src/org/openqa/selenium/ie:ie",
"//java/src/org/openqa/selenium/json:json",
"//java/src/org/openqa/selenium/lift:lift",
"//java/src/org/openqa/selenium/manager:manager",
"//java/src/org/openqa/selenium/remote/http/jdk:jdk",
"//java/src/org/openqa/selenium/remote/http:http",
"//java/src/org/openqa/selenium/remote:remote",
"//java/src/org/openqa/selenium/safari:safari",
"//java/src/org/openqa/selenium/support:support",
"//java/src/org/openqa/selenium:client-combined",
"//java/src/org/openqa/selenium:core",
] + CDP_DEPS,
maven_coordinates = "org.seleniumhq.selenium:selenium-bom:%s" % SE_VERSION,
)

java_export(
name = "grid",
srcs = glob(
Expand Down
80 changes: 80 additions & 0 deletions java/src/org/openqa/selenium/grid/bom-pom-template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<groupId>{groupId}</groupId>
<artifactId>{artifactId}</artifactId>
<version>{version}</version>
<packaging>pom</packaging>

<name>{groupId}:{artifactId}</name>
<description>Selenium automates browsers. That's it! What you do with that power is entirely up to you.</description>
<url>https://selenium.dev/</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/SeleniumHQ/selenium/</url>
<connection>scm:git:https://github.com/SeleniumHQ/selenium.git</connection>
<developerConnection>scm:git:git@github.com:SeleniumHQ/selenium.git</developerConnection>
</scm>

<developers>
<developer>
<id>simon.m.stewart</id>
<name>Simon Stewart</name>
<roles>
<role>Owner</role>
</roles>
</developer>
<developer>
<id>barancev</id>
<name>Alexei Barantsev</name>
<roles>
<role>Committer</role>
</roles>
</developer>
<developer>
<id>diemol</id>
<name>Diego Molina</name>
<roles>
<role>Committer</role>
</roles>
</developer>
<developer>
<id>james.h.evans.jr</id>
<name>Jim Evans</name>
<roles>
<role>Committer</role>
</roles>
</developer>
<developer>
<id>theautomatedtester</id>
<name>David Burns</name>
<roles>
<role>Committer</role>
</roles>
</developer>
<developer>
<id>titusfortner</id>
<name>Titus Fortner</name>
<roles>
<role>Committer</role>
</roles>
</developer>
</developers>

<dependencyManagement>
<dependencies>
{dependencies}
</dependencies>
</dependencyManagement>
</project>

0 comments on commit 4e02ef4

Please sign in to comment.