Skip to content

Instantly share code, notes, and snippets.

@jprinet
Created November 3, 2025 09:53
Show Gist options
  • Select an option

  • Save jprinet/92a1dafd712ee378e6e0b824106cae1f to your computer and use it in GitHub Desktop.

Select an option

Save jprinet/92a1dafd712ee378e6e0b824106cae1f to your computer and use it in GitHub Desktop.
Make openapi-generator-maven-plugin cacheable
log.debug('Evaluating custom Develocity logic')
buildCache.registerMojoMetadataProvider(context -> {
context.withPlugin("openapi-generator-maven-plugin", () -> {
if ("generate".equals(context.getMojoExecution().getGoal())) {
log.debug('Configuring OpenAPI code generator caching')
context.inputs(inputs -> {
try {
List<String> compileClasspathElements = context.getProject().getCompileClasspathElements();
log.debug("codegen compile classpath elements:")
log.debug(compileClasspathElements.toString())
inputs.fileSet("codegenCompileClasspath", compileClasspathElements, fileSet -> fileSet.normalizationStrategy(com.gradle.develocity.agent.maven.adapters.MojoMetadataProviderAdapter.Context.FileSet.NormalizationStrategy.CLASSPATH));
} catch (Exception e) {
throw new IllegalStateException("Classpath can't be resolved");
}
inputs
.fileSet("templateDirectory", fileSet -> fileSet.normalizationStrategy(com.gradle.develocity.agent.maven.adapters.MojoMetadataProviderAdapter.Context.FileSet.NormalizationStrategy.RELATIVE_PATH))
.properties("property","strictSpec","skipValidateSpec","enablePostProcessFile","skipOperationExample","removeOperationIdPrefix","templateResourcePath","artifactId","groupId","artifactVersion","library","packageName","invokerPackage","modelPackage","modelNamePrefix",
"modelNameSuffix","apiNameSuffix","apiPackage","ignoreFileOverride","skipOverwrite","configurationFile","mergedFileInfoDescription","mergedFileInfoVersion","mergedFileName","mergedFileInfoName","inputSpecRootDirectory","inputSpec","generatorName",
"collapsedSpec","includeCollapsedSpecInArtifacts","engine","generateAliasAsModel","minimalUpdate","configOptions","instantiationTypes","importMappings","schemaMappings","inlineSchemaNameMappings","inlineSchemaOptions","nameMappings","parameterNameMappings",
"modelNameMappings","enumNameMappings","operationIdNameMappings","openapiNormalizer","typeMappings","languageSpecificPrimitives","openapiGeneratorIgnoreList","additionalProperties","serverVariableOverrides","reservedWordsMappings","generateApis",
"apisToGenerate","generateModels","generateRecursiveDependentModels","modelsToGenerate","generateSupportingFiles","supportingFilesToGenerate","generateModelTests","generateModelDocumentation","generateApiTests","generateApiDocumentation","skip",
"skipIfSpecIsUnchanged","addCompileSourceRoot","addTestCompileSourceRoot","dryRun","environmentVariables","globalProperties","configHelp","cleanupOutput","withXml")
.ignore("buildContext", "verbose", "gitHost", "gitUserId", "gitRepoId", "auth", "httpUserAgent", "logToStderr", "mavenProject", "mavenProjectHelper", "mojo", "project")
});
context.outputs(outputs -> {
outputs.cacheable("this plugin has CPU-bound goals with well-defined inputs and outputs");
outputs.directory("output");
outputs.directory("target/generated-sources/openapi");
outputs.directory("target/generated-test-sources/openapi");
});
context.getProject().addCompileSourceRoot("target/generated-sources/openapi/src/main/java");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment