Build Swagger Api Client in Build

I have a gradle build that does perform the following steps:

  • Create yaml file from API Classes
  • Generate typescript-angular Client with Swagger Codegenerator
  • npm install, build and publish typescript Client to private registry

This works like it should.
I now wanted to do the same thing for a java client generated with the swagger Codegenerator but I am struggeling with the build for the java client…

I use the following plugins:

plugins {
    id 'com.github.node-gradle.node'
    id 'org.hidetake.swagger.generator'
    id 'com.benjaminsproule.swagger'

The swaggerSources in my build gradle for the java client looks like this

    tenantmgmcmpjavaapi {
        inputFile = file("./build/generated/resources/openapi/tenant-mgm-cmp-api.yaml")
        code {
            outputDir = file("./build/swagger-tenant-mgm-cmp-java-api")
            language = 'java'
            library = 'resttemplate'
            components = [apis: true, apiTests: false, supportingFiles: true]
            additionalProperties = [
                    'invokerPackage': "com.tenantmgmcmp.hub",
                    'apiPackage'  : "com.tenantmgmcmp.hub.client",
                    'modelPackage'  : "com.tenantmgmcmp.hub.dto",
                    "groupId": "com.tenantmgmcmp",
                    'artifactId': "tenant-mgm-cmp-api-client",
                    'artifactVersion': project.version


The java client is correctly generated with this settings.
So far so good.

But how do I now build the generated java sources so that I can publish the client.jar to an artifactory?
The generated Client is in a subfolder ./build/swagger-tenant-mgm-cmp-java-api which of course only exists after the codeGeneration ran.
Therefore I did not find a way to use include or a runtime project dependency as gradle instantly fails on buildstart an says it can not find the folder…

would be happy for any hint,

If you do

sourceSets { 
    main {
        java {

the generated code is automatically compiled along and also all tasks needing source code like compilation task, source jar task, … automatically have an implicit task dependency to the code generation task. Of course the code generation task needs to have its output properly declared for it to work.