简体   繁体   中英

NetBeans w/ Gradle Support System Environments for Testing

So I'm trying to get started on Java development with a project using the Google Places API, through the Client Library for Java. I've been a PHP/Javascript dev for a while now and have made my way through Headfirst Java, but haven't worked with Gradle before.

So far I am embarrassingly stuck just getting the Client Library to test and build successfully. I've git-cloned the client library, installed Netbeans, JDK 8, and the Gradle Support plugin for Netbeans and set up my Google API Key. I'm working on Windows, FWIW. According the docs at https://github.com/googlemaps/google-maps-services-java I have to set an API_KEY Environment variable for the tests to run, so I've tried to set that as a JVM option for the Client Library project in Netbeans (see screenshot, it was a real key but obviously I removed the key itself before taking the screenshot)

屏幕截图

This is based on the documentation for the Gradle Support plugin here: https://github.com/kelemen/netbeans-gradle-project/wiki/Built-In-Tasks

Unfortunately I still get IllegalArgumentException: No credentials Found!... for all my tests. I set a breakpoint in com.google.maps.AuthenticatedTest.java:57 and debugged the tests and pretty clearly it seems that the environment variable is not set at that point (the apiKey variable is an empty string there), although I'm sure the method I've used for adding the JVM args is working because I started getting stack traces for the tests after adding it (Initially I was just getting: "com.google.maps.GeolocationApiTest > initializationError FAILED java.lang.IllegalArgumentException" and then at the end it suggested I run the tests with --stacktrace for more details).

I'm guessing there is something alarmingly basic that I am missing, but I am stumped as to where to look from here.

Java's -D argument sets a property (something you can look up using System.getProperty method), not an environment variable. So clearly, in your case the proper flag will be:

-Dapi.key="secret key"

Notice the difference in names between property and environment variable.

Clearly, you can still use the environment variables if you set them elsewhere (your login shell profile, Windows' system properties, etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM