Fix Java 6 compatibility for Query module

Specifically, removed a try-with-resources usage, as well as diamond brackets. Also cleaned up the module's Gradle script to use content inherited from root project.