Skip to content
Advertisement

How to trigger a task after build

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)

Advertisement

Answer

What you want is this:

build.configure { finalizedBy generateJavaApi }
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement