diff --git a/.plzconfig b/.plzconfig index eb59b60..bf168eb 100644 --- a/.plzconfig +++ b/.plzconfig @@ -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 diff --git a/ChangeLog b/ChangeLog index 544a370..01fdbd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/README.md b/README.md index aa269ae..87a02fa 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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", @@ -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", @@ -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: @@ -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`. ``` @@ -103,7 +103,7 @@ 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"] @@ -111,7 +111,7 @@ 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"] @@ -119,7 +119,7 @@ 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` ``` @@ -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 @@ -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. ``` @@ -166,7 +166,7 @@ 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"] @@ -174,8 +174,8 @@ 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: @@ -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 +``` diff --git a/VERSION b/VERSION index 0bfccb0..8f0916f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.5 +0.5.0 diff --git a/build_defs/java.build_defs b/build_defs/java.build_defs index fafdeec..51f19be 100644 --- a/build_defs/java.build_defs +++ b/build_defs/java.build_defs @@ -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] diff --git a/third_party/java/BUILD b/third_party/java/BUILD index bdf9854..589a1f9 100644 --- a/third_party/java/BUILD +++ b/third_party/java/BUILD @@ -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 @@ -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( @@ -66,6 +81,10 @@ maven_jar( ":logback-core", ":slf4j-api", ], + licences = [ + "EPL-1.0", + "LGPL-2.1-only", + ], ) maven_jar( @@ -73,6 +92,10 @@ maven_jar( hash = "47c0fd342995d3315b8faccacc324b2a76143b27c430d4b2d6a29eabc31f5c14", id = "ch.qos.logback:logback-core:1.1.3", test_only = True, + licences = [ + "EPL-1.0", + "LGPL-2.1-only", + ], ) maven_jar( @@ -80,4 +103,7 @@ maven_jar( hash = "3863e27005740d4d1289bf87b113efea115e9a22408a7d623be8004991232bfe", id = "org.slf4j:slf4j-api:1.7.10", test_only = True, + licences = [ + "MIT", + ] )