Code Monkey home page Code Monkey logo

basex-gradle-starter's Introduction

basex-gradle-starter

A simple build script template for using BaseX (8.2) with Gradle. Also adds Saxon 9.6 so you can use XSLT 2.0 out of the gate.

Caution: this is still in very early stage.

Installation steps:

  1. git clone https://github.com/xokomola/basex-gradle-starter.git

Yep, that's right. There's only one step between wanting to use this and running queries with Basex. It even installs Gradle for you.

To see what tasks are available:

gradlew tasks

To execute other tasks:

gradlew <taskname>

For more information on Gradle have a look at it's extensive documentation.

Startup tasks

Most of the familiar startup scripts are all available as tasks:

  • gui
  • console
  • server and serverstop
  • http, httpstart and httpstop

Configuration of BaseX is done in gradle.properties.

By default will put all data under the basex subdirectory.

Create a database

gradlew create -Pdb=dbname -Pdir=~/tmp/xml

Export a database

gradlew export -Pdb=dbname -Pdir=~/tmp/export

XQuery tasks

To run a simple query:

gradlew query -Pq="1+1"

To run all tests under basex/webapp:

gradlew xqtest

Execute BaseX commands

See the BaseX documentation on commands. To execute BaseX commands from a file:

gradle command -Pc=commands.bxs

To execute BaseX commands provided as a string on the command line:

gradle command -Pc="get chop"

Running faster with "daemon"

And by using the --daemon option you can also avoid a lot of the Java startup tax.

gradlew --daemon query

Where to put XQuery code?

For now the assumes that both source and tests are in basex/webapp (or wherever you point org.basex.WEBPATH property in gradle.properties to).

Run tests automatically

Gradle introduced "continous builds". If you want all tests to run automatically when test scripts or XQuery source code changes use this:

gradlew -t xqtest

Building an HTTP application distribution

You've created an application, running and testing it using this build script. Now it's time to distribute the application.

gradlew distZip

This creates a Zip with the application and start scripts.

See also: Gradle Application Plugin

Create a runnable server jar

You can combine all the needed jar files and create a so-called fat jar. This allows you to run BaseX as a jar (easy to deploy). You can already do that with the BaseX core distribution but with this it also includes the optional libraries.

gradlew shadowJar

This will create a jar (we do not have local classes yet) inside build/libs. The task will build both a jar with local code and another one with all dependencies (postfixed with -all).

Run the server:

java -Dorg.basex.dbpath=basex/data
     -Dorg.basex.repopath=basex/repo 
     -Dorg.basex.webpath=basex/web
     -jar build/libs/basex-gradle-start-0.1-all.jar

Note that you will have to pass the paths (and possibly other settings). In this case I passed the paths to the project files. You can also use all the regular basexhttp command-line arguments if you wish.

For example start the HTTP server on a different port:

java -Dorg.basex.dbpath=basex/data
     -Dorg.basex.repopath=basex/repo 
     -Dorg.basex.webpath=basex/web
     -jar build/libs/basex-gradle-start-0.1-all.jar
     -h1234

The name of the jar is the name of the project. The version is set from within build.gradle.

To connect to this server you could also use the same jar (from another shell window):

java -cp build/lib/basex-gradle-start-0.1-all.jar org.basex.BaseXClient

Why are so many dependencies listed, aren't they part of the BaseX POM?

This is a Gradle limitation. Gradle doesn't follow transitive dependencies that are declared as optional. This makes sense but it's a bit unfortunate that to include these optional libraries they have to be explicitly listed in the build script.

Known issues

  • Client task (console) prints build progress message in between input. This is confusing.

  • Sometimes I cannot access the server with console from another shell. Run it with -d option and you'll see that it cannot acquire a lock

  • Task distZip also packs basex directory but when running it it still uses the dir from the project. Need to do better config to set the paths.

Contributors

TODO

  • Run only specific tests (xqtest always runs all tests)
  • Better configuration
  • Provide arguments for query tasks
  • Packaging as WAR for Tomcat etc.
  • Building XAR packages and managing module repository
  • Backup and restore

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.