-
-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement an example maven project (#15)
* Implement an example maven project * Removed glob for srcs
- Loading branch information
Showing
7 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
bazel-bin | ||
bazel-genfiles | ||
bazel-java-maven | ||
bazel-out | ||
bazel-testlogs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
java_library( | ||
name = "java-maven-lib", | ||
srcs = glob(["src/main/java/com/example/myproject/*.java"]), | ||
deps = ["@com_google_guava_guava//jar"], | ||
) | ||
|
||
java_binary( | ||
name = "java-maven", | ||
main_class = "com.example.myproject.App", | ||
runtime_deps = [":java-maven-lib"], | ||
) | ||
|
||
java_test( | ||
name = "tests", | ||
srcs = glob(["src/test/java/com/example/myproject/*.java"]), | ||
test_class = "com.example.myproject.TestApp", | ||
deps = [ | ||
":java-maven-lib", | ||
"@com_google_guava_guava//jar", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Maven Java application | ||
---------------------- | ||
|
||
This project demonstrates the usage of Bazel to retrieve dependencies from | ||
Maven repositories. | ||
|
||
To build this example, you will need to | ||
[install Bazel](http://bazel.io/docs/install.html). | ||
|
||
The Java application makes use of a library in [Guava](https://github.com/google/guava), which is downloaded from a remote repository using Maven. | ||
|
||
This application demonstrates the usage of rules `maven_jar` and `maven_server` to configure dependencies. The dependencies are configured in the `WORKSPACE` file. | ||
|
||
Build the application by running: | ||
|
||
``` | ||
$ bazel build :java-maven | ||
``` | ||
|
||
Test the application by running: | ||
|
||
``` | ||
$ bazel test :tests | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
maven_jar( | ||
name = "com_google_guava_guava", | ||
artifact = "com.google.guava:guava:18.0", | ||
server = "maven_uk_server", | ||
) | ||
|
||
maven_server( | ||
name = "maven_uk_server", | ||
url = "http://uk.maven.org/maven2", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.myproject; | ||
|
||
import com.google.common.primitives.Ints; | ||
|
||
/** | ||
* This application compares two numbers, using the Ints.compare | ||
* method from Guava. | ||
*/ | ||
public class App { | ||
|
||
public static int compare(int a, int b) { | ||
return Ints.compare(a, b); | ||
} | ||
|
||
public static void main(String... args) throws Exception { | ||
App app = new App(); | ||
System.out.println("Success: " + app.compare(2, 1)); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
java-maven/src/test/java/com/example/myproject/TestApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.myproject; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for correct dependency retrieval with maven rules. | ||
*/ | ||
public class TestApp { | ||
|
||
@Test | ||
public void testCompare() throws Exception { | ||
App app = new App(); | ||
assertEquals("should return 0 when both numbers are equal", 0, app.compare(1, 1)); | ||
} | ||
|
||
} |