# JSON Schema generation and package to JAR using Gradle?

**URL:** https://discuss.gradle.org/t/json-schema-generation-and-package-to-jar-using-gradle/39485
**Category:** Help/Discuss
**Created:** [April 1, 2021, 1:28pm UTC](https://discuss.gradle.org/t/json-schema-generation-and-package-to-jar-using-gradle/39485 "2021-04-01T13:28:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![PhoenixFlash](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@PhoenixFlash](https://discuss.gradle.org/u/PhoenixFlash)
#### Post date: [April 1, 2021, 1:28pm UTC](https://discuss.gradle.org/t/json-schema-generation-and-package-to-jar-using-gradle/39485/1 "2021-04-01T13:28:05Z")

</div>

I basically want to create a Library project in which I want to generate POJO’s as part of the build and package it as a JAR.

So basically, the set of steps should be something like :

1. generate POJO using jsonschema2pojo Java class
2. use gradle task to execute step 1
3. use gradle task to package it to the JAR

All of this if can be done via a single build, it would be great. The issue which I am facing currently is :

I manually have to run a gradle task to generate pojo’s and then another gradle task to package it as a JAR. How can I combine it?

---

<div class="post-metadata">

### Author: ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)
#### Post date: [April 1, 2021, 11:30pm UTC](https://discuss.gradle.org/t/json-schema-generation-and-package-to-jar-using-gradle/39485/2 "2021-04-01T23:30:22Z")

</div>

This should help get you going:

```
task genSources {
    def outDir = new File( buildDir, 'mygensources' )
    outputs.dir( outDir )

    doLast {
        println "generating source into ${outDir}"
        new File( outDir, 'Generated.java' ).withWriter('UTF-8') {
            it.write '''
                public class Generated {
                }
            '''
        }
    }
}

sourceSets.main.java.srcDir( tasks.genSources )

```

Results:

```
$ ./gradlew compileJava
> Task :genSources
generating source into /home/cdore/projects/gen/build/mygensources
> Task :compileJava

$ ll build/mygensources/ build/classes/java/main/
build/classes/java/main/:
total 4
-rw-rw-r-- 1 cdore cdore 252 Apr 1 17:24 Generated.class

build/mygensources/:
total 4
-rw-rw-r-- 1 cdore cdore 72 Apr 1 17:24 Generated.java
```
