Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.0 major repackaging of rule #30 #95

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ bin
# after running the //tools/codecoverage tooling you will be left with this root level folder
# it contains your test results, so do not checkin
coverage-reports

# release zips
rules-spring-*.zip
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## Salesforce Spring Boot Rule for Bazel
## Salesforce Spring Rules for Bazel

This repository contains the [Spring Boot](https://spring.io/guides/gs/spring-boot/) rule for the [Bazel](https://bazel.build/) build system.
It enables Bazel to build Spring Boot applications and package them as an executable jar file.
The executable jar is the best way to deploy your Spring Boot application in production environments.

The Salesforce *springboot* rule can be found, along with documentation, in this location:
- [bazel-springboot-rule](tools/springboot): a Bazel extension to build and package Spring Boot applications
- [springboot](springboot): a Bazel extension to build and package Spring Boot applications

The *springboot* rule runs on any version of Bazel 1.2.1 or higher.
Please do not link to the *master* branch of this rule in your Bazel workspace, use an official release instead:
- [bazel-springboot-rule releases](https://github.com/salesforce/bazel-springboot-rule/releases)
- [rules-spring releases](https://github.com/salesforce/bazel-springboot-rule/releases)

### Support and Ongoing Development

Expand All @@ -22,35 +22,33 @@ To see what bug fixes and new features are planned, consult the roadmaps located

:octocat: Please do us a **huge favor**. If you think this project could be useful for you, now or in the future, please hit the **Star** button at the top. That helps us advocate for more time and resources on this project. Thanks!

### Loading the Rule in your WORKSPACE
### Loading the Spring Rules in your WORKSPACE

Before you can use the rule in your BUILD files, you need to add it to your workspace.
There are two approaches to doing this.

**Reference an official release**
This loads a pre-built version of this rule into your workspace during the build.
It may or may not work for you, as it does not allow you to customize it.
On [our roadmap](https://github.com/salesforce/bazel-springboot-rule/projects/2) we have work items to upgrade this rule to use more modern packaging idioms.
This is the recommended approach for most users.

```starlark
http_archive(
name = "bazel_springboot_rule",
sha256 = "94b0227d73c10fe7566e1faf12e101a8ea18b57322debe90d4ff3494e017592f",
name = "rules_spring",
sha256 = "7d4f12748df340397559decd8348289a6f85ae32dae344545b6d08ad036a9cfe",
urls = [
"https://github.com/salesforce/bazel-springboot-rule/releases/download/1.1.1/bazel-springboot-rule-1.1.1.zip",
"https://github.com/salesforce/bazel-springboot-rule/releases/download/2.0.0/rules-spring-2.0.0.zip",
],
)
```

**Copy the rule into your workspace (aka vendoring)**
This may be the quickest option.
It allows you to bring in the rule, and make customizations as necessary.
This approach allows you to bring in the rule, and make customizations as necessary.
We recommend copying it into location *//tools/springboot* in your workspace but you are free to change this if you like.

Once it is copied in, add this to your WORKSPACE:
```starlark
local_repository(
name = "bazel_springboot_rule",
name = "rules_spring",
path = "tools/springboot",
)
```
Expand All @@ -65,15 +63,30 @@ That approach is sufficient if Bazel and your Bazel workspace (i.e. source code)

At Salesforce, Bazel is not available in production environments, and so this alternate approach is not viable.

### Are you refreshing your fork for the first time since September 29, 2020?
### Migrations

#### Are you refreshing your Spring Boot archive/fork for the first time since March X, 2021?

On that date I merged in the major repackaging of the Spring Boot rule into the *master* branch.
This was to comply with the standardized Bazel rule layout conventions.
When the Spring Boot rule was originally written, the conventions did not exist.
This repackaging makes the rule more modern.

For rule 1.x users, you will need to do the following:
- All WORKSPACE and BUILD file references to *bazel_springboot_rule* must be changed to *rules_spring*
- All BUILD and .bzl file references to *//tools/springboot* must be changed to *//springboot*

See [Repackaging work item](https://github.com/salesforce/bazel-springboot-rule/issues/30) for more details.

#### Are you refreshing your Spring Boot archive/fork for the first time since September 29, 2020?

On that date I switched the repo to use *maven_install* style dependencies, instead of the obsolete *maven_jar* ([removed as of Bazel 2.x](https://github.com/bazelbuild/bazel/issues/6799)).
I tagged the old code line as 1.0.2.
To restore the old style, please use the following stanza in your WORKSPACE (to replace whatever you have there).

```starlark
git_repository(
name = "bazel_springboot_rule",
name = "rules_spring",
tag = "1.0.2",
remote = "https://github.com/salesforce/bazel-springboot-rule",
verbose = False,
Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Licensed under the BSD 3-Clause license.
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
#
workspace(name = "bazel_springboot_rule")
workspace(name = "rules_spring")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand All @@ -18,8 +18,8 @@ http_archive(
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("//:external_deps.bzl", "external_maven_jars")
external_maven_jars()
load("//:repositories.bzl", "rules_spring_deps")
rules_spring_deps()

load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

# load our Spring Boot rule
load("//tools/springboot:springboot.bzl", "springboot")
load("//springboot:springboot.bzl", "springboot")

# dependencies from other packages in the workspace
lib_deps = [
Expand All @@ -16,7 +16,7 @@ lib_deps = [

# create our deps list for Spring Boot
springboot_deps = [
"//tools/springboot/import_bundles:springboot_required_deps",
"//springboot/import_bundles:springboot_required_deps",
"@maven//:org_springframework_boot_spring_boot_starter_jetty",
"@maven//:org_springframework_boot_spring_boot_starter_web",
"@maven//:org_springframework_spring_webmvc",
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ To run:
bazel run //examples/helloworld
```

For full documentation, see the [//tools/springboot](../../tools/springboot) package documentation.
For full documentation, see the [//springboot](../../springboot) package documentation.
12 changes: 6 additions & 6 deletions makerelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
#

RELEASE_VERSION=1.1.2
RELEASE_VERSION=2.0.0

rm -rf bazel-*

TMPDIR=/tmp/bazel-springboot-rule-release
TMPDIR=/tmp/rules-spring-release
mkdir $TMPDIR
mv tools/python_interpreter/bin $TMPDIR
mv tools/python_interpreter/captive_python3 $TMPDIR

rm -rf tools/springboot/tests/__pycache__
rm -rf tools/springboot/__pycache__
rm -rf springboot/tests/__pycache__
rm -rf springboot/__pycache__

jar -cvf bazel-springboot-rule-${RELEASE_VERSION}.zip *
jar -cvf rules-spring-${RELEASE_VERSION}.zip *

mv $TMPDIR/bin tools/python_interpreter
mv $TMPDIR/captive_python3 tools/python_interpreter

echo "RELEASE built: bazel-springboot-rule-${RELEASE_VERSION}.zip"
echo "RELEASE built: rules-spring-${RELEASE_VERSION}.zip"
echo "Remember to update the http_archive stanza in the top level README.md"
7 changes: 3 additions & 4 deletions external_deps.bzl → repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repositories = [
"https://repo1.maven.org/maven2",
]

def external_maven_jars():
def rules_spring_deps():
maven_install(
artifacts = [
"org.slf4j:jcl-over-slf4j:1.7.26",
Expand Down Expand Up @@ -79,7 +79,7 @@ def external_maven_jars():
version_conflict_policy = "pinned",
strict_visibility = True,
generate_compat_repositories = False,
maven_install_json = "@bazel_springboot_rule//:maven_install.json",
maven_install_json = "@rules_spring//:maven_install.json",
resolve_timeout = 1800,
)

Expand All @@ -96,7 +96,6 @@ def external_maven_jars():
version_conflict_policy = "pinned",
strict_visibility = True,
generate_compat_repositories = False,
maven_install_json = "@bazel_springboot_rule//:spring_boot_starter_jetty_install.json",
maven_install_json = "@rules_spring//:spring_boot_starter_jetty_install.json",
resolve_timeout = 1800,
)

File renamed without changes.
13 changes: 6 additions & 7 deletions tools/springboot/README.md → springboot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ This is a *BUILD* file code snippet of how to invoke the rule:

```starlark
# load our Spring Boot rule
load("//tools/springboot:springboot.bzl", "springboot",)
load("//springboot:springboot.bzl", "springboot",)

# create our deps list for Spring Boot, we have some convenience targets for this
springboot_deps = [
"//tools/springboot/import_bundles:springboot_required_deps",
"//springboot/import_bundles:springboot_required_deps",
"@maven//:org_springframework_boot_spring_boot_starter_jetty",
"@maven//:org_springframework_boot_spring_boot_starter_web",
"@maven//:org_springframework_spring_webmvc",
Expand Down Expand Up @@ -45,7 +45,7 @@ The required *springboot* rule attributes are as follows:

## Build and Run

After installing the rule into your workspace at *tools/springboot*, you are ready to build.
After installing the rule into your workspace, you are ready to build.
Add the rule invocation to your Spring Boot application *BUILD* file as shown above.
```bash
# Build
Expand All @@ -71,16 +71,15 @@ The executable jar file is ready to be copied to your production environment.

### Manage External Dependencies in your WORKSPACE

This repository has an example [WORKSPACE](../../external_deps.bzl) file that lists necessary and some optional Spring Boot dependencies.
This repository has an example [WORKSPACE](../../WORKSPACE) file that lists necessary and some optional Spring Boot dependencies.
These will come from a Nexus/Artifactory repository, or Maven Central.
Because the version of each dependency needs to be explicitly defined, it is left for you to review and add to your *WORKSPACE* file.
You will then need to follow an iterative process, adding external dependencies to your *BUILD* and *WORKSPACE* files until it builds and runs.

### Convenience Import Bundles

The [//tools/springboot/import_bundles](import_bundles) package contains some example bundles of imports.
There are bundles for the Spring Boot framework, as well as bundles for the various starters.
The ones provided in this repository are just examples.
The [//springboot/import_bundles](import_bundles) package contains a list of core set of Spring Boot dependencies.
We recommend starting with this list, and then creating your own bundles if it helps.

### Detecting, Excluding and Suppressing Unwanted Classes

Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions springboot/import_bundles/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright (c) 2017-2021, salesforce.com, inc.
# All rights reserved.
# Licensed under the BSD 3-Clause license.
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
#

# List of standard imports bundles that most/all Spring Boot app will need.

java_import(
name = "springboot_required_deps",
jars = [],
visibility = ["//visibility:public"],
exports = [
"@maven//:org_springframework_boot_spring_boot",
"@maven//:org_springframework_boot_spring_boot_actuator",
"@maven//:org_springframework_boot_spring_boot_actuator_autoconfigure",
"@maven//:org_springframework_boot_spring_boot_autoconfigure",
"@maven//:org_springframework_boot_spring_boot_loader",
"@maven//:org_springframework_boot_spring_boot_starter",
"@maven//:org_springframework_boot_spring_boot_starter_logging",
"@maven//:org_springframework_spring_aop",
"@maven//:org_springframework_spring_beans",
"@maven//:org_springframework_spring_context",
"@maven//:org_springframework_spring_core",
"@maven//:org_springframework_spring_expression",
"@maven//:org_springframework_spring_web",
],
)
11 changes: 11 additions & 0 deletions springboot/import_bundles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Import Bundles for Spring Boot Starters

This is a scheme for providing convenience bundles of dependencies for each open source Spring Boot starter.
*springboot_required_deps* is a convenience bundle that contains the core list that all Spring Boot apps need.
We used to maintain others, but have since removed all other bundles.

```starlark
deps = [
"//springboot/import_bundles:springboot_required_deps",
]
```
16 changes: 8 additions & 8 deletions tools/springboot/springboot.bzl → springboot/springboot.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ def springboot(
native.genrule(
name = genmanifest_rule,
srcs = [":" + dep_aggregator_rule],
cmd = "$(location @bazel_springboot_rule//tools/springboot:write_manifest.sh) " + boot_app_class + " $@ $(SRCS)",
cmd = "$(location @rules_spring//springboot:write_manifest.sh) " + boot_app_class + " $@ $(SRCS)",
# message = "SpringBoot rule is writing the MANIFEST.MF...",
tools = ["@bazel_springboot_rule//tools/springboot:write_manifest.sh"],
tools = ["@rules_spring//springboot:write_manifest.sh"],
outs = [genmanifest_out],
tags = tags,
)
Expand All @@ -326,16 +326,16 @@ def springboot(
gengitinfo_out = "git.properties"
native.genrule(
name = gengitinfo_rule,
cmd = "$(location @bazel_springboot_rule//tools/springboot:write_gitinfo_properties.sh) $@",
tools = ["@bazel_springboot_rule//tools/springboot:write_gitinfo_properties.sh"],
cmd = "$(location @rules_spring//springboot:write_gitinfo_properties.sh) $@",
tools = ["@rules_spring//springboot:write_gitinfo_properties.sh"],
outs = [gengitinfo_out],
tags = tags,
stamp = 1,
)

# SUBRULE 2C: CLASSPATH INDEX
if classpath_index == None:
classpath_index = "@bazel_springboot_rule//tools/springboot:empty.txt"
classpath_index = "@rules_spring//springboot:empty.txt"

# see https://github.com/salesforce/bazel-springboot-rule/issues/81
_appjar_locator_rule(
Expand Down Expand Up @@ -368,11 +368,11 @@ def springboot(
classpath_index,
":" + dep_aggregator_rule,
],
cmd = "$(location @bazel_springboot_rule//tools/springboot:springboot_pkg.sh) " +
cmd = "$(location @rules_spring//springboot:springboot_pkg.sh) " +
"$(location @bazel_tools//tools/jdk:singlejar) " + boot_app_class +
" $(JAVABASE) " + name + " " + str(use_build_dependency_order) + " $@ $(SRCS)",
tools = [
"@bazel_springboot_rule//tools/springboot:springboot_pkg.sh",
"@rules_spring//springboot:springboot_pkg.sh",
"@bazel_tools//tools/jdk:singlejar",
],
tags = tags,
Expand All @@ -388,7 +388,7 @@ def springboot(
if fail_on_duplicate_classes:
_dupeclasses_rule(
name = dupecheck_rule,
script = "@bazel_springboot_rule//tools/springboot:check_dupe_classes",
script = "@rules_spring//springboot:check_dupe_classes",
springbootjar = genjar_rule,
allowlist = duplicate_class_allowlist,
fail_on_duplicate_classes = fail_on_duplicate_classes,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ do
done

if [[ $FOUND_SPRING_JAR -ne 1 ]]; then
echo "ERROR: //tools/springboot/write_manifest.sh could not find spring-boot jar"
echo "ERROR: //springboot/write_manifest.sh could not find spring-boot jar"
exit 1
fi

Expand Down
6 changes: 3 additions & 3 deletions tools/buildstamp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ The way to signal to Bazel to stamp a particular artifact is to add an attribute
stamp = 1
```

This is done automatically for you in the [Spring Boot rule](../springboot/springboot.bzl)
This is done automatically for you in the [Spring Boot rule](../../springboot/springboot.bzl)
when it generates the *git.properties* file, as seen in this snippet:

```starlark
gengitinfo_out = "git.properties"
native.genrule(
name = gengitinfo_rule,
cmd = "$(location //tools/springboot:write_gitinfo_properties.sh) $@",
tools = ["//tools/springboot:write_gitinfo_properties.sh"],
cmd = "$(location //springboot:write_gitinfo_properties.sh) $@",
tools = ["//springboot:write_gitinfo_properties.sh"],
outs = [gengitinfo_out],
tags = tags,
stamp = 1,
Expand Down
4 changes: 2 additions & 2 deletions tools/buildstamp/get_workspace_status
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# More information:
# Bazel stamping: https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
# Spring Boot git.properties: //tools/springboot/write_gitinfo_properties.sh
# Spring Boot git.properties: //springboot/write_gitinfo_properties.sh
# Spring Boot info actuator endpoint: ttps://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints

# First, make sure the current working directory is the Bazel workspace root.
Expand Down Expand Up @@ -56,7 +56,7 @@ echo "Full Bazel build stamping enabled. Adding Git properties to stamp. See //t
# GIT
# ********************************

# This data is then later consumed by the //tools/springboot rule (perhaps other rules as well) to write
# This data is then later consumed by the //springboot rule (perhaps other rules as well) to write
# a git.properties file into the Spring Boot jar, which is then surfaced in the Spring Boot
# actuator info endpoint.

Expand Down
2 changes: 1 addition & 1 deletion tools/formatter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This script runs the Bazel buildifier tool on all of our Bazel files (BUILD, \*.
Execute it from the root of the repo.

```bash
cd bazel-springboot-rule
cd rules-spring
./tools/formatter/format_bazel_files.sh
```

Expand Down
Loading