Home > Mobile >  How to trigger a task after build
How to trigger a task after build

Time:03-06

I have the following code:

import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
    id 'org.openapi.generator' version '5.3.1'
}

apply plugin: 'java'

sourceSets {
    main {
        java.srcDirs  = "${buildDir}/api/src/main/java/"
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'javax.validation:validation-api'
    implementation 'com.fasterxml.jackson.core:jackson-annotations'
    implementation "io.swagger:swagger-annotations"
}

task generateJavaApi(type: GenerateTask) {
    generatorName = "spring"
    inputSpec = "$buildDir/resources/main/static/api.yaml"
    outputDir = "$buildDir/api"
    apiPackage = "org.myApi.api"
    modelPackage = "org.myApi.model"
    configOptions = [
            interfaceOnly  : "true",
            openApiNullable: "false"
    ]
}

configure(generateJavaApi) {
    group = 'openapi tools'
    description = 'Generate Java API'
}

generateJavaApi.dependsOn(build)

If I write build.doLast(generateJavaApi), IntelliJ tells me the following: No candidates found for method call build.dolast.

Why is that and how would you trigger generateJavaApi after build?

(so that running gradle build would automatically also trigger the generation of the java api)

CodePudding user response:

What you want is this:

build.configure { finalizedBy generateJavaApi }
  • Related