Skip to content

Commit

Permalink
build: use rules_spring bazel rule to build/run spring boot projects
Browse files Browse the repository at this point in the history
  • Loading branch information
damingerdai committed Feb 12, 2024
1 parent 69d9bdf commit b637da5
Show file tree
Hide file tree
Showing 4 changed files with 4,431 additions and 6 deletions.
24 changes: 19 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test")
load("@rules_spring//springboot:springboot.bzl", "springboot")

package(default_visibility = ["//visibility:public"])

java_library(
name = "java-maven-lib",
name = "jobs-lib",
srcs = glob([
"src/main/java/org/daming/jobs/*.java",
"src/main/java/org/daming/jobs/api/advice/*.java",
Expand Down Expand Up @@ -36,11 +37,14 @@ java_library(
"@maven//:org_springframework_boot_spring_boot_devtools",

"@maven//:org_springframework_boot_spring_boot",
"@maven//:org_springframework_boot_spring_boot_loader",
"@maven//:org_springframework_boot_spring_boot_loader_tools",
"@maven//:org_springframework_boot_spring_boot_autoconfigure",
"@maven//:org_springframework_spring_aop",
"@maven//:org_springframework_spring_beans",
"@maven//:org_springframework_spring_core",
"@maven//:org_springframework_spring_context",
"@maven//:org_springframework_spring_expression",
"@maven//:org_springframework_spring_web",

# "@maven//:org_apache_shiro_shiro_spring_boot_starter",
Expand All @@ -51,10 +55,9 @@ java_library(
"@maven//:org_slf4j_slf4j_api",

"@maven//:org_quartz_scheduler_quartz",

"@maven//:org_aspectj_aspectjweaver",

"@maven//:org_apache_tomcat_embed_tomcat_embed_core",
"@maven//:jakarta_servlet_jakarta_servlet_api",
"@maven//:jakarta_annotation_jakarta_annotation_api",
"@maven//:jakarta_xml_bind_jakarta_xml_bind_api",
"@maven//:com_fasterxml_jackson_core_jackson_core",
Expand All @@ -65,18 +68,29 @@ java_library(
java_binary(
name = "jobs",
main_class = "org.daming.jobs.JobsApplication",
runtime_deps = [":java-maven-lib"],
runtime_deps = [":jobs-lib"],
deploy_manifest_lines = {
"Main-Class": "org.daming.jobs.JobsApplication",
},
)

springboot(
name = "springboot",
# specify the main class
boot_app_class = "org.daming.jobs.JobsApplication",
# refrence the library
java_library = ":jobs-lib",
# https://github.com/salesforce/rules_spring/issues/177
boot_launcher_class = 'org.springframework.boot.loader.launch.JarLauncher',
)


# java_test(
# name = "tests",
# srcs = glob(["src/test/java/com/example/myproject/*.java"]),
# test_class = "com.example.myproject.TestApp",
# deps = [
# ":java-maven-lib",
# ":jobs-lib",
# "@maven//:com_google_guava_guava",
# "@maven//:junit_junit",
# ],
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ yarn start
open the [browser](http://localhost:3000/)
![login](https://raw.githubusercontent.com/damingerdai/jobs/master/screenshots/login.png)

## bazel

new manve install json

```
bazel run @maven//:pin
```

update maven install json

```
bazel run @unpinned_maven//:pin
```


build and run

```
bazel build //:springboot
bazel run //:springboot
```

#### Swagger UI

`jobs` support [swagger ui](http://127.0.0.1:8443/swagger-ui/index.html).
Expand Down
24 changes: 23 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ http_archive(

)

http_archive(
name = "rules_spring",
sha256 = "7bb891ccb2f53ca188a769b3a3777be1c38348e18091afea05320f3003b3e886",
urls = [
"https://github.com/salesforce/rules_spring/releases/download/2.3.1/rules-spring-2.3.1.zip",
"https://mirror.ghproxy.com/https://github.com/salesforce/rules_spring/releases/download/2.3.1/rules-spring-2.3.1.zip",
],
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()
Expand Down Expand Up @@ -54,22 +63,31 @@ shiros = [
artifact = "shiro-web",
version = "1.13.0",
classifier = "jakarta",

),

]

maven_install(
artifacts = [
"org.springframework.boot:spring-boot:3.2.2",
"org.springframework.boot:spring-boot-starter:3.2.2",
"org.springframework.boot:spring-boot-loader-tools:3.2.2",
"org.springframework.boot:spring-boot-loader:3.2.2",
"org.springframework.boot:spring-boot-starter:3.2.2",
"org.springframework.boot:spring-boot-starter-web:3.2.2",
"org.springframework.boot:spring-boot-starter-jdbc:3.2.2",
"org.springframework.boot:spring-boot-starter-quartz:3.2.2",
"org.springframework.boot:spring-boot-starter-aop:3.2.2",

#"org.springframework.boot:spring-boot-configuration-processor:3.2.2",

"io.springfox:springfox-boot-starter:3.0.0",
"com.auth0:java-jwt:3.19.4",
"org.postgresql:postgresql:42.4.0",

"jakarta.servlet:jakarta.servlet-api:6.0.0",
'javax.annotation:javax.annotation-api:1.3.2',

"org.springframework.boot:spring-boot-devtools:3.2.2",
"org.springframework.boot:spring-boot-starter-test:3.2.2"

Expand All @@ -82,7 +100,11 @@ maven_install(
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
maven_install_json = "//:maven_install.json",
# override_targets = {
# "javax.servlet:javax.servlet-api": "jakarta.servlet:jakarta.servlet-api",
# },
)

load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()
Loading

0 comments on commit b637da5

Please sign in to comment.