rules_appengine icon indicating copy to clipboard operation
rules_appengine copied to clipboard

appengine_war doesn't work with a java_library

Open regisd opened this issue 9 years ago • 7 comments

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 avatar Dec 13 '16 22:12 regisd

I can try to fix that if you want.

regisd avatar Dec 13 '16 23:12 regisd

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 [email protected] 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 .

pmbethe09 avatar Dec 13 '16 23:12 pmbethe09

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 avatar Dec 13 '16 23:12 regisd

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

regisd avatar Dec 13 '16 23:12 regisd

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

On Tue, Dec 13, 2016 at 6:13 PM, Régis Décamps [email protected] 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 .

pmbethe09 avatar Dec 13 '16 23:12 pmbethe09

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"],

regisd avatar Dec 13 '16 23:12 regisd

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

pmbethe09 avatar Dec 13 '16 23:12 pmbethe09