Skip to content
Open
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
8 changes: 7 additions & 1 deletion .plzconfig
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,11 @@ Help = The maven repo to use for maven_jar
[PluginConfig "home"]
ConfigKey = Home
Optional = true
Help = Sets the java home variable
Help = Sets the java home variable
Inherit = True

[PluginConfig "require_licences"]
DefaultValue = false
Type = bool
Inherit = true
Help = If set, the licences field on maven_jar will be mandatory
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.4.6
-------------
* Add `require_licences` to plugin config

Version 0.4.5
-------------
* fix `java_test` using f-string to test package arg
Expand Down
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Java rules
# Java rules

This repo provides Java rules for the [please](https://please.build) build system.

# Basic usage
See `./example` in this repo for a working example.
See `./example` in this repo for a working example.

```python
# BUILD
Expand All @@ -23,18 +23,18 @@ java_library(
)

# src/test/java/build/please/foo/BUILD
# A test for the above library.
# A test for the above library.
java_test(
name = "foo_test",
srcs = ["FooTest.java"],
deps = [
"//third_party/java:junit",
"//third_party/java:junit",
"//src/main/java/build/please/foo",
]
)

# src/main/java/build/please/foo/BUILD
# This produces a self-executing .jar
# This produces a self-executing .jar
java_binary(
name = "app",
main_class = "build.please.Main",
Expand All @@ -43,7 +43,7 @@ java_binary(
)

# third_party/java/BUILD
# These rules pull down third party dependencies from maven.
# These rules pull down third party dependencies from maven.
maven_jar(
name = "junit",
hash = "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a",
Expand All @@ -65,8 +65,8 @@ Then add this to your `.plzconfig`:
[Parse]
PreloadSubincludes = @java_rules//build_defs:java
```
Alternatively, if you're not using Java everywhere, you may add `subinclude("@java_rules//build_defs:java")` to each
BUILD individually.
Alternatively, if you're not using Java everywhere, you may add `subinclude("@java_rules//build_defs:java")` to each
BUILD individually.

## Toolchain
By default, Please will use the JDK on the path. Optionally, you may use `java_toolchain()` to manage your JDK:
Expand All @@ -92,9 +92,9 @@ Plugins are configured through the Plugin section like so:
SomeConfig = some value
```

The available configuration options for this plugin are documented here.
The available configuration options for this plugin are documented here.

## JavacTool
## JavacTool
The path to the Java compiler to use. Defaults to `javac`.

```
Expand All @@ -103,23 +103,23 @@ JavacTool = /opt/java/bin/javac
```

## JavacFlags
Any additional flags to apply to the javac tool.
Any additional flags to apply to the javac tool.

```
[Plugin "java"]
JavacFalgs = --flag1 --flag2
```

## JavacTestFlags
Any additional flags to apply to the javac tool when compiling tests.
Any additional flags to apply to the javac tool when compiling tests.

```
[Plugin "java"]
TestJavacFlags = --flag1 --flag2
```

## JunitRunner
The tool used to run Java tests. Defaults to the junit runner for this plugin version
The tool used to run Java tests. Defaults to the junit runner for this plugin version
i.e. `@java_rules//tools:junit_runner`

```
Expand All @@ -135,7 +135,7 @@ JunitRunner = //tools:my_custom_junit_runner
```

## SourceLevel
The source level of the project. Defaults to 8.
The source level of the project. Defaults to 8.
```
[Plugin "java"]
SourceLevel = 15
Expand All @@ -156,7 +156,7 @@ ReleaseLevel = 15
```

## Toolchain
If set, please will use the jdk provided by the `java_toolchain()` rule specified by this build label. See the toolchain
If set, please will use the jdk provided by the `java_toolchain()` rule specified by this build label. See the toolchain
section above for more info.

```
Expand All @@ -166,16 +166,16 @@ Toolchain = //third_party/java:toolchain

## DefaultTestPackage
The test package to use when none is specifically set on the `java_test()` rule. If not set, Please will run all tests
present in the `.jar` that are not from third party code.
present in the `.jar` that are not from third party code.

```
[Plugin "java"]
DefaultTestPackage = please.build.
```

## MavenRepo
The maven repositories to load jars from. This value can be repeated and defaults to `https://repo1.maven.org/maven2`
and `https://repo.maven.apache.org/maven2`, the canonical Maven Central repository URLs.
The maven repositories to load jars from. This value can be repeated and defaults to `https://repo1.maven.org/maven2`
and `https://repo.maven.apache.org/maven2`, the canonical Maven Central repository URLs.

To add a custom repo, you may do so by setting the following:

Expand All @@ -185,3 +185,11 @@ MavenRepo = https://repo1.maven.org/maven2
MavenRepo = https://repo.maven.apache.org/maven2
MavenRepo = https://maven.repo.org
```

## RequireLicences
To require licences for Mavan jars, you set the `RequireLicences` option to true.

```
[Plugin "java"]
RequireLicences = true
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.5
0.5.0
6 changes: 6 additions & 0 deletions build_defs/java.build_defs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,12 @@ def maven_jar(name:str, id:str, repository:str|list=None, labels:list=[], hash:s

def _parse_maven_artifact(id, sources=True, licences=None):
"""Parses a Maven artifact in group:artifact:version format, with possibly some extras."""

if not licences:
msg = f'No licence found for {id}, should add licences = [...] to the rule'
if CONFIG.JAVA.REQUIRE_LICENCES:
fail(msg)

parts = id.split(':')
if len(parts) == 5:
group, artifact, version = parts[:3]
Expand Down
26 changes: 26 additions & 0 deletions third_party/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@ maven_jar(
deps = [
":hamcrest",
],
licences = [
"EPL-1.0",
],
)

maven_jar(
name = "hamcrest",
hash = "4877670629ab96f34f5f90ab283125fcd9acb7e683e66319a68be6eb2cca60de",
id = "org.hamcrest:hamcrest-all:1.3",
licences = [
"BSD-3-Clause",
],
)

maven_jar(
name = "gson",
hash = "53bc5fe7644db908e6071d6c8b59059acadce7fc14217933d7251994e8673104",
id = "com.google.code.gson:gson:2.8.4",
licences = [
"Apache-2.0",
],
)

# These are shipped as components of Please, but for easier management the code lives in
Expand All @@ -49,12 +58,18 @@ maven_jar(
":jacoco_shaded",
":junit",
],
licences = [
"Apache-2.0",
],
)

maven_jar(
name = "jacoco_shaded",
hashes = ["9927bc9184d434c8ed0ed7ba46257df36e31dbd6bd224845d7a02d9e0894da4c"],
id = "build.please:jacoco-shaded:0.8.4",
licences = [
"Apache-2.0",
]
)

maven_jar(
Expand All @@ -66,18 +81,29 @@ maven_jar(
":logback-core",
":slf4j-api",
],
licences = [
"EPL-1.0",
"LGPL-2.1-only",
],
)

maven_jar(
name = "logback-core",
hash = "47c0fd342995d3315b8faccacc324b2a76143b27c430d4b2d6a29eabc31f5c14",
id = "ch.qos.logback:logback-core:1.1.3",
test_only = True,
licences = [
"EPL-1.0",
"LGPL-2.1-only",
],
)

maven_jar(
name = "slf4j-api",
hash = "3863e27005740d4d1289bf87b113efea115e9a22408a7d623be8004991232bfe",
id = "org.slf4j:slf4j-api:1.7.10",
test_only = True,
licences = [
"MIT",
]
)
Loading