dsmiley commented on code in PR #1793: URL: https://github.com/apache/solr/pull/1793#discussion_r1581719562
########## solr/solrj/build.gradle: ########## @@ -85,3 +94,73 @@ dependencies { testImplementation 'org.apache.commons:commons-lang3' testImplementation 'io.dropwizard.metrics:metrics-core' } + +/** + * Java Code Generation for Solr API + */ + +evaluationDependsOn(":solr:api") + +configurations { + openApiSpecFile { + canBeConsumed = false + } +} + +ext { + generatedCodeDir = "${buildDir}/generated/" + javaTemplateDir = "${projectDir}/src/resources/java-template" +} + +dependencies { + openApiSpecFile(project(path: ":solr:api", configuration: "openapiSpec")) +} + +/** + * Code Generation task + */ +openApiGenerate { + generatorName = "java" + inputSpec = project(":solr:api").openApiSpecFile + + // Add 'debugModels: ""' or 'debugOperations: ""' to get the JSON input to mustache templating for those components + globalProperties.set([apis: "", models: "false"]) + templateDir = project.javaTemplateDir + apiPackage = "org.apache.solr.client.solrj.request" + outputDir = project.generatedCodeDir + generateApiTests = false + generateModelTests = false + generateApiDocumentation = false + generateModelDocumentation = false + additionalProperties = ["modelPackage": "org.apache.solr.client.api.model"] +} + +tasks.openApiGenerate.dependsOn configurations.openApiSpecFile + +def generatedFiles = files("${project.generatedCodeDir}/src/main/java") { + builtBy tasks.openApiGenerate +} + +/** + * Setup Spotless (Code formatting) for the generated java files + */ +def generatedExt = new JavaExtension(spotless) +project.spotlessJavaSetup.execute(generatedExt) +generatedExt.target(generatedFiles) +def generatedSpotlessTask = generatedExt.createIndependentApplyTask("generatedSpotless") +generatedSpotlessTask.group("build") +generatedSpotlessTask.description("Apply formatting for generated code") + +tasks.openApiGenerate.finalizedBy generatedSpotlessTask + Review Comment: @gerlowskija this part of build.gradle is kind of sad. An ideal Gradle file is declarative yet this code is as imperative as can be. It need not be this way! BTW I played with ChatGPT briefly to convert this to a declarative style and it wasn't perfect but it was useful. There is something missing here: `generatedSpotlessTask.dependsOn(':checkJdkInternalsExportedToGradle')` The point of that task is to get a helpful error about a build configuration issue. Without that, you get mysterious errors about Google Java Format not being able to access certain modules of Java that have not been exported. Perhaps there's a way for that to be applied in a general way so it doesn't need to be remembered; not sure. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org