Giter Site home page Giter Site logo

rules_groovy's Introduction

Build status

๐Ÿ“ฃ [Unmaintained] Groovy Rules

Warning

Due to an absence of any maintainers, this repository is archived and currently unmaintained.

We discourage any new dependencies on the contents of this repository.

If you, or your organization, are interested in revitalizing this project by taking over its maintenance, we welcome your initiative. To discuss the process of un-archiving and assuming ownership of this repository, please reach out to us via email at [email protected] or join the conversation on our Slack workspace in the #rules channel. You can sign up for Slack access at https://slack.bazel.build.

Overview

These build rules are used for building Groovy projects with Bazel. Groovy libraries may interoperate with and depend on Java libraries and vice-versa.

Setup

To be able to use the Groovy rules, you must provide bindings for the following targets:

  • //external:groovy-sdk, pointing at the Groovy SDK binaries
  • //external:groovy, pointing at the Groovy core language jar
  • //external:junit, pointing at JUnit (only required if using the test rules)
  • //external:spock, pointing at Spock (only required if using spock_test)

The easiest way to do so is to add the following to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "io_bazel_rules_groovy",
    url = "https://github.com/bazelbuild/rules_groovy/archive/0.0.6.tar.gz",
    sha256 = "21c7172786623f280402d3b3a2fc92f36568afad5a4f6f5ea38fd1c6897aecf8",
    strip_prefix = "rules_groovy-0.0.6",
)
load("@io_bazel_rules_groovy//groovy:repositories.bzl", "rules_groovy_dependencies")
rules_groovy_dependencies()

Basic Example

Suppose you have the following directory structure for a simple Groovy and Java application:

[workspace]/
    WORKSPACE
    src/main/groovy/
        app/
            BUILD
            GroovyApp.groovy
        lib/
            BUILD
            GroovyLib.groovy
            JavaLib.java
    src/test/groovy/
        lib/
            BUILD
            LibTest.groovy

Then, to build the code under src/main/groovy/lib/, your src/main/groovy/lib/BUILD can look like this:

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_library")

groovy_library(
    name = "groovylib",
    srcs = glob(["*.groovy"]),
    visibility = ["//visibility:public"],
    deps = [
        ":javalib",
    ],
)

java_library(
    name = "javalib",
    srcs = glob(["*.java"]),
)

For simplicity, you can combine Groovy and Java sources into a single library using groovy_and_java_library. Note that this allows the Groovy code to reference the Java code, but not vice-versa. Your src/main/groovy/lib/BUILD file would then look like this:

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_and_java_library")

groovy_and_java_library(
    name = "lib",
    srcs = glob(["*.groovy", "*.java"]),
)

To build the application under src/main/groovy/app, you can define a binary using groovy_binary as follows:

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_binary")

groovy_binary(
    name = "GroovyApp",
    srcs = glob(["*.groovy"]),
    main_class = "app.GroovyApp",
    deps = [
         "//src/main/groovy/lib:groovylib",
    ],
)

Finally, you can write tests in Groovy using groovy_test. The srcs of this rule will be converted into names of class files that are passed to JUnit. For this to work, the test sources must be under src/test/groovy or src/test/java. To build the test under src/test/groovy/lib, your BUILD file would look like this:

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_test", "groovy_library")


groovy_library(
  name = "testlib",
  srcs = glob(["*.groovy"]),
)

groovy_test(
  name = "LibTest",
  srcs = ["LibTest.groovy"],
  deps = [":testlib"],
)

If you're using JUnit or Spock, see groovy_junit_test or spock_test for wrappers that make testing with these systems slightly more convenient.

groovy_library

groovy_library(name, srcs, deps, **kwargs)
Attributes
name Name, required

A unique name for this rule.

srcs List of labels, required

List of .groovy source files used to build the library.

deps List of labels or .jar files, optional

List of other libraries to be included on the compile-time classpath when building this library.

