-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.getProperty doesn't seem to work #76
Comments
I also wanted to say, I did my best to follow along with #1 and the other existing issues, but I found trouble understanding them or applying them to my situation. What I am asking is, what is the supported way of accessing Closure defines in J2CL? |
Example.java/Config.java needs a Second guess, due to my lack of familiarity with the effects of modules and exports: you might need to actually ask for |
@niloc132 i've also tried injecting the value via a Closure JS file with a it is unclear to me if a it seems to me from reading the code that the |
You need both .js and .native.js. The .native.js adds the "goog.require" to your transpiled .java output (since you can't write a java Other examples that might help: One more example, in gwt-dom, trying to provide the same legacy "experience" of telling which browser is running (in this case because blink/webkit's RTL setup is ... not as easy to work with as gecko): |
Sorry didn't read the whole thread yet but taking a quick; seems like you are using goog.module. goog.module doesn't work with @define; pls use goog.provide instead. |
@gkdn / @niloc132 thank you for your help on this, but I still can't get it to work :( i've updated my sample according to your directions. here are the changes I made
goog.require('app');
goog.provide('app');
/**
* Defines a symbol for the app version.
*
* @public
* @define {!string} app.version
*/
app.version = goog.define('APP_VERSION', 'alpha');
@JsType
public class Config {
/**
* Retrieve the application version setting.
*
* @return Version assigned for the currently-running application.
**/
public static String getAppVersion() {
return System.getProperty("app.version", "alpha");
}
}
closure_js_library(
name = "ConfigModule",
srcs = ["module.js"],
)
j2cl_library(
name = "Config",
srcs = [
"Config.java",
"Config.native.js",
],
deps = [
":ConfigModule",
]
) |
Pls change System.getProperty uses the name passed to goog.define. Also you can simplify your setup like following:
It would be great to put a sample for others to follow as an example; instead of digging for examples from jre or jsnterop. |
I’ll give that a shot and mark up a PR as a sample. thank you again for your help |
https://github.com/google/j2cl/blob/master/docs/best-practices.md#custom-compile-time-code-stripping should be updated to reflect the way that this is expected to work. |
Thinking about it; it is easy introduce a Bazel macro to streamline this. |
Describe the bug
I'm trying to use
System.getProperty
to access a Closure--define=
, provided viadefs
. I can't seem to get it to work no matter what I do.To Reproduce
Example.java
:module.js
:config-test.js
:BUILD.bazel
:(
config_test.html
omitted because it basically just includes the JS).The build then fails with the following exception:
Outputs
Bazel version
2.0.0
Expected behavior
I would expect it not to error, firstly. Then, I would expect it to emit
abc123
in place of the string in the define.If I leave the define unspecified, the error disappears, but then, of course, the default string is used, which fails the test.
The text was updated successfully, but these errors were encountered: