bazelbuild / rules_appengine

AppEngine rules for Bazel
Apache License 2.0
30 stars 51 forks source link

appengine_war doesn't work with a java_library #33

Open regisd opened 7 years ago

regisd commented 7 years ago

The doc reads:

appengine_war(name, jars, data, data_path)

and

jars List of labels, required List of JAR files that will be uncompressed as the code for the Web Application. If it is a java_library or a java_import, the JAR from the runtime classpath will be added in the lib directory of the Web Application.

In my experience, the jars from the targets are not added.

In fact, even examples is adding the jar explicitely:

jars = ["//examples/src:src_deploy.jar"],

This would also work:

jars = ["//examples/src:srr.jar"],

But this doesn't:

jars = ["//examples/src:src"],

If I understand correctly, it should (and the syntax would be nicer and follow the convention of listing targets, not build artifacts).

regisd commented 7 years ago

I can try to fix that if you want.

pmbethe09 commented 7 years ago

It works fine for a java_binary, so what would the "fix" be?

On Tue, Dec 13, 2016 at 6:01 PM, Régis Décamps notifications@github.com wrote:

I can try to fix that if you want.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_appengine/issues/33#issuecomment-266889999, or mute the thread https://github.com/notifications/unsubscribe-auth/ALF-0tgLhu16wbPtkuNJiKLLNGaeRWmwks5rHyPYgaJpZM4LMVPL .

regisd commented 7 years ago

I don't experience the same behaviour. The provided examples uses a java_binary and this is also failing when referencing the target rather than the jar.

I mean, the compilation works doesn't succeeds, but the war doesn't contain the jar, hence the server will hit a NoClassDefFoundError at runtime.

regisd commented 7 years ago

And this is how I would fix it:

--- a/appengine/appengine.bzl
+++ b/appengine/appengine.bzl
@@ -121,6 +121,9 @@ def _war_impl(ctxt):
   transitive_deps = set()
   for jar in ctxt.attr.jars:
     if hasattr(jar, "java"):  # java_library, java_import
+      transitive_deps += jar.files
       transitive_deps += jar.java.transitive_runtime_deps
     elif hasattr(jar, "files"):  # a jar file
       transitive_deps += jar.files
pmbethe09 commented 7 years ago

Are you using the '_deploy.jar' target of the java_binary?

On Tue, Dec 13, 2016 at 6:13 PM, Régis Décamps notifications@github.com wrote:

And this is how I would fix it:

--- a/appengine/appengine.bzl +++ b/appengine/appengine.bzl @@ -121,6 +121,9 @@ def _war_impl(ctxt):

transitive_deps = set() for jar in ctxt.attr.jars: if hasattr(jar, "java"): # java_library, java_import+ transitive_deps += jar.files transitive_deps += jar.java.transitive_runtime_deps elif hasattr(jar, "files"): # a jar file transitive_deps += jar.files

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bazelbuild/rules_appengine/issues/33#issuecomment-266892386, or mute the thread https://github.com/notifications/unsubscribe-auth/ALF-0gK1gomklY4wWAHORVMYcEgfvsa1ks5rHyaHgaJpZM4LMVPL .

regisd commented 7 years ago

Paul, can you open the description on github? I involuntary pressed send, but edited the issue with more details.

To answer your last question, I was expecting to use

jars = ["//examples/src"],
pmbethe09 commented 7 years ago

I see.
No, you have to use //examples/src:src_deploy.jar to get all of the transitive deps in jar form.

So maybe as you point out, the doc should be updated. Not sure the suggested .bzl change is sufficient for a java_library