These can be either other `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

**kwargs see java_binary

The other arguments of this rule will be passed to the `java_import` that wraps the groovy library.

groovy_and_java_library

groovy_and_java_library(name, srcs, deps, **kwargs)
Attributes
name Name, required

A unique name for this rule.

srcs List of labels, required

List of .groovy and .java source files used to build the library.

deps List of labels or .jar files, optional

List of other libraries to be included on the compile-time classpath when building this library.

These can be either other `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

**kwargs see java_binary

The other arguments of this rule will be passed to the `java_import` that wraps the groovy library.

groovy_binary

groovy_binary(name, main_class, srcs, deps, **kwargs)
Attributes
name Name, required

A unique name for this rule.

main_class String, required

The name of either a class containing a `main` method or a Groovy script file to use as an entry point (see here for more details on scripts vs. classes).

srcs List of labels, required

List of .groovy source files used to build the application.

deps List of labels or .jar files, optional

List of other libraries to be included on both the compile-time classpath when building this application and the runtime classpath when executing it.

These can be `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

**kwargs see java_binary

The other arguments of this rule will be passed to the `java_binary` underlying the `groovy_binary`.

groovy_test

groovy_test(name, deps, srcs, data, resources, jvm_flags, size, tags)
Attributes
name Name, required

A unique name for this rule.

srcs List of labels, required

List of .groovy source files whose names will be converted to classes passed to JUnitCore.

deps List of labels or .jar files, optional

List of libraries to be included on both the compile-time classpath when building this test and on the runtime classpath when executing it.

These can be `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

resources List of labels, optional

A list of data files to include on the test's classpath. This is accomplished by creating a `java_library` containing only the specified resources and including that library in the test's dependencies.

jvm_flags List of strings, optional

A list of flags to embed in the wrapper script generated for running this binary.

groovy_junit_test

groovy_junit_test(name, tests, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags)
Attributes
name Name, required

A unique name for this rule.

tests List of labels, required

List of .groovy source files that will be used as test specifications that will be executed by JUnit.

groovy_srcs List of labels, optional

List of additional .groovy source files that will be used to build the test.

java_srcs List of labels, optional

List of additional .java source files that will be used to build the test.

deps List of labels or .jar files, optional

List of libraries to be included on both the compile-time classpath when building this test and on the runtime classpath when executing it.

