git_repository(
name = "graknlabs_bazel_distribution",
remote = "https://github.com/graknlabs/bazel-distribution",
commit = "e181add439dc1cfb7b1c27db771ec741d5dd43e6"
)
for each artifact you want to publish to maven central,
create an aggregate scala_library
target that includes sources for all finer-grained targets (if you have
targets with coarse-grained granularity you can skip this step)
scala_library(
name = "greyhound-core",
srcs = [
"//core/src/main/scala/com/wixpress/dst/greyhound/core:sources",
"//core/src/main/scala/com/wixpress/dst/greyhound/core/admin:sources",
"//core/src/main/scala/com/wixpress/dst/greyhound/core/consumer:sources",
"//core/src/main/scala/com/wixpress/dst/greyhound/core/metrics:sources",
"//core/src/main/scala/com/wixpress/dst/greyhound/core/producer:sources",
],
tags = ["maven_coordinates=com.wix:greyhound-core_2.12:{pom_version}"],
visibility = ["//:__subpackages__"],
deps = [
"@dev_zio_zio_2_12",
"@org_apache_kafka_kafka_clients",
"@org_slf4j_slf4j_api",
],
)
A few notes:
- All the labels in srcs are actually filegroup with appropriate visibility settings that allow out-of-package dependency:
filegroup(
name = "sources",
srcs = glob(["*.java"]) + glob(["*.scala"]),
visibility = ["//core:__subpackages__"],
)
- There is a special
maven_coordinates
tag that helps theassemble_maven
rule to fill-in details in the pom file. - You also have to add a
maven_coordinates
tag to the 3rd party dependencies (such asdev_zio_zio_2_12
in the deps attribute of the example above) so that they will appear as dependencies in the pom file.
Add assemble_maven target for each artifact you want to publish. It will create all the necessary files for your artifact, including main jar, source jar and pom file. Enter all project details for the pom file.
load("@graknlabs_bazel_distribution//maven/templates:rules.bzl", "deploy_maven", "assemble_maven")
assemble_maven(
name = "assemble-maven",
target = "//core:greyhound-core",
package = "{maven_packages}",
project_name = "Greyhound Core",
project_description = "Greyhound - Rich Kafka Client with ZIO API",
project_url = "https://github.com/wix/greyhound",
scm_url = "https://github.com/wix/greyhound.git",
version_file = "//central-sync:VERSION",
developers = {"1": ["name=Natan Silnitsky", "[email protected]", "organization=Wix"]},
license = "mit"
)
Notes:
- For the target attribute you should put the label for the
scala_library
target you created in the previous step with all the relevant sources. - Make sure the
project_name
andproject_description
are unique for each of these targets/artifacts - The
VERSION
file just contains the SEMVER, e.g. 1.0.0 - Currently supported licenses include
apache
andMIT
Add deploy_maven
target for each artifact you want to publish.
The deployment.properties
file should contain the url for the sonatype stating area:
repo.maven.release=https://oss.sonatype.org/service/local/staging/deploy/maven2/
Build the assemble_maven target and review the generated pom file and jar file in the bazel-bin directory. Change the targets configuration as needed.
For more specific information on publishing to Maven Central repository, see this blog post