Bael 2989 (#7609)
* Added examples for building Java project with Bazel * Added examples for building Java project with Bazel
This commit is contained in:
parent
39a2838ba0
commit
d3ba9f47ef
|
@ -0,0 +1,31 @@
|
|||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
|
||||
RULES_JVM_EXTERNAL_TAG = "2.0.1"
|
||||
RULES_JVM_EXTERNAL_SHA = "55e8d3951647ae3dffde22b4f7f8dee11b3f70f3f89424713debd7076197eaca"
|
||||
|
||||
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(
|
||||
artifacts = [
|
||||
"org.apache.commons:commons-lang3:3.9"
|
||||
],
|
||||
repositories = [
|
||||
"https://repo1.maven.org/maven2",
|
||||
]
|
||||
)
|
||||
|
||||
http_jar (
|
||||
name = "apache-commons-lang",
|
||||
url = "https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar"
|
||||
)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
java_binary (
|
||||
name = "BazelApp",
|
||||
srcs = glob(["src/main/java/com/baeldung/*.java"]),
|
||||
main_class = "com.baeldung.BazelApp",
|
||||
deps = ["//bazelgreeting:greeter", "@maven//:org_apache_commons_commons_lang3"]
|
||||
)
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>bazel</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>bazelapp</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>bazelgreeting</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung;
|
||||
|
||||
import com.baeldung.Greetings;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class BazelApp {
|
||||
|
||||
public static void main(String ... args) {
|
||||
Greetings greetings = new Greetings();
|
||||
|
||||
System.out.println(greetings.greet("Bazel"));
|
||||
|
||||
System.out.println(StringUtils.lowerCase("Bazel"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
java_library (
|
||||
name = "greeter",
|
||||
srcs = glob(["src/main/java/com/baeldung/*.java"]),
|
||||
visibility = ["//bazelapp:__pkg__"]
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>bazel</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>bazelgreeting</artifactId>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung;
|
||||
|
||||
public class Greetings {
|
||||
|
||||
public String greet(String name) {
|
||||
return "Hello ".concat(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>bazel</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>bazelgreeting</module>
|
||||
<module>bazelapp</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue