Coder Social home page Coder Social logo

gradle-java-jsonschema's Introduction

gradle-java-jsonSchema

Build Status

Gradle plugin that allows to generate json schema from java classes and build a zip file containing all the schemas. For all classes which are compiled to buildDir/java/classes/main a json schema will be generated. Plugin allows to include/exclude class files. See plugin parameters.

How to use

Build

At the moment the plugin is not uploaded to any public repository. That means you have to build it yourself. Just run

$ ./gradlew build

to generate the jar or

$ ./gradlew publishToMavenLocal

to push the jar to your local maven repository.

Add to your project

The project setup should look like a normal java project. That means src/main/java contains the java files which you want to use to build json schemas and all dependecies needed to compile are specified in the gradle build file.
After you have pushed the plugin to your repository, update the build.gradle. First add the dependency to buildscript section and apply the plugin:

buildscript {

    repositories {
        mavenLocal()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.chris.gradle.json:gradle-java-jsonSchema:0.1.4"
    }
}
apply plugin: 'java'
apply plugin: 'com.chris.json.schema'

It's necessary to apply the java plugin, because this plugin depends on java build tasks to compile class files from java code.

Configure plugin

The plugin has some simple configuration mechanism to control the generated json schema.

jsonSchema {
    compileClasspath = sourceSets.main.compileClasspath
    pretty true
    exclude "**/*Support.class", "**/*Communication*"
    include "**/*Seq.class"
}

Plugin Parameters

compileClasspath: The configuration where gradle-java-jsonSchema-plugin can find the jars needed to compile java files. In a normal java project it should set to sourceSets.main.compileClasspath.
pretty: Defines if the json schemas should be generated in compact or in human readable way. Default is false (compact).
exclude: Exclude class files from schema generation.
include: Include class files in schema generation.

Generate schemas or zip-file

The plugin contains two tasks. generateJsonSchema to just generate the schema files and jsonSchemaZip to build a zip file containing all the schemas. Of course jsonSchemaZip depends on generateJsonSchema. Execute the tasks like:

$ ./gradlew generateJsonSchema
# or
$ ./gradlew jsonSchemaZip

gradle-java-jsonschema's People

Contributors

chris060986 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dpolivaev

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.