Skip to content

Commit

Permalink
Gradle - make GenerateTask properties optional (#2185)
Browse files Browse the repository at this point in the history
This allows easier creation of custom `GenerateTask`. Specifically, this makes:

 - generateModelTests
 - generateModelDocumentation
 - generateApiTests
 - generateApiDocumentation
 - withXml

optional, following the same pattern as other properties in GenerateTask.

Without this change, we get `java.lang.IllegalStateException: No value
has been specified for this provider.` until these properties are
specified for the task, when attempting to define a custom generate task
(such as one to generate API docs).
  • Loading branch information
kahowell authored and jimschubert committed Feb 21, 2019
1 parent 0650d2f commit 329843b
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,25 @@ open class GenerateTask : DefaultTask() {
GeneratorProperties.clearProperty(CodegenConstants.APIS)
}

GeneratorProperties.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString())
GeneratorProperties.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString())
GeneratorProperties.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString())
GeneratorProperties.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString())
GeneratorProperties.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
if (generateApiDocumentation.isPresent) {
GeneratorProperties.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString())
}

if (generateModelDocumentation.isPresent) {
GeneratorProperties.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString())
}

if (generateModelTests.isPresent) {
GeneratorProperties.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString())
}

if (generateApiTests.isPresent) {
GeneratorProperties.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString())
}

if (withXml.isPresent) {
GeneratorProperties.setProperty(CodegenConstants.WITH_XML, withXml.get().toString())
}

// now override with any specified parameters
verbose.ifNotEmpty { value ->
Expand Down

2 comments on commit 329843b

@mimatn
Copy link

@mimatn mimatn commented on 329843b Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered the stated problem, and solved as said in the commit header. Thank you very much for the easy-to-google problem description and solution.

@jimschubert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Thanks @kahowell for writing such an excellent commit message!

Please sign in to comment.