These can be `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

resources List of labels, optional

A list of data files to include on the test's classpath. This is accomplished by creating a `java_library` containing only the specified resources and including that library in the test's dependencies.

jvm_flags List of strings, optional

A list of flags to embed in the wrapper script generated for running this binary.

spock_test

spock_test(name, specs, deps, groovy_srcs, java_srcs, data, resources, jvm_flags, size, tags)
Attributes
name Name, required

A unique name for this rule.

specs List of labels, required

List of .groovy source files that will be used as test specifications that will be executed by JUnit.

groovy_srcs List of labels, optional

List of additional .groovy source files that will be used to build the test.

java_srcs List of labels, optional

List of additional .java source files that will be used to build the test.

deps List of labels or .jar files, optional

List of libraries to be included on both the compile-time classpath when building this test and on the runtime classpath when executing it.

These can be `groovy_library` targets, `java_library` targets, `groovy_and_java_library` targets, or raw .jar files.

resources List of labels, optional

A list of data files to include on the test's classpath. This is accomplished by creating a `java_library` containing only the specified resources and including that library in the test's dependencies.

jvm_flags List of strings, optional

A list of flags to embed in the wrapper script generated for running this binary.

rules_groovy's People

Contributors

alexeagle avatar aranguyen avatar bmuschko avatar buchgr avatar damienmg avatar davidzchen avatar dslomov avatar ekuefler avatar greggdonovan avatar hlopko avatar hvadehra avatar jart avatar jin avatar kchodorow avatar matthewxperiel avatar meteorcloudy avatar nlopezgi avatar philwo avatar robbiemc avatar theimplementer avatar trescube avatar vladmos avatar wyverald avatar xingao267 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rules_groovy's Issues

Checksum missing for junit and spock core dependencies

Kind of related to #39, the checksum is missing for the junit and spock-core dependencies in the rules_groovy_dependencies macro. Adding the checksum would allow the pre-fetch of the dependencies and then use them with the bazel's --distdir option.

The checksum is required for bazel to check the distdir: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpDownloader.java:128

The artifact_sha256 attribute of the rules_groovy_dependencies macro can be used for this.

Support Bazel option --incompatible_remove_native_maven_jar

When including the groovy rules from HEAD when building a spock_test you get the following error:

external/io_bazel_rules_groovy/groovy/groovy.bzl:445:5: no such package '@spock_artifact//jar': The native maven_jar rule is deprecated. See https://docs.bazel.build/versions/master/skylark/backward-compatibility.html#remove-native-maven-jar for migration information.
Use --incompatible_remove_native_maven_jar=false to temporarily continue using the native rule. and referenced by '//external:spock'

Flag --incompatible_no_implicit_file_export will break rules_groovy in Bazel 1.2.1

Incompatible flag --incompatible_no_implicit_file_export will break rules_groovy once Bazel 1.2.1 is released.

Please see the following CI builds for more information:

Questions? Please file an issue in https://github.com/bazelbuild/continuous-integration

Important: Please do NOT modify the issue title since that might break our tools.

Flag --incompatible_restrict_string_escapes will break rules_groovy in Bazel 1.2.1

Incompatible flag --incompatible_restrict_string_escapes will break rules_groovy once Bazel 1.2.1 is released.

Please see the following CI builds for more information:

Questions? Please file an issue in https://github.com/bazelbuild/continuous-integration

Important: Please do NOT modify the issue title since that might break our tools.

rules_groovy is failing on Bazel CI with RBE

https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/559#7fe8c92c-6cf6-4dd5-ba04-d0dfb92f6ede

ERROR: cc_toolchain_suite '@bazel_toolchains//configs/ubuntu16_04_clang/1.0/bazel_0.16.1/default:toolchain' does not contain a toolchain for CPU 'k8', you may want to add an entry for 'k8|clang' into toolchains and toolchain_identifier 'linux_gnu_x86' into the corresponding cc_toolchain rule (see --incompatible_disable_cc_toolchain_label_from_crosstool_proto).

@nlopezgi

Flag --incompatible_use_platforms_repo_for_constraints will break rules_groovy in Bazel 1.2.1

Incompatible flag --incompatible_use_platforms_repo_for_constraints will break rules_groovy once Bazel 1.2.1 is released.

Please see the following CI builds for more information:

Questions? Please file an issue in https://github.com/bazelbuild/continuous-integration

Important: Please do NOT modify the issue title since that might break our tools.

compilation fails when classpath is long

When the Java classpath is long, the command line "-cp" argument passed to groovyc exceeds the Linux maximum size for any single command argument, which is roughly 131K.

I have a hack to groovy/groovy.bzl that works around the problem by using symlinks. The groovyc command really needs a way to specify very long classpaths. Maybe it would be better to set the CLASSPATH environment variable in the Bazel rule?

What do you think?

Flag --incompatible_disable_starlark_host_transitions will break rules_groovy in Bazel 7.0

Incompatible flag --incompatible_disable_starlark_host_transitions will be enabled by default in the next major release (Bazel 7.0), thus breaking rules_groovy. Please migrate to fix this and unblock the flip of this flag.

The flag is documented here: bazelbuild/bazel#17032.

Please check the following CI builds for build and test results:

Never heard of incompatible flags before? We have documentation that explains everything.
If you have any questions, please file an issue in https://github.com/bazelbuild/continuous-integration.

[Bazel CI] Groovyc command in rules_groovy fails with "Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7" with Bazel@HEAD

CI: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/3701#018e16aa-c47f-4884-8fc8-f7533591df20

Platform: MacOS

Logs:

ERROR: ๏ฟฝ[0m/Users/buildkite/builds/bk-imacpro-8/bazel-org-repo-root/rules_groovy/example/src/main/groovy/lib/BUILD:17:24: Groovyc example/src/main/groovy/lib/libgroovyjavalib-groovy.jar failed: (Exit 1): bash failed: error executing Groovyc command (from target //example/src/main/groovy/lib:groovyjavalib-groovy) 
Error: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
Error: Exception org.codehaus.groovy.GroovyBugError [in thread "main"]
ERROR: ๏ฟฝ[0m/Users/buildkite/builds/bk-imacpro-8/bazel-org-repo-root/rules_groovy/example/src/main/groovy/lib/BUILD:3:15: Groovyc example/src/main/groovy/lib/libgroovylib-impl.jar failed: (Exit 1): bash failed: error executing Groovyc command (from target //example/src/main/groovy/lib:groovylib-impl) 
Error: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
Error: Exception org.codehaus.groovy.GroovyBugError [in thread "main"]
ERROR: ๏ฟฝ[0mBuild did NOT complete successfully
Error: The command exited with status 1๏ฟฝ[0m
error: exit status 1

Culprit:

Steps:

git clone https://github.com/bazelbuild/rules_groovy
git reset 47adf9ba4d6a4ad5be29d0599436f68bc811bfad  --hard
export USE_BAZEL_VERSION=ee8e833bbb530e4a84e3b9c2f4a07b48c78fad85 
bazel build //...

CC Greenteam @comius

Should have full examples

There are examples in README.md, but it would be nice to have them in the example/ directory.
I'd like to build them all using bazel build //.... This is useful for checking that the code is still working, and to see the full examples (including groovy source code).

Also, http_archive in the setup instructions should be updated to version 0.0.3.

Thanks!

Error: 'JavaInfo' value has no field or method 'transitive_runtime_deps' with Bazel@HEAD

https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/3228#0189dd37-24d0-4ff4-8848-4c20fc7635a4

Platform : Ubuntu, Windows, MacOS

ERROR: /Users/buildkite/builds/bk-imacpro-18/bazel-downstream-projects/rules_groovy/example/src/main/groovy/lib/BUILD:3:15: in _groovy_jar rule //example/src/main/groovy/lib:groovylib-impl:
Traceback (most recent call last):
	File "/Users/buildkite/builds/bk-imacpro-18/bazel-downstream-projects/rules_groovy/groovy/groovy.bzl", line 29, column 26, in _groovy_jar_impl
		dep[JavaInfo].transitive_runtime_deps
Error: 'JavaInfo' value has no field or method 'transitive_runtime_deps'
Available attributes: _compile_time_java_dependencies, _constraints, _neverlink, _transitive_full_compile_time_jars, annotation_processing, api_generating_plugins, compilation_info, compile_jars, full_compile_jars, java_outputs, module_flags_info, outputs, plugins, runtime_output_jars, source_jars, transitive_compile_time_jars, transitive_native_libraries, transitive_runtime_jars, transitive_source_jars
(04:17:12) ERROR: /Users/buildkite/builds/bk-imacpro-18/bazel-downstream-projects/rules_groovy/example/src/main/groovy/lib/BUILD:3:15: Analysis of target '//example/src/main/groovy/lib:groovylib-impl' failed
(04:17:12) ERROR: Analysis of target '//example/src/main/groovy/lib:groovylib-impl' failed; build aborted

Steps :

git clone https://github.com/bazelbuild/rules_groovy.git && cd rules_groovy
git reset d55a16c68d9ccd7e07bed5e3e46219bd2e55eda6 --hard
export USE_BAZEL_VERSION=dbd9e1889f899fe20c7e1195bbde57a8c40b4327
bazel build //...

CC Greenteam @comius

groovy_test sources must be under src/test/java or src/test/groovy

I met this error message when I add a target without in src/test/groovy folder, because of I may have another folder named src/integration/groovy or even groovytests folder.

I think it may be a too strict constraint for a common language build rule, at least support modifying the groovy source root for the groovy_test targets may help.

My project structure:

.
โ”œโ”€โ”€ BUILD.bazel
โ”œโ”€โ”€ WORKSPACE.bazel
โ””โ”€โ”€ src
    โ”œโ”€โ”€ integration
    โ”‚ย ย  โ””โ”€โ”€ groovy
    โ”‚ย ย      โ””โ”€โ”€ ...
    โ”œโ”€โ”€ main
    โ”‚ย ย  โ””โ”€โ”€ kotlin
    โ”‚ย ย      โ””โ”€โ”€ ...
    โ””โ”€โ”€ test
     ย ย  โ””โ”€โ”€ groovy
     ย ย      โ””โ”€โ”€ ...

groovy_test reports could not find class

I run into some problems when trying to use rules_groovy.

Minimal steps to reproduce:

git clone https://github.com/Vertexwahn/BazelDemos
cd BazelDemos
cd GroovyDemo
bazel test //...

In the case you have not installed Bazel you can installed it on a Ubuntu 20.04 machine this way:

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install -y bazel

The problem:

When I run bazel test //... I get the following error:

JUnit version 4.12
.E
Time: 0.001
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [HelloWorldTest]
	at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)
	at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
	at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
	at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
	at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: HelloWorldTest
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at org.junit.internal.Classes.getClass(Classes.java:16)
	at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
	... 4 more

FAILURES!!!
Tests run: 1,  Failures: 1

Details to setup:

My setup looks like this:

.bazelverion

5.0.0

WORKSPACE.bazel

# rules_groovy
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_groovy",
    sha256 = "21c7172786623f280402d3b3a2fc92f36568afad5a4f6f5ea38fd1c6897aecf8",
    strip_prefix = "rules_groovy-0.0.6",
    url = "https://github.com/bazelbuild/rules_groovy/archive/0.0.6.tar.gz",
)

load("@io_bazel_rules_groovy//groovy:repositories.bzl", "rules_groovy_dependencies")

rules_groovy_dependencies()

src/test/groovy/BUILD.bazel

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_test")

groovy_test(
    name = "HelloWorldTest",
    srcs = ["HelloWorldTest.groovy"],
)

src/test/groovy/HelloWorldTest.groovy

package src.test.groovy

import groovy.util.GroovyTestCase

class HelloWorldTest extends GroovyTestCase {
    void testAssertions() {
        assertTrue(1 == 1)
    }
}

It reports that class HelloWorldTest can not be found.
Any hints what I am doing wrong here?
What do I need to change to get a working Groovy unit test working?

My expectation is that the unit test succeeds.

(BTW: I am using Ubuntu 20.04)

--> I asked this also on StackOverflow

Support Bazel option --incompatible_disallow_legacy_java_provider

bazel --all_incompatible_changes currently chokes on groovy.bzl:

Traceback (most recent call last):
        ...
        File ".../external/io_bazel_rules_groovy/groovy/groovy.bzl", line 26, in _groovy_jar_impl
                depset(ctx.files.deps, transitive = [dep....")])
        File ".../external/io_bazel_rules_groovy/groovy/groovy.bzl", line 26, in depset
                dep.java.transitive_runtime_deps
The .java provider is deprecated and cannot be used when --incompatible_disallow_legacy_java_provider is set. Please migrate to the JavaInfo Skylark provider.
ERROR: Analysis of target '//src/utilities/db-config:groovylib-groovy' failed; build aborted: Analysis of target '//src/utilities/db-config:groovylib-groovy' failed; build aborted

Please move from native to Skylark rules for external git/http repositories

Bazel is planning to move away from native rules for external repositories to Skylark rules, mainly because bundling every version control system in bazel does not scale. As part of this effort, we plan to submit https://bazel-review.googlesource.com/c/bazel/+/55932 soon, which will cause bazel by default to insist that the skylark versions the git and http rules for external repositories be used. This can be disabled by a flag for at least the next 6 months, but we still would appreciate if you could adopt your repository to use the Skylark versions of those rules soon.

A test run of downstream projects with that flag flip in bazel enabled can be found at https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/286

For more background, see

Thanks.

Java/Groovy cross-compilation doesn't seem to work

For the following code

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_and_java_library", "groovy_binary")

groovy_and_java_library(
    name = "prodlib",
    srcs = ["src/main/groovy/com/bmuschko/HelloWorld.groovy", "src/main/groovy/com/bmuschko/messenger/Messenger.java"],
)

groovy_binary(
    name = "hello-world",
    srcs = ["src/main/groovy/com/bmuschko/HelloWorld.groovy"],
    main_class = "com.bmuschko.HelloWorld",
    deps = [":prodlib"],
)

I receive this error message:

bazel run //:hello-world
ERROR: /Users/bmuschko/dev/projects/bazel-examples/groovy/groovy-java-cross-compilation/BUILD:3:1: Traceback (most recent call last):
	File "/Users/bmuschko/dev/projects/bazel-examples/groovy/groovy-java-cross-compilation/BUILD", line 3
		groovy_and_java_library(name = "prodlib", srcs = ["src/mai..."])
	File "/private/var/tmp/_bazel_bmuschko/bdc37c78ed902a101b2e2292e351e501/external/io_bazel_rules_groovy/groovy/groovy.bzl", line 154, in groovy_and_java_library
		groovy_deps += [(name + "-java")]
trying to mutate a frozen object
ERROR: error loading package '': Package '' contains errors
INFO: Elapsed time: 0.077s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
FAILED: Build did NOT complete successfully (1 packages loaded)

Let me know if there's an issue with my code or if that's a bug.

Directory entries are not included in the generated jar file

It looks like jar files generated using the groovy_library rule, unlike the ones generated with the java_library one, don't contain directory entries.

For instance, given a java class Test.class under the com.example package, the resulting jar file would contain the following entries (excluding the META-INF directory):

  • com/
  • com/example/
  • com/example/Test.class

At runtime, the following code will then work as expected, returning a URL to the jar file:

ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
URL url = systemClassLoader.getResource("com/example");

The same does not work (the URL returned is null) with a jar generated with the groovy_library rule because the only entry in it is: com/example/Test.class.

groovy_library should strict about declaring direct dependencies

Currently, the groovy_library rule and those related to it, are not strict that users declare all direct dependencies. This is likely because of how it is computing transitive dependencies. Specifically the combination of depset and how it adding together the java target's transitive dependencies

def _groovy_jar_impl(ctx):
  ...

  # Extract all transitive dependencies
  # TODO(bazel-team): get transitive dependencies from other groovy libraries
  all_deps = depset(ctx.files.deps)
  for this_dep in ctx.attr.deps:
    if hasattr(this_dep, "java"):
      all_deps += this_dep.java.transitive_runtime_deps

This allows us to not necessarily list all of the java code we import. As some can be picked up transitively.

This goes against the grain of how Bazel traditionally operates, i.e. explicitly declare all directly used dependencies.

@laurentlb, as you know much more about Starlark, do you have any recommendations or thoughts on why the current implementation is sketchy. Kristina put a TODO statement three years ago, and the Starlark language has changed drastically since then.

https://github.com/petroseskinder/rules_groovy/blob/master/groovy/groovy.bzl#L22

Latest published rules are broken for Bazel 2.0.0

I receive the following error message when executing the rules v0.0.5 with Bazel 2.0.0. Works fine with Bazel 1.1.0.

ERROR: /private/var/tmp/_bazel_bmuschko/db126b824c509a76348765b600ae1c98/external/io_bazel_rules_groovy/groovy/groovy.bzl:434:5: Traceback (most recent call last):
	File "/Users/bmuschko/dev/projects/bazel-examples/groovy/hello-world/WORKSPACE", line 9
		groovy_repositories()
	File "/private/var/tmp/_bazel_bmuschko/db126b824c509a76348765b600ae1c98/external/io_bazel_rules_groovy/groovy/groovy.bzl", line 434, in groovy_repositories
		native.maven_server(<2 more arguments>)
type 'struct' has no method maven_server()
ERROR: error loading package 'external': Package 'external' contains errors
INFO: Elapsed time: 0.202s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

This is my WORKSPACE code:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_groovy",
    url = "https://github.com/bazelbuild/rules_groovy/archive/0.0.5.tar.gz",
    sha256 = "d41ca1290de57f2eabc71d5a097689491e3afe7337367a7326396d55db4910f7",
    strip_prefix = "rules_groovy-0.0.5",
)

load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_repositories")
groovy_repositories()

Looks to me like native.maven_server does not exist anymore. I believe you'll have to fully rely on rules_jvm_external now.

Seems like a change has already been made on master to remove the use of native.maven_server. When are you planning to release a Bazel 2.0.0-compatible rules version?

rules_groovy broken by bazel@HEAD

Hello dear rules owners,

I see that bazel@HEAD breaks rules_groovy: https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/386#521eab58-5b3d-4ca8-934b-c6960bdcd355.

Would you mind taking a look? Thank you very much!

This is the announcement email:
We are very close to remove in-memory //tools/default* package in favor of using @bazel_tools//tools/jdk: and @bazel_tools//tools/cpp: instead.
The changes will be ready with next release.

Motivation:
//tools/default was initially created as virtual in-memory package. It generates content dynamically based on current configuration. There is no need of having //tools/defaults any more as LateBoundAlias can generate dynamic configuration-based label resolving. Also, having //tools/default makes negative impact on performance, and introduces unnecessary code complexity.

All references to //tools/defaults:* targets should be removed or replaced to corresponding target in @bazel_tools//tools/jdk: and @bazel_tools//tools/cpp: packages.

Scope of changes and impact:
All targets in //tools/default will not exist any more. If you have any references inside your BUILD or *.bzl files to any of its, then bazel will fail to resolve.

Migration plan:

Please replace all occurrences:

//tools/defaults:jdk
-- by @bazel_tools//tools/jdk:current_java_runtime
-- or/and @bazel_tools//tools/jdk:current_host_java_runtime

//tools/defaults:java_toolchain
-- by @bazel_tools//tools/jdk:current_java_toolchain

//tools/defaults:crosstool
-- by @bazel_tools//tools/cpp:current_cc_toolchain
-- or/and @bazel_tools//tools/cpp:current_cc_host_toolchain
-- if you need reference to libc_top, then @bazel_tools//tools/cpp:current_libc_top

These targets will not be supported any more:
//tools/defaults:coverage_report_generator
//tools/defaults:coverage_support

Failure building groovy_binary

I get the following failure attempting to get a basic groovy_binary rule working:

$ bazel run java/examples:HelloGroovy 
INFO: Found 1 target...
ERROR: /home/mattmoor/bazel-glibc/java/examples/BUILD:34:1: error executing shell command: 'set -e;rm -rf bazel-out/local-fastbuild/bin/java/examples/libHelloGroovy-lib-impl.jar.build_output
mkdir -p bazel-out/local-fastbuild/bin/java/examples/libHelloGroovy-lib-impl.jar.build_output
expo...' failed: I/O error during sandboxed execution: /home/mattmoor/.cache/bazel/_bazel_mattmoor/4c53d6d0ace4750b3e4c72c352abc709/bazel-sandbox/39470475-730a-411a-b7c5-686dcdefa05c-0/execroot/bazel-glibc/external/groovy_sdk_artifact/groovy-2.4.4/indy (Directory not empty).
Target //java/examples:HelloGroovy failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.208s, Critical Path: 0.02s
ERROR: Build failed. Not running target.

The changes to my repo are trivial:

$ git diff --cached
diff --git a/WORKSPACE b/WORKSPACE
index a1d91ea..6399a9c 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -37,6 +37,16 @@ git_repository(
 load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
 scala_repositories()
 
+# Groovy rules
+git_repository(
+    name = "io_bazel_rules_groovy",
+    remote = "https://github.com/bazelbuild/rules_groovy.git",
+    commit = "02029366fa73e417e51c0beef22e46e6a77d9b91", # update this as needed
+)
+
+load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_repositories")
+groovy_repositories()
+
 # For everything.
 http_file(
    name = "glibc",
diff --git a/java/examples/BUILD b/java/examples/BUILD
index 337a0f2..51bcddc 100644
--- a/java/examples/BUILD
+++ b/java/examples/BUILD
@@ -28,3 +28,11 @@ docker_build(
     files = [":HelloScala_deploy.jar"],
     cmd = ["/HelloScala_deploy.jar"]
 )
+
+load("@io_bazel_rules_groovy//groovy:groovy.bzl", "groovy_binary")
+
+groovy_binary(
+    name = "HelloGroovy",
+    srcs = ["HelloGroovy.groovy"],
+    main_class = "examples.HelloGroovy",
+)
\ No newline at end of file
diff --git a/java/examples/HelloGroovy.groovy b/java/examples/HelloGroovy.groovy
new file mode 100644
index 0000000..0c17331
--- /dev/null
+++ b/java/examples/HelloGroovy.groovy
@@ -0,0 +1,7 @@
+package examples
+
+class HelloGroovy {
+   static void main(String[] args) {
+      println "Hello world"
+   }
+}
\ No newline at end of file

I'm currently using the commit at head with:

$ bazel version
Build label: 0.4.3
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Dec 22 12:31:25 2016 (1482409885)
Build timestamp: 1482409885
Build timestamp as int: 1482409885

Flag --incompatible_load_java_rules_from_bzl will break rules_groovy in Bazel 1.2.1

Incompatible flag --incompatible_load_java_rules_from_bzl will break rules_groovy once Bazel 1.2.1 is released.

Please see the following CI builds for more information:

Questions? Please file an issue in https://github.com/bazelbuild/continuous-integration

Important: Please do NOT modify the issue title since that might break our tools.

groovy_test implementation uses forbidden operator on depset

For the following code

groovy_library(
  name = "testlib",
  srcs = glob(["**/*.groovy"]),
)

groovy_test(
    name = "tests",
    srcs = ["src/test/groovy/com/bmuschko/messenger/MessengerTest.groovy"],
    deps = [":testlib"],
)

I receive this error message.

bazel test //:tests
ERROR: /Users/bmuschko/dev/projects/bazel-examples/groovy/junit4-test/BUILD:14:1: in _groovy_test rule //:tests:
Traceback (most recent call last):
	File "/Users/bmuschko/dev/projects/bazel-examples/groovy/junit4-test/BUILD", line 14
		_groovy_test(name = 'tests')
	File "/private/var/tmp/_bazel_bmuschko/d3fe1e22cf58ce848cb5c284730e1906/external/io_bazel_rules_groovy/groovy/groovy.bzl", line 219, in _groovy_test_impl
		all_deps += this_dep.java.transitive_runtime_deps
`+` operator on a depset is forbidden. See https://docs.bazel.build/versions/master/skylark/depsets.html for recommendations. Use --incompatible_depset_union=false to temporarily disable this check.
ERROR: Analysis of target '//:tests' failed; build aborted: Analysis of target '//:tests' failed; build aborted
INFO: Elapsed time: 1.910s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (26 packages loaded, 675 targets configured)
FAILED: Build did NOT complete successfully (26 packages loaded, 675 targets configured)

You can only work around it by add the command line option --incompatible_depset_union=false. I am using Bazel version 0.26.0.

Support Bazel option --incompatible_load_java_rules_from_bzl

Loading rules_groovy's groovy.bzl when Bazel is launched with --incompatible_load_java_rules_from_bzl causes the build to fail with the following:

ERROR: .../BUILD.bazel:134:1: in java_import rule //pkg:target: The native Java rules are deprecated. Please load java_import from the rules_java repository. See http://github.com/bazelbuild/rules_java and https://github.com/bazelbuild/bazel/issues/8741. You can temporarily bypass this error by setting --incompatible_load_java_rules_from_bzl=false.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.